PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.13k stars 884 forks source link

Set icon making marker draggable again #178

Closed littlemaneuver closed 8 years ago

littlemaneuver commented 8 years ago

Please make sure to check the following boxes before submitting an issue. Thanks!

We are using leaflet icon as an icon so inside the componentDidUpdate method check like this.props.icon !== prevProps.icon is always true. It triggers setIcon method. This method is making marker draggable again here is the original issue

Actual behavior

The marker is draggable even I've changed my draggable prop to false

Steps to reproduce

<Marker
          draggable={props.draggable} //true on init
          ... 
          icon={L.icon({
                      iconUrl: "some/icon.png",
                      iconSize: [35, 50],
                      iconAnchor: [25, 45]
                    })
           }
/>

then update props.drggable to false and you'll still get drggable marker.

This behavior could be fixed by setting more complex check on the icon property or by allowing to use leaflet version 1.0.0-rc.1

here is the proof this jsfiddle.

PaulLeCam commented 8 years ago

It seems to be an issue in Leaflet itself and not caused by this library, so you'll have to wait for a fix upstream or implement a workaround yourself.

littlemaneuver commented 8 years ago

The fix has been released already, but your peerDependency doesn't allow me to install version later than 0.7.x. and another reason is checking for the identity of two objects (leaflet icon), otherwise, setIcon is called every propagation cycle.

PaulLeCam commented 8 years ago

peerDependencies does not constraint you in any way using npm 3, if you want to use another version you can set it in your own package.json, but this library is not made to be compatible with Leaflet v1 yet, so it won't be supported until then. So you can either implement a fix in your application code or wait for a release compatible with Leaflet v1, but I don't plan on implementing a fix in this lib itself as it's an issue from Leaflet.