Use a fallback image
This source code of this example is adapted from the MapLibre GL JS example - Use a fallback image.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
m = leafmap.Map(center=[-77, 38.75], zoom=5, style="streets")
source = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-77.03238901390978, 38.913188059745586],
},
"properties": {"title": "Washington DC", "icon": "monument"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-79.9959, 40.4406]},
"properties": {"title": "Pittsburgh", "icon": "bridges"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-76.2859, 36.8508]},
"properties": {"title": "Norfolk", "icon": "harbor"},
},
],
},
}
m.add_source("points", source)
layer = {
"id": "points",
"type": "symbol",
"source": "points",
"layout": {
"icon-image": [
"coalesce",
["image", ["concat", ["get", "icon"], "_15"]],
["image", "marker_15"],
],
"text-field": ["get", "title"],
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 0.6],
"text-anchor": "top",
},
}
m.add_layer(layer)
m
m = leafmap.Map(center=[-77, 38.75], zoom=5, style="streets")
source = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-77.03238901390978, 38.913188059745586],
},
"properties": {"title": "Washington DC", "icon": "monument"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-79.9959, 40.4406]},
"properties": {"title": "Pittsburgh", "icon": "bridges"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-76.2859, 36.8508]},
"properties": {"title": "Norfolk", "icon": "harbor"},
},
],
},
}
m.add_source("points", source)
layer = {
"id": "points",
"type": "symbol",
"source": "points",
"layout": {
"icon-image": [
"coalesce",
["image", ["concat", ["get", "icon"], "_15"]],
["image", "marker_15"],
],
"text-field": ["get", "title"],
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 0.6],
"text-anchor": "top",
},
}
m.add_layer(layer)
m
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.