Leaflet.MapCenterCoord
Leaflet.MapCenterCoord copied to clipboard
Issue with switching plugin off and solution
Hi, thank you for making this plugin available. I created a button to turn it on and off. When turning it off, not all event listeners were turned off.
I think it was a small typo in onRemove
on line 45 of L.Control.MapCenterCoord.js.
Current code of plugin:
38 onRemove: function (map) {
39 // remove icon's DOM elements and listeners
40 if (this.options.icon) {
41 map.getPanes().overlayPane.removeChild(this._iconEl);
42 map.off('viewreset', this._onReset, this);
43 }
44 map.off('move', this._onMapMove, this);
45 map.off('moveend', this._onMapMove, this); /* _onMapMove should be _onMapMoveEnd */
46 },
Correction:
38 onRemove: function (map) {
39 // remove icon's DOM elements and listeners
40 if (this.options.icon) {
41 map.getPanes().overlayPane.removeChild(this._iconEl);
42 map.off('viewreset', this._onReset, this);
43 }
44 map.off('move', this._onMapMove, this);
45 map.off('moveend', this._onMapMoveEnd, this); /* corrected */
46 },
With this correction my button turns plugin on and off as expected.