leaflet-search icon indicating copy to clipboard operation
leaflet-search copied to clipboard

Conflict with https://github.com/bbecquet/Leaflet.RotatedMarker in Leaflet 1.0.0

Open tomchadwin opened this issue 8 years ago • 2 comments

leaflet.rotatedMarker.js:9
Uncaught TypeError: Cannot read property 'iconAnchor' of undefined
(anonymous function) @ leaflet.rotatedMarker.js:9
proto.callInitHooks @ leaflet.js:365
proto.callInitHooks @ leaflet.js:359
NewClass @ leaflet.js:314
onAdd @ leaflet-search.js:137
addTo @ leaflet.js:11610
addTo @ leaflet-search.js:160
addControl @ leaflet.js:11674
(anonymous function) @ index.html:121

See https://github.com/bbecquet/Leaflet.RotatedMarker/issues/6

tomchadwin avatar Sep 28 '16 14:09 tomchadwin

Hi! It seems the problem occurs because in the default options passed to the subclass L.Control.Search.Marker, icon may be false instead of a valid Iconobject. https://github.com/stefanocudini/leaflet-search/blob/689c3deb30f1138d5e2a8a27610b6daf00df87d6/src/leaflet-search.js#L83

My code in rotatedMarker assumes it's always an Icon object with options, so it crashes. I will add a check to make this line more robust: https://github.com/bbecquet/Leaflet.RotatedMarker/blob/master/leaflet.rotatedMarker.js#L9

But I think the best way to fix the bug is on your side, by avoiding false as a valid icon value in your subclass. As it contradicts the original Leaflet.Marker API, you may run into problems with other plugins as well.

What do you think?

bbecquet avatar Sep 29 '16 17:09 bbecquet

Confirmed that @bbecquet's fix to Leaflet.Rotated marker solves the problem. I've closed the issue on his repo, but will leave this one open so you can implement his suggestions in leaflet-search if you want. Thanks!

tomchadwin avatar Sep 30 '16 07:09 tomchadwin