Skip to content

Commit

Permalink
Multimap support
Browse files Browse the repository at this point in the history
When you have more than one map in the same HTML, clipPath ids are conflicting. Also, same id in differents svg cause issues and is not standar https://www.w3.org/TR/SVG/struct.html#IDAttribute.

To support it, we use the layer _leaflet_id property as prefix on ids.
  • Loading branch information
Ruben Pardo committed May 31, 2016
1 parent ec155e2 commit 26ec7de
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions TileLayer.GeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,26 @@ L.TileLayer.GeoJSON = L.TileLayer.Ajax.extend({
L.TileLayer.Ajax.prototype._reset.apply(this, arguments);
},

_getUniqueId: function() {
return this._leaflet_id || ''; // jshint ignore:line
},

// Remove clip path elements from other earlier zoom levels
_removeOldClipPaths: function () {
for (var clipPathId in this._clipPathRectangles) {
var clipPathZXY = clipPathId.split('_').slice(1);
var zoom = parseInt(clipPathZXY[0], 10);
if (zoom !== this._map.getZoom()) {
var rectangle = this._clipPathRectangles[clipPathId];
this._map.removeLayer(rectangle);
var clipPath = document.getElementById(clipPathId);
if (clipPath !== null) {
clipPath.parentNode.removeChild(clipPath);
var prefix = clipPathId.split('tileClipPath')[0];
if (String(this._getUniqueId()) === String(prefix)) {
var clipPathZXY = clipPathId.split('_').slice(1);
var zoom = parseInt(clipPathZXY[0], 10);
if (zoom !== this._map.getZoom()) {
var rectangle = this._clipPathRectangles[clipPathId];
this._map.removeLayer(rectangle);
var clipPath = document.getElementById(clipPathId);
if (clipPath !== null) {
clipPath.parentNode.removeChild(clipPath);
}
delete this._clipPathRectangles[clipPathId];
}
delete this._clipPathRectangles[clipPathId];
}
}
},
Expand Down Expand Up @@ -123,7 +130,7 @@ L.TileLayer.GeoJSON = L.TileLayer.Ajax.extend({
}

// Create the clipPath for the tile if it doesn't exist
var clipPathId = 'tileClipPath_' + tilePoint.z + '_' + tilePoint.x + '_' + tilePoint.y;
var clipPathId = this._getUniqueId() + 'tileClipPath_' + tilePoint.z + '_' + tilePoint.x + '_' + tilePoint.y;
var clipPath = document.getElementById(clipPathId);
if (clipPath === null) {
clipPath = document.createElementNS(L.Path.SVG_NS, 'clipPath');
Expand Down

0 comments on commit 26ec7de

Please sign in to comment.