Skip to main content

A Python package for creating interactive maps with anywidget and JavaScript mapping libraries

Project description

AnyMap

image image image image Conda Recipe image Conda Downloads image

A Python package for creating interactive maps with anywidget and JavaScript mapping libraries

Features

  • 🗺️ Interactive Maps: Create beautiful, interactive maps in Jupyter notebooks
  • 🔄 Bidirectional Communication: Full Python ↔ JavaScript communication
  • 📱 Multi-cell Support: Render maps in multiple notebook cells without conflicts
  • 🎯 MapLibre Integration: Built-in support for MapLibre GL JS
  • 🛠️ Extensible: Easy to add support for other mapping libraries
  • 🚀 Familiar API: Similar to ipyleaflet for easy migration

Installation

pip install anymap
conda install -c conda-forge anymap

Quick Start

from anymap import MapLibreMap

# Create a basic map
m = MapLibreMap(
    center=[-122.4194, 37.7749],  # San Francisco
    zoom=12,
    height="600px"
)
m

Basic Usage

Creating Maps

from anymap import MapLibreMap

# Create a map with custom settings
m = MapLibreMap(
    center=[-74.0060, 40.7128],  # New York City
    zoom=13,
    height="500px",
    bearing=45,  # Map rotation
    pitch=60     # 3D tilt
)

Adding Markers

# Add a marker with popup
m.add_marker(
    lat=40.7128,
    lng=-74.0060,
    popup="<h3>New York City</h3><p>The Big Apple</p>"
)

Working with GeoJSON

# Add GeoJSON data
geojson_data = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [-74.0060, 40.7128]
            },
            "properties": {"name": "NYC"}
        }
    ]
}

m.add_geojson_layer(
    layer_id="cities",
    geojson_data=geojson_data,
    layer_type="circle",
    paint={
        "circle-radius": 8,
        "circle-color": "#ff0000"
    }
)

Event Handling

def handle_click(event):
    lat, lng = event['lngLat']
    print(f"Clicked at: {lat:.4f}, {lng:.4f}")

m.on_map_event('click', handle_click)

Dynamic Updates

# Change map properties
m.set_center(-0.1278, 51.5074)  # London
m.set_zoom(14)

# Animate to a location
m.fly_to(2.3522, 48.8566, zoom=15)  # Paris

Multi-Cell Rendering

AnyMap is designed to work seamlessly across multiple notebook cells:

# Cell 1
m = MapLibreMap(center=[0, 0], zoom=2)
m

# Cell 2 - Same map instance
m.add_marker(0, 0, popup="Origin")

# Cell 3 - Display again
m

Advanced Features

Layer Management

# Add and remove layers
m.add_source("my-source", {
    "type": "geojson",
    "data": geojson_data
})

m.add_layer("my-layer", {
    "id": "my-layer",
    "type": "circle",
    "source": "my-source",
    "paint": {"circle-radius": 5}
})

# Remove layers
m.remove_layer("my-layer")
m.remove_source("my-source")

Custom JavaScript Methods

# Call any MapLibre GL JS method
m.call_js_method('easeTo', {
    'center': [lng, lat],
    'zoom': 14,
    'duration': 2000
})

Examples

Check out the example notebooks in the examples/ directory:

  • basic_usage.ipynb - Basic map creation and interaction
  • advanced_features.ipynb - Advanced layer management and styling
  • multi_cell_test.ipynb - Multi-cell rendering tests

Development

To set up for development:

git clone https://github.com/opengeos/anymap.git
cd anymap
pip install -e .

Run tests:

python -m unittest tests.test_anymap -v

Roadmap

  • ✅ MapLibre GL JS backend
  • ✅ Mapbox GL JS backend
  • ✅ Leaflet backend
  • ✅ OpenLayers backend
  • ✅ DeckGL backend
  • ✅ KeplerGL backend
  • 🔲 Cesium backend
  • 🔲 Potree backend

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anymap-0.6.1.tar.gz (158.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anymap-0.6.1-py2.py3-none-any.whl (180.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file anymap-0.6.1.tar.gz.

File metadata

  • Download URL: anymap-0.6.1.tar.gz
  • Upload date:
  • Size: 158.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for anymap-0.6.1.tar.gz
Algorithm Hash digest
SHA256 e17228b23b0e58e299bc6d28e7b46d6701d29ab971867c7f4d6dd176195a2ddb
MD5 6f8c078b3ae43b8f653817fe617f3646
BLAKE2b-256 bc12ea983671a4998ff8aa483450850710e43cab467621c04d7901c48f273305

See more details on using hashes here.

File details

Details for the file anymap-0.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: anymap-0.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 180.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for anymap-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 26e34918b4cfd7c12a628a2adfa3bafc06521baad10d71d1758d7561940e5491
MD5 5286534889850e1dd7a5dfcb856442f9
BLAKE2b-256 d1487e0ff89f04ee6b751baacb362055f3b46a59214ed9e816c0dc320302c5d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page