mhasbie / react-leaflet-vectorgrid

React wrapper of Leaflet.VectorGrid. Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet.
MIT License
19 stars 10 forks source link

Component not updating/re-rendering on changing redux props #9

Closed apal21 closed 5 years ago

apal21 commented 5 years ago

I'm using this library to load a GeoJSON file but I'm changing the opacity using redux. For the first time, it is loading the proper opacity but not updating it after dispatching the actions to update props.

Currently, to make this thing work, I added this code but it is a bit laggy.

updateLeafletElement(oldProps, newProps) {
    if (oldProps != newProps) {
        this.forceUpdate();
    }
}

I think there should be a way to make this work properly.

mecmartini commented 5 years ago

You must set a unique key value on your vector layer. This is not documented on react-leaflet-vectorgrid but it is on react-leaflet.

As example, in my case I managed it like this:

const provinceKey = 'province_' + regionFilter + provinceFilter + departmentFilter;
const departmentkey = 'department_' + regionFilter + provinceFilter + departmentFilter;

...

return(
  <VectorGrid key={provinceKey} {...provincesOptions} />
  <VectorGrid key={departmentkey} {...departementsOptions} />
)
apal21 commented 5 years ago

Thank you for the response. I'll try this and let you know in this thread.

apal21 commented 5 years ago

Thank you @mecmartini. It is working properly. Closing this issue.