Skip to content

Commit

Permalink
implement hasLayer method
Browse files Browse the repository at this point in the history
And fix some related bugs
  • Loading branch information
johndoe committed May 20, 2020
1 parent e4df1b9 commit affa3f5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/plugin/leaflet.canvas-markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit affa3f5

Please sign in to comment.