From affa3f5c1c5b8aee979fa79532a1223dcb3f7e34 Mon Sep 17 00:00:00 2001 From: johndoe Date: Wed, 20 May 2020 14:52:43 +0300 Subject: [PATCH] implement hasLayer method And fix some related bugs --- src/plugin/leaflet.canvas-markers.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/plugin/leaflet.canvas-markers.js b/src/plugin/leaflet.canvas-markers.js index 16c872a..ba26b22 100644 --- a/src/plugin/leaflet.canvas-markers.js +++ b/src/plugin/leaflet.canvas-markers.js @@ -231,7 +231,9 @@ function layerFactory (L) { img.onload = function () { queued.loaded = true; queued.queue.forEach(function (_marker) { - this._drawImage(_marker); + if (this.hasLayer(_marker)) { + this._drawImage(_marker); + } }, this); }.bind(this); } @@ -399,16 +401,16 @@ function layerFactory (L) { this._latlngsIdx.all().filter(function (marker) { return marker._canvasGroupID === groupID; }).forEach(function (el) { - this._latlngsIdx.remove(el); + this.removeMarker(el, false, true); }, this); }, - removeMarker: function (marker, redraw) { - var latlng = marker.getLatLng(); - var isDisplaying = this._map && this._map.getBounds().pad(this.options.padding).contains(latlng); + removeMarker: function (marker, redraw, hasLayer) { + if (!hasLayer && !this.hasLayer(marker)) { return; } this._latlngsIdx.remove(marker); - if (isDisplaying && redraw) { + if (redraw && this._map && + this._map.getBounds().pad(this.options.padding).contains(marker.getLatLng())) { this._redraw(); } marker.removeEventParent(this); @@ -434,6 +436,11 @@ function layerFactory (L) { return this; }, + hasLayer: function (layer) { + // return this._latlngsIdx.all().indexOf(layer) !== -1; + return layer._eventParents[L.Util.stamp(this)]; // !! to cut corners + }, + _hideContainer: function (hide) { if (this._isEmpty === hide) { return; } this._isEmpty = hide;