GeoJson: style changes would never be updated
render() {
const style = _.defaults(location.style, {
stroke: true,
color: "#2e5696",
opacity: 0.6,
weight: 2,
dashArray: "1",
fill: true,
fillColor: "#2e5696",
fillOpacity: 0.3,
});
return (
<GeoJson
style={style}
data={location.geojson}
layerContainer={layerContainer}
map={map}
>
</GeoJson>);
}
}
i did init GeoJson as above, the style is correct. But when i change the style later, the GeoJson would not be updated. Took a look at getPathOptions in Path.js always return empty style.

I'm going with a workaround like this:
render() {
return (
<GeoJson
key={location.id}
style={style}
data={location.geojson}
onEachFeature={this.onEachFeature}
layerContainer={layerContainer}
map={map}
{...style}
>
</GeoJson>);
}
L.geoJson( <Object> geojson?, <GeoJSON options> options? )
options of GeoJSONare not Path options like CircleMarker.
L.circleMarker( <LatLng> latlng, <Path options> options? )
I think we should change componentDidUpdate of _GeoJson.js_ to
componentDidUpdate(prevProps) {
this.setStyleIfChanged(prevProps.style, this.props.style);
}
What do you think @PaulLeCam @boromisp ? I can create PR for this
I believe how it currently works is the expected result because of how leafletjs works in the background, even though its not intuitive. Proposing to make the styles object a dynamic prop will break the resetStyles function.
For more information...
leafletjs will do something similar to
this.options = { ...this.options, ...this.options.styles }
when you initialize. This is because the options.styles is considered the source and is never changed. Instead the options object is changed when setStyles function is used. (source).
This is because leafletjs holds the initial styles for resetStyle. Setting styles={styles} will set the initial styles, so when resetStyles is called, it will use this object to resetStyles. Making the styles prop dynamic will break leafletjs's reference to the initial styles.
@PaulLeCam A bigger problem tied to GeoJson styles (for me) is that react-leaflet styles are only allowed to be objects, but leaflet allows styles to be objects or functions (source).
Hi,
Indeed, the style prop should be updated as expected if it is a function, that should be fixed in v0.11.6.