aviklai / react-leaflet-google-layer

Google layer for React-Leaflet using leaflet.gridlayer.googlemutant, implemented with typescript
MIT License
48 stars 8 forks source link

Can't set type dynamically #13

Closed hexadeciman closed 4 years ago

hexadeciman commented 4 years ago

When interpolating the type prop of in jsx only the initial value is taken into account, modifying the type doesn't seem to influence the google mutant layer

aviklai commented 4 years ago

Hi,

Sorry for the late response. Yes - you are correct. The reason for this is that internally, the google mutant library initializes a new google maps instance with the type you provided. In order to change the type, it has to initialize a new google maps instance (it doesn't support changing the map type dynamically).

Maybe you can try setting the key of ReactLeafletGoogleLayer to the type of the map so when you change the type, the key will change, and React will create a new instance of ReactLeafletGoogleLayer with the new type.

Please look at this example: https://codesandbox.io/s/basic-usage-z3x1m