Draw GeoJSON points
Draw points from a GeoJSON collection to a map.
This source code of this example is adapted from the MapLibre GL JS example - Draw GeoJSON points.
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!
m = leafmap.Map(center=[0, 0], zoom=1, style="positron")
image = "https://maplibre.org/maplibre-gl-js/docs/assets/osgeo-logo.png"
m.add_image("custom-marker", image)
source = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [100.4933, 13.7551]},
"properties": {"year": "2004"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [6.6523, 46.5535]},
"properties": {"year": "2006"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-123.3596, 48.4268]},
"properties": {"year": "2007"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [18.4264, -33.9224]},
"properties": {"year": "2008"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [151.195, -33.8552]},
"properties": {"year": "2009"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [2.1404, 41.3925]},
"properties": {"year": "2010"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-104.8548, 39.7644]},
"properties": {"year": "2011"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-1.1665, 52.9539]},
"properties": {"year": "2013"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-122.6544, 45.5428]},
"properties": {"year": "2014"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [126.974, 37.5651]},
"properties": {"year": "2015"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [7.1112, 50.7255]},
"properties": {"year": "2016"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-71.0314, 42.3539]},
"properties": {"year": "2017"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [39.2794, -6.8173]},
"properties": {"year": "2018"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [26.0961, 44.4379]},
"properties": {"year": "2019"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-114.0879, 51.0279]},
"properties": {"year": "2020"},
},
],
},
}
m.add_source("conferences", source)
layer = {
"id": "conferences",
"type": "symbol",
"source": "conferences",
"layout": {
"icon-image": "custom-marker",
"text-field": ["get", "year"],
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 1.25],
"text-anchor": "top",
},
}
m.add_layer(layer)
m
m = leafmap.Map(center=[0, 0], zoom=1, style="positron")
image = "https://maplibre.org/maplibre-gl-js/docs/assets/osgeo-logo.png"
m.add_image("custom-marker", image)
source = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [100.4933, 13.7551]},
"properties": {"year": "2004"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [6.6523, 46.5535]},
"properties": {"year": "2006"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-123.3596, 48.4268]},
"properties": {"year": "2007"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [18.4264, -33.9224]},
"properties": {"year": "2008"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [151.195, -33.8552]},
"properties": {"year": "2009"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [2.1404, 41.3925]},
"properties": {"year": "2010"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-104.8548, 39.7644]},
"properties": {"year": "2011"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-1.1665, 52.9539]},
"properties": {"year": "2013"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-122.6544, 45.5428]},
"properties": {"year": "2014"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [126.974, 37.5651]},
"properties": {"year": "2015"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [7.1112, 50.7255]},
"properties": {"year": "2016"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-71.0314, 42.3539]},
"properties": {"year": "2017"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [39.2794, -6.8173]},
"properties": {"year": "2018"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [26.0961, 44.4379]},
"properties": {"year": "2019"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-114.0879, 51.0279]},
"properties": {"year": "2020"},
},
],
},
}
m.add_source("conferences", source)
layer = {
"id": "conferences",
"type": "symbol",
"source": "conferences",
"layout": {
"icon-image": "custom-marker",
"text-field": ["get", "year"],
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 1.25],
"text-anchor": "top",
},
}
m.add_layer(layer)
m