I have a Leaflet map with a layer of polygons plotted from some GeoJSON data:
let dataLayer = L.layerGroup()
L.geoJSON(data, {
style: style,
onEachFeature: onDataFeature
})
The onDataFeature add a popup and functionality to zoom to the layer when clicked:
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onDataFeature(feature, layer) {
layer.bindPopup(feature.properties.popup_html)
layer.on({
click: zoomToFeature
});
dataLayer.addLayer(layer)
}
The issue is that the popup appears where you click which is not always in the center of the polygon. I'm trying to figure out if there is a way to move the popup to the center of the polygon after zoomToFeature or to trigger the popup in the middle after zoomToFeature. Any help is greatly appreciated :)