Layers and sources
Sources and layers are used to display raster or vector data on your map.
Sources
Sources state which data the map should display.
import openlayers as ol
geojson = ol.VectorSource(
url="https://openlayers.org/en/latest/examples/data/geojson/roads-seoul.geojson"
)
geotiff = ol.GeoTIFFSource(
sources=[{"url": "https://s2downloads.eox.at/demo/EOxCloudless/2020/rgbnir/s2cloudless2020-16bits_sinlge-file_z0-4.tif"}]
)
pmtiles = ol.PMTilesVectorSource(
url="https://r2-public.protomaps.com/protomaps-sample-datasets/nz-buildings-v3.pmtiles",
attributions=["© Land Information New Zealand"]
)
See Sources API
Layers
A layer defines how a source is displayed on the map:
import openlayers as ol
data = "https://openlayers.org/en/latest/examples/data/geojson/roads-seoul.geojson"
vector = ol.VectorLayer(
id="roads",
source=ol.VectorSource(url=data),
fit_bounds=True,
)
m = ol.Map(
ol.View(rotation=3.14 / 8),
layers=[ol.BasemapLayer(), vector]
)
m.add_default_tooltip()
See Layers API
Styles
Vector layers are styled with an object containing properties for the different styles, such as stroke, fill, circle or icon:
It is also possible to use a simple dictonary instead. In this case property names must use hyphens instead of underscores:
See Styles API and ol/style/flat for details.