Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!