From a20fd8082884f7106065f4af0c0945f7ab18f4e6 Mon Sep 17 00:00:00 2001 From: slutske22 Date: Thu, 7 May 2020 18:28:57 -0700 Subject: [PATCH] 1.1.3 - modifying L.Map.removeLayer(layer) --- example/with-modules.js | 16 ++++++++++++++++ src/leaflet-arrowheads.js | 40 +++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/example/with-modules.js b/example/with-modules.js index 799a583..a7c1f18 100644 --- a/example/with-modules.js +++ b/example/with-modules.js @@ -517,3 +517,19 @@ function flyToNorway(){ somePopup.closePopup() } + + + +window.simpleVector0 = simpleVector0 +window.map = map + +L.control.layers(null, { + "Vector 1": simpleVector0, + "Vector 2": simpleVector1, + "Vector 3": simpleVector2, + "Vector 4": simpleVector3, + "Vector 5": simpleVector4, + "Vector 6": simpleVector5, + "Group 2": group2, + "Group 3": group3 +}).addTo(map) \ No newline at end of file diff --git a/src/leaflet-arrowheads.js b/src/leaflet-arrowheads.js index 476fcb8..7e4a13f 100644 --- a/src/leaflet-arrowheads.js +++ b/src/leaflet-arrowheads.js @@ -30,8 +30,6 @@ L.Polyline.include({ // Reset variables from previous this._update() if (this._arrowheads){ this._arrowheads.remove() - let arrowheads = [] - let allhats = [] } // -------------------------------------------------------- // @@ -372,8 +370,7 @@ L.Polyline.include({ remove: function () { if (this._arrowheads){ - this._arrowheads.removeFrom(this._map || this._mapToAdd); - this._arrowheads = [] + this._arrowheads.remove(); } return this.removeFrom(this._map || this._mapToAdd); }, @@ -415,3 +412,38 @@ L.LayerGroup.include({ }) + + +L.Map.include({ + + removeLayer: function (layer) { + + var id = L.Util.stamp(layer); + + if (layer._arrowheads){ + layer._arrowheads.remove() + } + + if (!this._layers[id]) { return this; } + + if (this._loaded) { + layer.onRemove(this); + } + + if (layer.getAttribution && this.attributionControl) { + this.attributionControl.removeAttribution(layer.getAttribution()); + } + + delete this._layers[id]; + + if (this._loaded) { + this.fire('layerremove', {layer: layer}); + layer.fire('remove'); + } + + layer._map = layer._mapToAdd = null; + + return this; + }, + +})