Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

340
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda