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

243
Visualizações
Why does my Leaflet map centered the point of its lower left coner?

I have a leaflet map on my website with markers. However, I can't centered it well on Paris. This code works :

map.setView([lat,lng],zoom);

The map shows Paris as it's supposed to but the point I chose is not in the middle of my map. The map is centered on its lower left corner

Does someone know how to center the point in the middle of my map?

Thank's

Edit : full code

 var map = L.map('map', {
    scrollWheelZoom: false
})
map.setView(<?php echo "[".$latVille.", ".$lngVille."], ".$zoomVille;?>);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
    maxZoom: 18,
    id: 'mapbox/streets-v8',
    tileSize: 512,
    zoomOffset: -1,
    accessToken: ''
}).addTo(map);
Array.from($(".js-marker")).forEach((item) => {
        let marker = L.popup({
                                autoClose: false,
                                closeOnEsacapeKey: false,
                                closeOnClick: false,
                                closeButton: false,
                                className: 'marker',
                                maxWidth: 300
                            })
                                .setLatLng([item.dataset.lat,item.dataset.lng])
                                .setContent(item.dataset.prix+' €')
                                .openOn(map);})

Result : Screenshot

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you are adding markers it may be because of that, set the view after the markers are added, but hard to tell without the code.

I use for the tiles and this code will centre on the point

L.mapbox.accessToken = 'Your token';
var map = L.mapbox.map('map')
  .setView([52.462610, -1.588580], 14)
  .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));
about 4 years ago · Juan Pablo Isaza Relatório

0

Not sure if it's the best way to do it but I used setView after setting the markers and it works !

about 4 years ago · Juan Pablo Isaza Relatório
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