Skip to content

Map

The Map is the core component of your visualization, to which other components such as controls, layers or overlays are added. Components can be added either during initialization or afterwards:

import openlayers as ol

# Add components during initialization
m = ol.Map(controls=[ol.ZoomSliderControl()])

# Add components after initialization
m.add_control(ol.FullScreenControl())

View state

Properties such as center, zoom level and projection are managed by the View instance:

import openlayers as ol

initial_view = ol.View(center=(9.5, 51.31667), zoom=14)

m = ol.Map(initial_view)

# Change view settings afterwards
m.set_center(lon=172.606201, lat=-43.556510)
m.set_zoom(14)

m.set_view(ol.View(center=(172.606201, -43.556510), zoom=12))

Basemaps

A basemap in openlayers consists of one or more layers from your layer stack:

import openlayers as ol
from openlayers.basemaps import CartoBasemapLayer, Carto

# Use default OSM basemap
m = ol.Map(layers=[ol.BasemapLayer()])

# Use a CartoDB basemap
m = ol.Map(layers=[CartoBasemapLayer(Carto.DARK_NO_LABELS)])

See BasemapLayer API

If you hand over an empty layer stack to your map, a blank background is displayed:

m = ol.Map(layers=[])