Skip to content

Commit

Permalink
external: quick fix for L.CanvasIconLayer
Browse files Browse the repository at this point in the history
IITC-CE/Leaflet.Canvas-Markers#14
Solves performance issue caused by several large overlapping canvases,
observed in some browsers (especially while zooming/panning).

As it appeared, not all browsers canvas implementations are equal.
Issues reported for FF, Safari, and not up-to-date Android WebView.

TODO: reimplement the fix in better way
  • Loading branch information
johndoe committed Jan 17, 2020
1 parent 72d1e83 commit 803f3f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/external/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
2 changes: 2 additions & 0 deletions core/external/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
* https://github.com/IITC-CE/Leaflet.Canvas-Markers
leaflet.canvas-markers.js: 12fb5afd0a8cb7101a2e8f931e20be76818fe917
(https://github.com/Spaction/Leaflet.Canvas-Markers/pull/3)
+ quickfix https://github.com/IITC-CE/Leaflet.Canvas-Markers/pull/14
https://github.com/IITC-CE/Leaflet.Canvas-Markers/blob/83d8ea3f0fb4d7e242914a9021270326a7a5c03b/src/plugin/leaflet.canvas-markers.js
used in: ornaments.js


Expand Down

0 comments on commit 803f3f7

Please sign in to comment.