#Leaflet question:
-
#Leaflet question:
Google MyMaps allows you to display a list of custom locations you have placed on that map. And then you can click on any item on that list, and the map will zoom to the relevant location.
Is anything similar possible with Leaflet? And if so, could you point me to documentation or a tutorial?
-
#Leaflet question:
Google MyMaps allows you to display a list of custom locations you have placed on that map. And then you can click on any item on that list, and the map will zoom to the relevant location.
Is anything similar possible with Leaflet? And if so, could you point me to documentation or a tutorial?
@juergen_hubert Fairly simple with some basic javascript.
Most basic for markers:
const layer = new L.geoJSON(data, {
onEachFeature: (feature, layer) => {
layer.on({
click: (e) => {
map.panTo(e.target.getLatLng());
}
})
}
});There are slight variations depending on what kind of layer you're using, but search the docs for map.panTo or map.zoomTo. You can add events as a function of a layer group, or add the event to the marker layer as it's added. Does that help?
-
@juergen_hubert Fairly simple with some basic javascript.
Most basic for markers:
const layer = new L.geoJSON(data, {
onEachFeature: (feature, layer) => {
layer.on({
click: (e) => {
map.panTo(e.target.getLatLng());
}
})
}
});There are slight variations depending on what kind of layer you're using, but search the docs for map.panTo or map.zoomTo. You can add events as a function of a layer group, or add the event to the marker layer as it's added. Does that help?
@zeigert I don't know yet, but it's worth looking into. Thanks!