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

299
Visualizações
How to render multiple markers from an array of coordinates in react leaflet

as the title says i'm trying to render multiple markers over the map by using react leaflet. I'm gathering all the coordinates that i receive from a BE response and i put them into an array. When i render the component i only see the map without my markers. So i'm probably missing out something.

Here's my code:

var arrCoordinates = [[/* coordinates 1 */], [/* coordinates2 */]...[/* coordinates n */]]

function MultipleMarkers(){
    
    const map = useMapEvent({
        click(){
            map.locate()
        }
    })
    return arrCoordinate.map(coordinata => {
        <Marker position={coordinata}
            icon={new Icon({iconUrl: marker, iconSize: [25, 41], iconAnchor: [12, 41]})}>
            <Popup>{Object.keys(elem).length > 0 ? elem.bodyfindSegnalazione[0][0].indirizzo + ' ' + elem.bodyfindSegnalazione[0][0].civico + ' ' + elem.bodyfindSegnalazione[0][0].quartiere : ''}</Popup>
        </Marker>
    })
}
return (
    <div id="mapid" style={{display: showMap}}>
    <MapContainer 
        center={center} zoom={12} 
        scrollWheelZoom={true}
        style={{ height: "100%", width: "100%" }}
    >
        <TileLayer
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
        <MultipleMarkers />
        
    </MapContainer>
    </div>
);

I'll appreciate any suggestions, thanks in advance. Peace

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you are missing is the return statement before <Marker.

It should be

function MultipleMarkers() {
  const map = useMapEvent({
    click() {
      map.locate();
    }
  });

  return arrCoordinates.map((coordinata) => {
    return (
       <Marker position={coordinata}
        icon={new Icon({iconUrl: marker, iconSize: [25, 41], iconAnchor: [12, 41]})}>
        <Popup>{Object.keys(elem).length > 0 ? elem.bodyfindSegnalazione[0][0].indirizzo + ' ' + elem.bodyfindSegnalazione[0][0].civico + ' ' + elem.bodyfindSegnalazione[0][0].quartiere : ''}</Popup>
       </Marker>
    );
  });
}

Simplified example demo

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