Skip to content

Commit

Permalink
Allow multiple features per ID per tile (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-ward authored and IvanSanchez committed Jul 26, 2019
1 parent 5d6f31e commit a6f19ad
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/Leaflet.VectorGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ L.VectorGrid = L.GridLayer.extend({
}

if (storeFeatures) {
renderer._features[id] = {
// multiple features may share the same id, add them
// to an array of features
if (!renderer._features[id]) {
renderer._features[id] = [];
}

renderer._features[id].push({
layerName: layerName,
feature: featureLayer
};
});
}
}

Expand All @@ -166,17 +172,18 @@ L.VectorGrid = L.GridLayer.extend({

for (var tileKey in this._vectorTiles) {
var tile = this._vectorTiles[tileKey];
var features = tile._features;
var data = features[id];
if (data) {
var feat = data.feature;

var styleOptions = layerStyle;
if (layerStyle[data.layerName]) {
styleOptions = layerStyle[data.layerName];
}

this._updateStyles(feat, tile, styleOptions);
var features = tile._features[id];
if (features) {
for (var i=0; i<features.length; i++) {
var feature = features[i];

var styleOptions = layerStyle;
if (layerStyle[feature.layerName]) {
styleOptions = layerStyle[feature.layerName];
}

this._updateStyles(feature.feature, tile, styleOptions);
}
}
}
return this;
Expand All @@ -189,13 +196,15 @@ L.VectorGrid = L.GridLayer.extend({

for (var tileKey in this._vectorTiles) {
var tile = this._vectorTiles[tileKey];
var features = tile._features;
var data = features[id];
if (data) {
var feat = data.feature;
var styleOptions = this.options.vectorTileLayerStyles[ data.layerName ] ||
L.Path.prototype.options;
this._updateStyles(feat, tile, styleOptions);
var features = tile._features[id];
if (features) {
for (var i=0; i<features.length; i++) {
var feature = features[i];

var styleOptions = this.options.vectorTileLayerStyles[feature.layerName] ||
L.Path.prototype.options;
this._updateStyles(feature.feature, tile, styleOptions);
}
}
}
return this;
Expand Down

0 comments on commit a6f19ad

Please sign in to comment.