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

120
Visualizações
React Leaflet layer marker doesn't disapperar even after state is empty

My state looks like:

this.state = {
    onWayMarkers: [],
    preparingMarkers: [],
    concludedMarkers: [],
    cancelledMarkers: [],
}

May React Leaflet inside a <MapContainer>:

    <TileLayer
        attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    />        
    <LayersControl>
        <LayersControl.Overlay checked name="Concluded">
            <LayerGroup>
                {this.state.concludedMarkers.map((element, idx) => {
                    const icon = L.divIcon({
                       className: 'custom-icon',
                           html: ReactDOMServer.renderToString(this.mapIconConcluded(element.label)),
                            iconSize: [30, 30],
                            iconAnchor: [10, 32]
                        });

                    return(
                        <Marker key={`marker-${idx}`} position={element.coord} icon={icon}>
                        <Popup>
                        <span>{element.order_id}</span>
                        </Popup>
                        </Marker>
                    );
                })}
            </LayerGroup>
        </LayersControl.Overlay>

I have one of this piece of layer codes for each array item in this.state:

<LayersControl.Overlay name="name"><LayerGroup>{array.map}</LayerGroup></LayersControl.Overlay>  

When I update the state and clear one of the arrays, this happens:
The marker from the specific array disappears
But when I deactivate and activate the layer, the marker comes back ... without the Popup. I've printed console.log(this.state.array) and even with the array emptied the marker comes back

Any ideia on why this is happening and how can I fix it?

about 4 years ago · Juan Pablo Isaza
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