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

224
Vistas
How to solve this problem with pop-ups in Leaflet

I have a website featuring a map with a marker for different places of interest. I am using the js code below that works perfectly :

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);
        
//.  t is an array containing gps positions of the different places
for(i=0;i<t.length;i++){
    var marker = L.marker([t[i][lat], t[i][lon]]).addTo(mymap);
}

But when I try to add a pop-up for each marker with the code below, the whole map is moved to the left, and not centered anymore on the initial position defined with setView :

for(i=0;i<t.length;i++){
    var marker = L.marker([t[i][lat], t[i][lon]]).addTo(mymap);
    marker.bindPopup("<b>mon titre"</b><br>mon texte").openPopup();
}

Any idea of what is going on and the best way to solve the problem ? Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I found the solution : the problem comes from the fact that the pop-ups are open. Using the following line of code works :

marker.bindPopup("<b>mon titre"</b><br>mon texte").closePopup();

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