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

151
Visualizações
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 Respostas
Responde à pergunta

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