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

149
Views
Refresh MapBox Markers on a Timer?

I'm pretty new to JS apologies if this is basic. I'm putting together an application that pushes geo data from mobile up to MongoDB then plotting it on my browser with MapBox. I was able to follow this pretty good tutorial to get to the point where I can see all my datapoints.

Now I want to make it so that the page automatically refreshes by requesting an update from the server and reloading the markers accordingly. I figured out that I am able to set up a timer function like so:

const timer = setInterval(() => {
          console.log("Hello after 5s!");

}, 5000);

Now I need to know how to make it update the map. I see that the MapBox API has map.on("load"/"dblclick").. functions however not clear to me how to achieve my goal. How do I make requests and then re-render the map periodically?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was able to solve this with the getSource..setData paradigm like so:

async function refreshMarkers(){
          placeMarkers.forEach(marker => marker.remove());
          placeMarkers = await getPointsOfInterest([-121.4252, 37.7397]);
          console.log("placemarkers " + placeMarkers);
          map.getSource('markers').setData(placeMarkers);
          placeMarkers.forEach(marker => marker.addTo(map));
        }

        //TODO: 3. Create lookups for appropriate marker colors
        const timer = setInterval(() => {
          refreshMarkers();
        }, 30000);
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!