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

115
Views
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
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!