Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

335
Vistas
How to center a popup on a polygon using Leaflet

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 :)

enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda