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

245
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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