Map#

The Map class in ipyopenlayers serves as the primary widget for rendering interactive maps in Jupyter notebooks. It allows users to visualize and interact with geographic data by adding various layers, overlays, and controls. With support for custom basemaps and dynamic updates, the Map widget provides a powerful tool for geographic data analysis and visualization.

Example#

from ipyopenlayers import Map,RasterTileLayer

m = Map(
    center=[0, 0],
    zoom=2
)
# Add layer
layer=RasterTileLayer()
m.add_layer(layer)


# Display the map
m

Usage#

You can add multiple layers, overlays, and controls to the map using the add methods. All of these components are widgets themselves, allowing you to dynamically update their attributes from Python or by interacting with the map on the page.

As a Jupyter interactive widget, the layout of the Map object is specified by its Layout attribute. For more details, see the section on Layout and Styling of Jupyter widgets.

You can use multiple basemaps by manually creating TileLayer objects and passing them to the Map constructor.

Attributes and methods#

class ipyopenlayers.openlayers.Map(**kwargs: Any)[source]#

Map class.

The Map class is the main widget in ipyopenlayers.

layers#

The list of layers that are currently on the map.

Type:

list of Layer instances

controls#

The list of controls that are currently on the map.

Type:

list of Control instances

overlays#

The list of Overlays that are currently on the map.

Type:

list of Overlay instances

center#

The current center of the map.

Type:

list, default [0, 0]

zoom#

The current zoom value of the map.

Type:

float, default 0

add_control(control)[source]#

Add a control on the map.

Parameters:

control (Control instance) – The new control to add.

add_layer(layer)[source]#

Add a layer on the map.

Parameters:

layer (Layer instance) – The new layer to add.

add_overlay(overlay)[source]#

Add an overlay to the map.

Parameters:

overlay (BaseOverlay instance) – The overlay to add.

clear_layers()[source]#

Remove all layers from the map.

on_click(callback, remove=False)[source]#

Add a click event listener.

remove_control(control)[source]#

Remove a control from the map.

Parameters:

control (Control instance) – The control to remove.

remove_layer(layer)[source]#

Remove a layer from the map.

Parameters:

layer (Layer instance) – The layer to remove.

remove_overlay(overlay)[source]#

Remove an overlay from the map.

Parameters:

overlay (BaseOverlay instance) – The overlay to remove.