### Install anymap using pip Source: https://github.com/opengeos/anymap/blob/main/docs/examples/deckgl_example.ipynb Installs the anymap Python package. Ensure you have pip available in your environment. ```bash pip install anymap ``` -------------------------------- ### Import PotreeMap Widget Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Imports the PotreeMap widget from the anymap library. This is the initial setup step for using the viewer. ```python import os from anymap import PotreeMap print("Potree backend loaded successfully!") ``` -------------------------------- ### Initialize AnyMap and Print Confirmation Source: https://github.com/opengeos/anymap/blob/main/docs/examples/add_draw_data_example.ipynb Imports necessary libraries and initializes the AnyMap library, printing a confirmation message. This is a basic setup step for any AnyMap application. ```python from anymap import MapLibreMap import json print("AnyMap loaded successfully!") ``` -------------------------------- ### Setup CesiumMap Widget Source: https://github.com/opengeos/anymap/blob/main/docs/examples/cesium_example.ipynb Initializes the CesiumMap widget, requiring a Cesium ion access token. The token can be set as an environment variable or passed directly. This step ensures the Cesium backend is loaded successfully for globe visualizations. ```python import os from anymap import CesiumMap # Set your Cesium token (get a free one at https://cesium.com/ion/signup) # You can either set it as an environment variable CESIUM_TOKEN or pass it directly # os.environ['CESIUM_TOKEN'] = 'your_token_here' print("Cesium backend loaded successfully!") ``` -------------------------------- ### Mapbox Map Comparison Setup Source: https://github.com/opengeos/anymap/blob/main/docs/examples/map_comparison.ipynb Demonstrates how to initialize a MapCompare widget using Mapbox styles. This requires setting the 'MAPBOX_ACCESS_TOKEN' environment variable and specifying Mapbox style URLs. Note: This code is commented out and requires a valid token. ```python # Uncomment and set your Mapbox access token # import os # os.environ['MAPBOX_ACCESS_TOKEN'] = 'your_mapbox_token_here' # mapbox_compare = anymap.MapCompare( # left_map={ # "center": [37.7749, -122.4194], # "zoom": 12, # "style": "mapbox://styles/mapbox/streets-v12" # }, # right_map={ # "center": [37.7749, -122.4194], # "zoom": 12, # "style": "mapbox://styles/mapbox/satellite-v9" # }, # backend="mapbox", # orientation="vertical", # mousemove=True, # height="500px" # ) # mapbox_compare ``` -------------------------------- ### Set up Virtual Environment and Install anymap Source: https://github.com/opengeos/anymap/blob/main/docs/contributing.md These commands set up a virtual environment named 'anymap' using virtualenvwrapper, navigates into the cloned directory, and installs the local copy of anymap in development mode. ```shell mkvirtualenv anymap cd anymap/ python setup.py develop ``` -------------------------------- ### Install GeoPandas Source: https://github.com/opengeos/anymap/blob/main/docs/examples/save_draw_data_example.ipynb Installs the GeoPandas library, which is a dependency for the save_draw_data() method. This command-line instruction is necessary before running the Python code. ```bash pip install geopandas ``` -------------------------------- ### Serve Local LAZ File with Python HTTP Server Source: https://github.com/opengeos/anymap/blob/main/docs/examples/deckgl_pointcloud_example.ipynb Command to start a simple HTTP server in the current directory using Python 3. This is used to serve local files, such as LAZ files, for web access. ```bash # In the directory containing your LAZ file python -m http.server 8000 ``` -------------------------------- ### Set up AnyMap for Development Source: https://github.com/opengeos/anymap/blob/main/README.md Provides instructions for setting up the AnyMap project for local development. This involves cloning the repository, navigating into the directory, and installing the package in editable mode. ```bash git clone https://github.com/opengeos/anymap.git cd anymap pip install -e . ``` -------------------------------- ### Add Multiple Point Cloud Layers to Map with DeckGL Source: https://github.com/opengeos/anymap/blob/main/docs/examples/deckgl_pointcloud_example.ipynb This Python script initializes a MapLibreMap and sets up the basic configuration for adding multiple DeckGL point cloud layers. It serves as a starting point for demonstrating how to overlay different point cloud datasets with distinct visual properties. ```python # Create a map m4 = MapLibreMap( center=[0, 0], zoom=12, pitch=55, bearing=0, style="https://tiles.openfreemap.org/styles/positron", ) ``` -------------------------------- ### Create a Basic Map with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/basic_usage.ipynb Initializes a MapLibreMap instance centered on specific coordinates with a defined zoom level and height. The output is an interactive map object. ```python # Create a basic map m = MapLibreMap( center=[37.7749, -122.4194], # San Francisco coordinates [lat, lng] zoom=12, height="500px", ) m ``` -------------------------------- ### Import AnyMap and MapLibreMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/basic_usage.ipynb Imports the necessary AnyMap module and the MapLibreMap class for map creation. No external dependencies are required beyond the AnyMap package itself. ```python # Import the required modules from anymap import MapLibreMap import json ``` -------------------------------- ### Create Basic 3D Globe Source: https://github.com/opengeos/anymap/blob/main/docs/examples/cesium_example.ipynb Creates a fundamental 3D globe instance using CesiumMap, centered on specific geographic coordinates (New York City in this example). It allows setting camera height, dimensions, and disabling the navigation help button. ```python from anymap import CesiumMap # Create a basic Cesium map centered on New York City globe = CesiumMap( center=[40.7128, -74.0060], # NYC coordinates camera_height=2000000, # 200 km above surface width="100%", height="600px", navigation_help_button=False, ) globe ``` -------------------------------- ### Add Remote LAZ PointCloudLayer to MapLibreMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/deckgl_pointcloud_example.ipynb Python code to configure and add a PointCloudLayer to a MapLibreMap, loading data from a remote LAZ file URL. This example showcases specific props for LAZ files, including `coordinateSystem` and `material` settings for enhanced 3D rendering. ```python # Create a map for LAZ point cloud visualization m5 = MapLibreMap( center=[-123.068674, 44.055334], # Autzen Stadium area, Eugene, Oregon zoom=16, pitch=60, bearing=0, style="https://tiles.openfreemap.org/styles/liberty", ) # Add PointCloudLayer with LAZ data # The LAZ file will be loaded using @loaders.gl/las which DeckGL includes m5.add_deckgl_layer( "lidar-laz", "PointCloudLayer", "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/point-cloud-laz/indoor.0.1.laz", props={ # For LAZ files loaded by loaders.gl, we don't specify accessors # The loader automatically provides position and color data "getNormal": [0, 0, 1], # Default normal vector "pointSize": 1, "sizeUnits": "pixels", # LAZ files use absolute coordinates, not offset coordinates "coordinateSystem": "COORDINATE_SYSTEM.LNGLAT", "pickable": True, "opacity": 1.0, # Material properties for better 3D appearance "material": { "ambient": 0.35, "diffuse": 0.6, "shininess": 32, "specularColor": [60, 64, 70], }, }, ) m5.add_layer_control() m5.to_html("lidar.html") print("LAZ file will be loaded automatically by DeckGL's loaders.gl") print("This may take a moment depending on file size and network speed") m5 ``` -------------------------------- ### Show Potree Coordinate Grid Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Toggles the display of a coordinate grid in the Potree viewer and allows customization of its size and color for spatial reference. ```python # Show coordinate grid viewer.show_coordinate_grid(show=True, size=20, color="#666666") print("Coordinate grid enabled") ``` -------------------------------- ### Set Map Center and Zoom Source: https://github.com/opengeos/anymap/blob/main/docs/examples/openlayers_example.ipynb Shows how to programmatically set the map's center coordinates and zoom level, moving the view to Miami. ```python # Set center and zoom control_map.set_center(-80.1918, 25.7617) # Miami control_map.set_zoom(11) ``` -------------------------------- ### Create Default Potree Viewer Configuration Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Initializes a Potree viewer with various default settings for width, height, background color, point rendering, camera, and visual enhancements like EDL and grid. ```python # Create a basic Potree viewer viewer = PotreeMap( width="100%", height="600px", background_color="#1a1a1a", # Dark background point_size=1.5, point_size_type="adaptive", # Adaptive point sizing point_shape="square", camera_position=[0, 0, 50], camera_target=[0, 0, 0], fov=60, edl_enabled=True, # Eye Dome Lighting for better depth perception show_grid=True, grid_size=10, grid_color="#444444", ) viewer ``` -------------------------------- ### Advanced MapLibre Map with Custom Lighting and 3D Model Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_three_plugin_example.ipynb Creates a MapLibre map with a satellite base style, advanced custom lighting setup including ambient and directional lights with specific colors, and adds a GLTF model. This example is for creating visually rich and detailed 3D map scenes. ```python # Create a map with custom styling m4 = MapLibreMap( center=[-122.4194, 37.7749], # San Francisco zoom=17, pitch=70, bearing=60, height="700px", style="3d-satellite", # Use satellite style for better 3D context ) # Initialize Three.js scene m4.init_three_scene() # Create a dramatic lighting setup m4.add_three_light(light_type="ambient", intensity=0.3, color=0x404040) m4.add_three_light( light_type="directional", intensity=1.0, position=[2, 3, 1], color=0xFFFFFF ) m4.add_three_light( light_type="directional", intensity=0.5, position=[-1, -2, 1], color=0x8080FF ) # Add a 3D model m4.add_three_model( model_id="sf_model", url="https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf", coordinates=[-122.4194, 37.7749], scale=200, rotation=[0, 0, 0], ) m4 ``` -------------------------------- ### Cleanup Viewer State Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Resets the viewer by clearing all loaded point clouds, measurements, and filters. This function is useful for starting with a clean slate or preparing for new data loading. ```python # Clear all point clouds from the first viewer viewer.clear_point_clouds() print("Point clouds cleared from first viewer") # Clear measurements viewer.clear_measurements() print("Measurements cleared") # Clear filters viewer.clear_filters() print("Filters cleared") ``` -------------------------------- ### Create Basic Potree Viewer with URL Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Creates a basic Potree viewer by loading a point cloud from a given URL. Currently, only one viewer can be rendered at a time to avoid control conflicts. ```python url = "/files/potreelibs/pointclouds/lion_takanawa_las/cloud.js" viewer = PotreeMap(description="Lion", point_cloud_url=url, height="400px") viewer ``` -------------------------------- ### Create Expanded Geocoder Control Source: https://github.com/opengeos/anymap/blob/main/docs/examples/geocoder_example.ipynb Initializes a MapLibre map centered on Paris and adds a geocoder control that is always expanded, showing the search input box immediately. This setup is useful for immediate user interaction. ```python # Create a map with expanded geocoder m_expanded = MapLibreMap( center=[2.3522, 48.8566], zoom=11, style="positron", height="600px" # Paris ) # Add an expanded geocoder control m_expanded.add_geocoder_control(position="top-left", collapsed=False) m_expanded ``` -------------------------------- ### Get COG Metadata using MapLibreMap Instance Method Source: https://github.com/opengeos/anymap/blob/main/docs/examples/cog_metadata_example.ipynb Demonstrates retrieving COG metadata directly using the `get_cog_metadata` method of a `MapLibreMap` instance. This method also defaults to returning the bounding box in EPSG:4326. Requires `anymap`. ```python from anymap import MapLibreMap # Create a map instance m = MapLibreMap() # Get metadata using the map instance method (defaults to EPSG:4326) cog_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/naip_rgb_train_3857.tif" metadata = m.get_cog_metadata(cog_url) if metadata: print("Using MapLibreMap instance method:") print("=" * 50) bbox = metadata.get("bbox") if bbox: print(f"Bounding Box (EPSG:4326):") print(f" West: {bbox[0]:.6f}°") print(f" South: {bbox[1]:.6f}°") print(f" East: {bbox[2]:.6f}°") print(f" North: {bbox[3]:.6f}°") print(f"\nDimensions: {metadata.get('width')} x {metadata.get('height')} pixels") print(f"Bands: {metadata.get('count')}") print(f"Native CRS: {metadata.get('crs')}") print(f"Output CRS: {metadata.get('output_crs')}") print(m) m.add_cog_layer(layer_id="cogLayer", cog_url=cog_url, fit_bounds=True) ``` -------------------------------- ### Initialize AnyMap Mapbox Backend Source: https://github.com/opengeos/anymap/blob/main/docs/examples/mapbox_example.ipynb Imports necessary modules and initializes the AnyMap Mapbox backend. Requires a Mapbox access token, which can be set via an environment variable or directly during map instantiation. This snippet confirms successful loading. ```python # Import required modules from anymap import MapboxMap import json import os # Note: You need a Mapbox access token to use the Mapbox backend # Get a free token at https://account.mapbox.com/access-tokens/ # Set it as an environment variable: export MAPBOX_TOKEN="your_token_here" # Or pass it directly when creating the map: MapboxMap(access_token="your_token") print("AnyMap with Mapbox backend loaded successfully!") ``` -------------------------------- ### Load Multiple Point Clouds into Potree Viewer Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Demonstrates how to load multiple point cloud datasets into a single Potree viewer instance. Each point cloud can have a specified URL and name. ```python # Example of loading multiple point clouds point_clouds = [ { "url": "https://example.com/pointclouds/scan1/metadata.json", "name": "Building Scan", }, { "url": "https://example.com/pointclouds/scan2/metadata.json", "name": "Terrain Scan", }, ] # viewer.load_multiple_point_clouds(point_clouds) print("Multiple point clouds can be loaded simultaneously") ``` -------------------------------- ### Create a Second Independent Viewer Instance Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Instantiates a second, independent PotreeMap viewer with distinct configuration options. This verifies that viewer instances operate separately and do not affect each other's settings or state. ```python # Create a second, independent viewer with different settings viewer2 = PotreeMap( width="100%", height="500px", background_color="#003366", # Blue background point_size=1.0, point_size_type="attenuation", point_shape="circle", camera_position=[10, 10, 20], edl_enabled=False, show_grid=False, ) # Load different point cloud data (if available) # viewer2.load_point_cloud( # "https://example.com/pointclouds/another_scan/metadata.json", # "Another Point Cloud" # ) viewer2 ``` -------------------------------- ### MapLibre with Sun Light and 3D Model Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_three_plugin_example.ipynb Configures a MapLibre map with realistic sun lighting for 3D rendering. It initializes the Three.js scene, adds a sun light with ambient light, and then places a GLTF model. This setup is ideal for scenes requiring natural lighting conditions. ```python # Create another map with sun lighting m2 = MapLibreMap( center=[148.9819, -35.3981], # Different location in Canberra zoom=18, pitch=60, bearing=45, height="600px", ) # Initialize Three.js scene m2.init_three_scene() # Add sun and ambient light m2.add_three_light(light_type="sun") m2.add_three_light(light_type="ambient", intensity=0.3) # Add a 3D model m2.add_three_model( model_id="model_with_sun", url="https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf", coordinates=[148.9819, -35.3981], scale=100, rotation=[0, 0, 0], ) m2 ``` -------------------------------- ### Convert Point Cloud Data with PotreeConverter Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Converts LAS/LAZ point cloud files into a format suitable for Potree using the PotreeConverter command-line tool. Requires specifying input files and an output directory. ```bash PotreeConverter input.las -o output_directory --output-format LAZ ``` -------------------------------- ### Get COG Metadata in Native CRS with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/cog_metadata_example.ipynb Retrieves COG metadata, including the bounding box, in the file's native Coordinate Reference System (CRS) by setting `crs=None`. This is useful for precise geospatial operations when the default EPSG:4326 is not suitable. Requires `anymap` and `rasterio`. ```python from anymap import MapLibreMap from anymap.utils import get_cog_metadata # Sample COG URL from MapLibre documentation cog_url = "https://maplibre.org/maplibre-gl-js/docs/assets/cog.tif" # Get metadata in native CRS (EPSG:3857 in this case) metadata_native = get_cog_metadata(cog_url, crs=None) if metadata_native: print("COG Metadata (bbox in native CRS):") print("=" * 50) bbox = metadata_native.get("bbox") if bbox: print(f"Bounding Box (native CRS):") print(f" West: {bbox[0]:.2f}") print(f" South: {bbox[1]:.2f}") print(f" East: {bbox[2]:.2f}") print(f" North: {bbox[3]:.2f}") print(f"\nNative CRS: {metadata_native.get('crs')}") print(f"Output CRS: {metadata_native.get('output_crs')}") print( f"Dimensions: {metadata_native.get('width')} x {metadata_native.get('height')} pixels" ) print(f"Bands: {metadata_native.get('count')}") print("\n" + "=" * 50) print("COMPARISON:") print("=" * 50) metadata = get_cog_metadata(cog_url) # Re-fetch for comparison if metadata and metadata_native: print(f"EPSG:4326 bbox: {metadata.get('bbox')}") print(f"Native bbox: {metadata_native.get('bbox')}") ``` -------------------------------- ### Create and Display a Second Map Instance with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/basic_usage.ipynb Creates a second, independent MapLibreMap instance with different initial settings, including center, zoom, and a specific map style URL. This demonstrates the ability to manage multiple maps simultaneously. ```python # Create a new map instance m2 = MapLibreMap( center=[35.6762, 139.6503], # Tokyo zoom=10, height="600px", style="https://demotiles.maplibre.org/style.json", ) m2 ``` -------------------------------- ### Get COG Metadata in EPSG:4326 with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/cog_metadata_example.ipynb Retrieves metadata from a COG file, including bounding box (reprojected to EPSG:4326 by default), width, height, CRS, and number of bands. Requires the `anymap` and `rasterio` packages. The bounding box is returned in WGS84 for easy use with MapLibre. ```python from anymap import MapLibreMap from anymap.utils import get_cog_metadata # Sample COG URL from MapLibre documentation cog_url = "https://maplibre.org/maplibre-gl-js/docs/assets/cog.tif" # Get metadata with default CRS (EPSG:4326) metadata = get_cog_metadata(cog_url) if metadata: print("COG Metadata (bbox in EPSG:4326):") print("=" * 50) for key, value in metadata.items(): print(f"{key:15}: {value}") print("\n" + "=" * 50) print("Note: The bbox coordinates are in EPSG:4326 (WGS84)") print(f"Native CRS: {metadata.get('crs')}") print(f"Output CRS: {metadata.get('output_crs')}") else: print("Failed to retrieve metadata. Make sure rasterio is installed:") print("pip install rasterio") ``` -------------------------------- ### Convert LAS/LAZ to Potree Format (Bash) Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Illustrates the command-line usage of PotreeConverter for converting LAS/LAZ files into a format suitable for Potree. This step is necessary before loading data into the viewer. ```bash # Example conversion command (not run in this notebook) PotreeConverter input.las -o output_directory --output-format LAZ ``` -------------------------------- ### Install AnyMap with Conda Source: https://github.com/opengeos/anymap/blob/main/README.md Installs the AnyMap Python package using Conda, a popular package and environment manager. This command installs from the conda-forge channel, which is a community-led collection of recipes, build infrastructure, and distributions for the Conda package manager. ```bash conda install -c conda-forge anymap ``` -------------------------------- ### Utility Functions for Viewer Control Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Provides utility functions to control the viewer's display and capture its state. Includes fitting the view to point cloud bounds, taking screenshots, and retrieving camera position and target. ```python # Fit point clouds to screen viewer.fit_to_screen() print("View fitted to point cloud bounds") # Take a screenshot viewer.take_screenshot() print("Screenshot captured") # Get current camera position camera_pos = viewer.get_camera_position() camera_target = viewer.get_camera_target() print(f"Camera position: {camera_pos}") print(f"Camera target: {camera_target}") ``` -------------------------------- ### Customizing Geocoder Behavior and Appearance Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Provides examples of customizing various aspects of the geocoder's behavior, including language, initial state, clearing behavior, search triggers, result limits, and marker visibility. This example configures the geocoder for French language results. ```python # Create a map m6 = MapLibreMap(center=[2.3522, 48.8566], zoom=12, style="dark-matter", height="600px") # Add geocoder with custom behavior settings m6.add_maplibre_geocoder( position="top-right", api_key=maptiler_api_key, maplibre_api="maptiler", placeholder="Search for places in French...", language="fr", # French language results collapsed=True, # Start collapsed (icon only) clear_on_blur=True, # Clear search when input loses focus clear_and_blur_on_esc=True, # Clear and unfocus on ESC key min_length=3, # Minimum 3 characters to trigger search limit=8, # Show up to 8 results marker=True, show_result_markers=False, # Don't show markers for all results enable_event_logging=True, # Enable console logging ) m6 ``` -------------------------------- ### Multi-cell Rendering Test Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Demonstrates rendering the same viewer instance across multiple Jupyter notebook cells. Changes made in one cell should reflect in others, maintaining the viewer's state and settings. ```python # Display the same viewer instance again # This should maintain all the settings and state from above viewer ``` ```python # Change settings while displayed in multiple cells viewer.set_background_color("#0a0a0a") viewer.set_point_size(3.0) viewer.set_point_shape("square") print("Settings changed! Updates should appear on all viewer instances above.") ``` -------------------------------- ### Import AnyMap and Geocoder Libraries Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Imports necessary libraries for using AnyMap and the MapLibre GL Geocoder. This is a prerequisite for all subsequent examples. ```python import os from anymap import MapLibreMap ``` -------------------------------- ### Change Mapbox Map Style Source: https://github.com/opengeos/anymap/blob/main/docs/examples/mapbox_example.ipynb Shows how to dynamically change the visual style of an existing Mapbox map. This example switches the map to a satellite view. ```python # Change to satellite style m.set_style("mapbox://styles/mapbox/satellite-v9") m ``` -------------------------------- ### Initialize MapLibre Map with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/infobox_example.ipynb Initializes a MapLibre map using the AnyMap library. Sets the initial center, zoom level, style, and dimensions. Requires the 'anymap' library. ```python from anymap import MapLibreMap m = MapLibreMap(center=[0, 20], zoom=2.5, style="liberty", height="600px") ``` -------------------------------- ### Set Center and Zoom of Leaflet Map Source: https://github.com/opengeos/anymap/blob/main/docs/examples/leaflet_example.ipynb Shows how to programmatically set the map's center coordinates and zoom level. This example changes the view to Miami. ```python # Set center and zoom control_map.set_center(25.7617, -80.1918) # Miami control_map.set_zoom(11) ``` -------------------------------- ### Create MapLibre Map and Add DeckGL Layers (Python) Source: https://github.com/opengeos/anymap/blob/main/docs/examples/deckgl_example.ipynb Demonstrates creating a MapLibre map in Python and adding DeckGL layers like ScatterplotLayer and GeoJsonLayer. It uses sample garden data and GeoJSON data for landmarks. The map is then exported to an HTML file. Dependencies include the anymap library. ```python import sys import os from anymap.maplibre import MapLibreMap # Create a MapLibre map m = MapLibreMap( center=[2.345885, 48.860412], # Paris zoom=12, style="https://tiles.openfreemap.org/styles/bright", ) # Sample data for gardens in Paris (from the HTML example) garden_data = [ {"name": "Jardins du Trocadéro", "position": [2.289207, 48.861561], "district": 16}, {"name": "Jardin des Plantes", "position": [2.359823, 48.843995], "district": 5}, {"name": "Jardins des Tuileries", "position": [2.327092, 48.863608], "district": 1}, {"name": "Parc de Bercy", "position": [2.382094, 48.835962], "district": 12}, {"name": "Jardin du Luxembourg", "position": [2.336975, 48.846421], "district": 6}, ] # Add DeckGL ScatterplotLayer - using strings instead of lambda functions m.add_deckgl_layer( "gardens", "ScatterplotLayer", garden_data, props={ "getPosition": "position", # String accessor instead of lambda "getRadius": 100, "getFillColor": [49, 130, 206], "getLineColor": [175, 0, 32], "lineWidthMinPixels": 5, "radiusMinPixels": 20, "radiusMaxPixels": 100, "pickable": True, "opacity": 0.8, "stroked": True, "filled": True, }, ) print(f"DeckGL layers: {list(m.get_deckgl_layers().keys())}") # Toggle visibility m.set_deckgl_layer_visibility("gardens", False) m.set_deckgl_layer_visibility("gardens", True) geojson_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [2.3522, 48.8566], # Paris center }, "properties": {"name": "Paris Center", "size": 200}, }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [2.2945, 48.8534], # Eiffel Tower }, "properties": {"name": "Eiffel Tower", "size": 150}, }, ], } m.add_deckgl_layer( "landmarks", "GeoJsonLayer", geojson_data, props={ "pickable": True, "stroked": True, "filled": True, "pointType": "circle", "getFillColor": [255, 140, 0, 200], "getLineColor": [255, 0, 0], "getPointRadius": 80, "lineWidthMinPixels": 2, }, ) html_file = "test_deckgl_maplibre.html" m.to_html(html_file, title="DeckGL + MapLibre Test") m ``` -------------------------------- ### Set Up Event Handlers for User Interactions (Python) Source: https://github.com/opengeos/anymap/blob/main/docs/examples/mapbox_example.ipynb Configures event handlers to capture user interactions like map clicks and movements. It stores event data and prints details to the console. Requires the `nyc_map` object to be initialized. ```python # Store events for demonstration map_events = [] def on_map_click(event): lat, lng = event["lngLat"] map_events.append(f"Clicked at: {lat:.4f}, {lng:.4f}") print(f"Map clicked at: {lat:.4f}, {lng:.4f}") def on_map_move(event): center = event.get("center", [0, 0]) zoom = event.get("zoom", 0) print(f"Map moved to: {center[0]:.4f}, {center[1]:.4f} at zoom {zoom:.2f}") # Register event handlers nyc_map.on_map_event("click", on_map_click) yc_map.on_map_event("moveend", on_map_move) print("Event handlers registered. Try clicking and moving the map!") ``` -------------------------------- ### Combining Geocoder with Other Map Controls Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Demonstrates that the MapLibre GL Geocoder can be used alongside other map controls. This example adds a geocoder to a map that might include other functionalities. ```python # Create a comprehensive map with multiple controls m7 = MapLibreMap( center=[-87.6298, 41.8781], zoom=11, style="liberty", height="600px" # Chicago ) # Add MapLibre GL Geocoder m7.add_maplibre_geocoder( position="top-left", api_key=maptiler_api_key, maplibre_api="maptiler", placeholder="Search Chicago...", proximity=[-87.6298, 41.8781], country="us", ) ``` -------------------------------- ### Add Measurement Tools Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Enables various measurement tools within the viewer. Supported tools include 'distance', 'area', and 'volume'. Each call adds a new measurement capability. ```python # Add distance measurement tool viewer.add_measurement("distance") print("Distance measurement tool added") # Add area measurement tool viewer.add_measurement("area") print("Area measurement tool added") # Add volume measurement tool viewer.add_measurement("volume") print("Volume measurement tool added") ``` -------------------------------- ### Add Mapbox Controls Source: https://github.com/opengeos/anymap/blob/main/docs/examples/mapbox_example.ipynb Demonstrates adding interactive controls to a Mapbox map. This example adds navigation, scale, and fullscreen controls to the map's interface, typically positioned in the corners. ```python # Add various controls to the map m3d.add_control("navigation", "top-left") m3d.add_control("scale", "bottom-left") m3d.add_control("fullscreen", "top-right") print("Navigation, scale, and fullscreen controls added") ``` -------------------------------- ### Filtering Search Results with a Bounding Box Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Demonstrates how to restrict geocoding search results to a defined geographical area using the `bbox` parameter. This example limits searches to the bounding box of California. ```python # Create a map of California m5 = MapLibreMap(center=[-119.4179, 36.7783], zoom=6, style="positron", height="600px") # Add geocoder with bounding box for California # Bounding box: [minLng, minLat, maxLng, maxLat] m5.add_maplibre_geocoder( position="top-left", api_key=maptiler_api_key, maplibre_api="maptiler", placeholder="Search in California...", bbox=[-124.48, 32.53, -114.13, 42.01], # California bounds marker=True, ) m5 ``` -------------------------------- ### Create Basic Mapbox Map Source: https://github.com/opengeos/anymap/blob/main/docs/examples/mapbox_example.ipynb Demonstrates the creation of a basic Mapbox GL JS map using AnyMap. It sets the center coordinates, zoom level, desired height, and a specific Mapbox style. The access token is handled automatically if configured via environment variables. ```python # Create a basic Mapbox map # NOTE: Replace "your_token_here" with your actual Mapbox access token # or set the MAPBOX_TOKEN environment variable m = MapboxMap( center=[37.7749, -122.4194], # San Francisco zoom=12, height="600px", style="mapbox://styles/mapbox/streets-v12", # access_token="your_token_here" # Replace with your actual token ) print(f"Access token set: {bool(m.access_token)}") print(f"Map style: {m.style}") m ``` -------------------------------- ### Load Point Cloud Data in Viewer Source: https://github.com/opengeos/anymap/blob/main/docs/examples/potree_example.ipynb Loads converted point cloud data into the PotreeMap viewer. Requires the URL to the point cloud's metadata.json file, hosted on a CORS-enabled web server. ```python viewer.load_point_cloud( "https://your-server.com/pointclouds/your_data/metadata.json", "Your Point Cloud Name" ) ``` -------------------------------- ### Applying Proximity Bias to Search Results Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Illustrates how to bias geocoding search results towards a specific geographical location using the `proximity` parameter. This example biases searches towards London. ```python # Create a map centered on London m4 = MapLibreMap(center=[-0.1276, 51.5074], zoom=11, style="positron", height="600px") # Add geocoder with proximity bias towards London m4.add_maplibre_geocoder( position="top-left", api_key=maptiler_api_key, maplibre_api="maptiler", placeholder="Search near London...", proximity=[-0.1276, 51.5074], # [lng, lat] for London marker=True, language="en", ) m4 ``` -------------------------------- ### Create Leaflet Maps with Markers, Polygons, and Polylines (Python) Source: https://context7.com/opengeos/anymap/llms.txt Illustrates how to create an interactive map using the Leaflet library via the `LeafletMap` class. The example shows setting the map's center, zoom level, and tile layer. It also demonstrates adding a circle overlay with a tooltip, a polygon with a tooltip, and a polyline, all with customizable visual properties. ```python from anymap import LeafletMap # Create a Leaflet map m = LeafletMap( center=[51.505, -0.09], # London [lat, lng] - Note: Leaflet uses lat, lng order zoom=13, tile_layer="OpenStreetMap", # or custom URL template height="600px" ) # Add a circle overlay circle_id = m.add_circle( latlng=[51.508, -0.11], radius=500, # meters color="blue", fillColor="blue", fillOpacity=0.3, tooltip="500m radius circle" ) # Add a polygon polygon_id = m.add_polygon( latlngs=[ [51.509, -0.08], [51.503, -0.06], [51.51, -0.047] ], color="red", fillColor="red", fillOpacity=0.2, tooltip="Triangle area" ) # Add polyline polyline_id = m.add_polyline( latlngs=[ [51.509, -0.08], [51.503, -0.09], [51.505, -0.11] ], color="green", weight=3 ) m ``` -------------------------------- ### Using Mapbox Geocoding API Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Shows how to use the MapLibre GL Geocoder with the Mapbox geocoding service. This example requires a Mapbox access token and configures a map centered on New York City. ```python # Create a map centered on New York City m2 = MapLibreMap( center=[-74.0060, 40.7128], zoom=11, style="dark-matter", height="600px" ) mapbox_api_key = os.environ["MAPBOX_TOKEN"] # Add MapLibre GL Geocoder with Mapbox API m2.add_maplibre_geocoder( position="top-left", api_key=mapbox_api_key, maplibre_api="mapbox", placeholder="Find a location...", language="en", marker=True, collapsed=True, ) m2 ``` -------------------------------- ### Remove Measures Control from MapLibreMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_measures.ipynb Illustrates the process of removing a measures control from a MapLibre map. The example creates a map with the control and includes a commented-out line showing how to remove it. The map is centered on Berlin. ```python # Create a map and add measures control m_removable = MapLibreMap( center=[13.4050, 52.5200], zoom=11, style="positron", height="600px" # Berlin ) m_removable.add_measures_control(position="top-left") # Uncomment the line below to remove the measures control # m_removable.remove_measures_control(position="top-left") m_removable ``` -------------------------------- ### Fly to a Different Location on Leaflet Map Source: https://github.com/opengeos/anymap/blob/main/docs/examples/leaflet_example.ipynb Demonstrates the 'fly_to' method to smoothly animate the map view to a new location, specified by latitude, longitude, and zoom level. This example transitions the view to Los Angeles. ```python # Fly to a different location control_map.fly_to(34.0522, -118.2437, 12) # Los Angeles ``` -------------------------------- ### Display GeoJSON Data on Leaflet Map Source: https://github.com/opengeos/anymap/blob/main/docs/examples/leaflet_example.ipynb Loads and visualizes GeoJSON data on a Leaflet map. This example defines sample point data for New York City and Chicago and styles them with specific colors and weights. ```python # Sample GeoJSON data geojson_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-74.0060, 40.7128]}, "properties": {"name": "New York City", "population": 8175133}, }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-87.6298, 41.8781]}, "properties": {"name": "Chicago", "population": 2693976}, }, ], } # Create map with GeoJSON data geojson_map = anymap.LeafletMap(center=[40.0, -80.0], zoom=5) geojson_map.add_geojson( geojson_data, style={"color": "purple", "weight": 2, "fillOpacity": 0.7} ) geojson_map ``` -------------------------------- ### Import AnyMap and Initialize Draw Control Support Source: https://github.com/opengeos/anymap/blob/main/docs/examples/draw_control_example.ipynb This snippet imports the necessary MapLibreMap class from AnyMap and confirms that draw control support is available. It serves as a basic setup for using draw control functionalities. ```python from anymap import MapLibreMap import json print("AnyMap loaded successfully!") print("Draw control support is built into the MapLibre implementation.") ``` -------------------------------- ### Filtering Geocoding Results by Country and Type Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_geocoder_example.ipynb Demonstrates advanced configuration to filter geocoding results by a specific country ('us') and place types ('place', 'locality'). This example focuses on cities within the United States. ```python # Create a map focused on the United States m3 = MapLibreMap(center=[-98.5795, 39.8283], zoom=4, style="liberty", height="600px") # Add geocoder with country filter and specific place types m3.add_maplibre_geocoder( position="top-left", api_key=maptiler_api_key, maplibre_api="maptiler", placeholder="Search US cities...", country="us", # Limit to United States types="place,locality", # Only show cities and localities limit=10, marker=True, ) m3 ``` -------------------------------- ### Initialize MapLibre Map with Three.js Scene Source: https://github.com/opengeos/anymap/blob/main/docs/examples/maplibre_three_plugin_example.ipynb Sets up a MapLibre map with a tilted view suitable for 3D models and initializes the Three.js scene. It includes adding ambient and directional lighting for the 3D environment. This is the foundational step for rendering 3D objects. ```python from anymap import MapLibreMap # Create a map centered on Canberra, Australia with pitch for 3D viewing m = MapLibreMap( center=[149.1300, -35.2809], # Canberra zoom=16, pitch=60, # Tilt the map for better 3D viewing bearing=0, height="600px", ) # Initialize the Three.js scene m.init_three_scene() # Add lighting to the scene m.add_three_light(light_type="ambient", intensity=0.5) m.add_three_light(light_type="directional", intensity=0.8, position=[1, 1, 1]) m ``` -------------------------------- ### Initialize Leaflet Map for Control Demonstrations Source: https://github.com/opengeos/anymap/blob/main/docs/examples/leaflet_example.ipynb Creates a basic Leaflet map centered on San Francisco. This map will be used in subsequent steps to demonstrate various control and interaction methods. ```python # Create a map for demonstrations control_map = anymap.LeafletMap(center=[37.7749, -122.4194], zoom=10) # San Francisco control_map ``` -------------------------------- ### Add GeoJSON Layer to Map with AnyMap Source: https://github.com/opengeos/anymap/blob/main/docs/examples/basic_usage.ipynb Adds a layer of GeoJSON data to the map, allowing visualization of geographic features. This example demonstrates adding circle markers with custom paint properties. Requires valid GeoJSON data. ```python # Sample GeoJSON data geojson_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-0.1278, 51.5074]}, "properties": {"name": "London", "population": 8900000}, }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [2.3522, 48.8566]}, "properties": {"name": "Paris", "population": 2141000}, }, ], } # Add GeoJSON layer m.add_geojson_layer( layer_id="cities", geojson_data=geojson_data, layer_type="circle", paint={ "circle-radius": 8, "circle-color": "#ff0000", "circle-stroke-width": 2, "circle-stroke-color": "#ffffff", }, ) ``` -------------------------------- ### Fit Leaflet Map Bounds to a Specific Area Source: https://github.com/opengeos/anymap/blob/main/docs/examples/leaflet_example.ipynb Utilizes the 'fit_bounds' method to adjust the map's viewport to encompass a defined bounding box, specified by its southwest and northeast corner coordinates. This example sets bounds for an area in Miami. ```python # Fit bounds to a specific area # Southwest and Northeast corners of the bounding box control_map.fit_bounds([[25.7617, -80.1918], [25.7907, -80.1310]]) ```