Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping zoom animation for empty layers to improve performance #14

Open
wants to merge 2 commits into
base: getevents
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/plugin/leaflet.canvas-markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,22 @@ function layerFactory (L) {
this._latlngsIdx = new LatLngsIndex();
},

_checkDisplay() {
if (this._latlngsIdx._total) {
this._container.style.display = 'initial';
} else {
this._container.style.display = 'none';
}
},

onAdd: function () {
L.Renderer.prototype.onAdd.call(this);
L.DomUtil.toBack(this._container);
},

_initContainer: function () {
L.Canvas.prototype._initContainer.call(this);
this._checkDisplay();
},

onRemove: function () {
Expand Down Expand Up @@ -331,6 +340,7 @@ function layerFactory (L) {
this._pointsIdx.insert(marker, batch);
}
this._latlngsIdx.insert(marker, batch);
this._checkDisplay();
},

// Adds single layer at a time. Less efficient for rBush
Expand Down Expand Up @@ -396,12 +406,14 @@ function layerFactory (L) {
}).forEach(function (el) {
this._latlngsIdx.remove(el);
}, this);
this._checkDisplay();
},

removeMarker: function (marker, redraw) {
var latlng = marker.getLatLng();
var isDisplaying = this._map && this._map.getBounds().pad(this.options.padding).contains(latlng);
this._latlngsIdx.remove(marker);
this._checkDisplay();

if (isDisplaying && redraw) {
this._redraw();
Expand All @@ -426,6 +438,7 @@ function layerFactory (L) {
this._latlngsIdx.clear();
this._pointsIdx.clear();
this._clear();
this._checkDisplay();
return this;
}
});
Expand Down