AnyMap

repository·main·Indexed 42 days ago

https://github.com/opengeos/anymap

A Python package for creating interactive maps in Jupyter notebooks using anywidget and JavaScript mapping libraries. Version 0.12.0 supports multiple backends including MapLibre GL JS, Mapbox GL JS, Cesium, Potree, Deck.gl, Leaflet, OpenLayers, and Kepler.gl, featuring bidirectional Python-JavaScript communication, multi-cell rendering, and tools for 3D geospatial visualization.

Tokens
71.5K
Snippets
286
Records
327
Agent score
53%

What's inside AnyMap

  1. Overview of the anymap module

    main
    The anymap module provides a high-level interface for creating and interacting with interactive maps. It supports features such as creating basic maps, applying custom settings, adding markers with popups and custom styling, and integrating GeoJSON data.
  2. Set up anymap for local development

    main

    To contribute to anymap, follow these steps to set up a local development environment using a virtual environment and a development install:

    1. Fork the repository on GitHub.
    2. Clone your fork locally.
    3. Create a virtual environment (e.g., using virtualenvwrapper) and install the package in development mode using python setup.py develop.
    4. Create a new branch for your changes.
    5. Verify changes using flake8, local tests (pytest or python setup.py test), and tox to ensure compatibility across supported Python versions.
    6. Push your branch and submit a pull request.
    # Clone your fork
    $ git clone git@github.com:your_name_here/anymap.git
    
    # Set up local development environment
    $ mkvirtualenv anymap
    $ cd anymap/
    $ python setup.py develop
    
    # Create a development branch
    $ git checkout -b name-of-your-bugfix-or-feature
    
    # Run quality checks
    $ flake8 anymap tests
    $ python setup.py test # or pytest
    $ tox
    
    # Commit and push
    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
  3. Create a basic MapLibreMap

    main

    To create a basic interactive map using the MapLibre backend, import MapLibreMap and provide a center coordinate (longitude, latitude), a zoom level, and a height.

    Note: The center parameter expects [longitude, latitude].

    from anymap import MapLibreMap
    
    # Create a basic map
    m = MapLibreMap(
        center=[-122.4194, 37.7749],  # San Francisco
        zoom=12,
        height="600px"
    )
    m
  4. Pull Request Guidelines for anymap

    main

    When submitting a pull request to anymap, ensure the following requirements are met:

    • Testing: The pull request must include tests.
    • Documentation: If new functionality is added, update the documentation. New features should be encapsulated in functions with docstrings and added to the list in README.rst.
    • Compatibility: The code must work for Python 3.8 and later, as well as PyPy. Ensure tests pass for all supported Python versions using tox.
  5. Visualize LAZ (LiDAR) files

    main

    AnyMap provides specialized support for LAZ files (compressed LiDAR data).

    Key Features:

    • Automatic Precision: AnyMap automatically enables fp64: true (64-bit float precision) for LAZ files. This prevents the 'flat appearance' issue where 32-bit floats cause Z-coordinates (elevation) to fail in 3D space.
    • Automatic Loading: Uses @loaders.gl/las to load and parse files in a Web Worker.
    • Coordinate System: LAZ files typically use geographic coordinates, so set coordinateSystem to COORDINATE_SYSTEM.LNGLAT.

    Usage Note: When using LAZ files, you do not need to specify getPosition or getColor in props as the loader extracts them automatically.

    m.add_deckgl_layer(
        "lidar-laz",
        "PointCloudLayer",
        "https://example.com/data.laz",
        props={
            "getNormal": [0, 0, 1],
            "pointSize": 1,
            "coordinateSystem": "COORDINATE_SYSTEM.LNGLAT",
            "pickable": True,
        }
    )
  6. Filter geocoding results by country, type, or bounding box

    main

    You can refine search results using several filtering parameters in add_maplibre_geocoder:

    • country: Limit results to specific country code(s) (e.g., "us" or "us,ca").
    • types: Filter by place types using a comma-separated string (e.g., "place,locality").
    • bbox: Limit results to a specific bounding box defined as [minLng, minLat, maxLng, maxLat].
    • proximity: Bias results towards a specific [lng, lat] location.
    m3.add_maplibre_geocoder(
        position="top-left",
        api_key=maptiler_api_key,
        maplibre_api="maptiler",
        country="us",
        types="place,locality",
        bbox=[-124.48, 32.53, -114.13, 42.01],
        proximity=[-0.1276, 51.5074]
    )
  7. Use custom HTTP headers for private tile layers

    main

    You can use the request_headers parameter to pass custom HTTP headers (such as Authorization Bearer tokens or API keys) with all tile requests. This is essential for accessing private tile servers, OAuth-protected services, or including custom headers for logging.

    Note that headers are applied to all tile requests, including style sources, sprites, and glyphs. Changing request_headers dynamically will apply to new requests but will not re-fetch tiles that have already been loaded.

    import anymap
    
    # Create a map with authorization headers
    m = anymap.Map(
        center=[-74.0060, 40.7128],
        zoom=12,
        request_headers={"Authorization": "Bearer YOUR_TOKEN_HERE"},
    )