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

130
Views
React Leaflet Polygons not updating with properties

I am trying to draw a set of polygons on a map and then change the color according to an external event which updates a property of the MapContainer. In my example the property is "view". I can see that the property value is updated properly but the polygons are not re-rendered. It's a simple set of polygon without Tile (no geographical map, only the polygons). I tried both with color and fillColor, but nothing changes when I update "view". Should I somehow force a map refresh? If yes, how?

<MapContainer
        id="leaflet-map"        
        center={center}
        zoom={zoom}
      >
        {this.props.data.map((poly, index) => {          
          return (
            <Polygon
              key={`poly-${poly.id}`}
              color={poly.color[this.props.view]}
              fillColor={
                poly.color[this.props.view]
              }
              positions={poly.attributes.coordinates}              
            >              
            </Polygon>
          );
        })}
      </MapContainer>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

OK, I found the answer. I hope this can help others. I have to modify pathOptions.color and pathOptions.fillColor and not directly color and fillColor. It works like this for me:

 <Polygon
              key={`poly-${poly.id}`}
              pathOptions={{  
                color: poly.color[this.props.view],
                fillColor: poly.color[this.props.view]
              }}
              positions={poly.attributes.coordinates}              
            >              
            </Polygon>
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!