I want to bind some data to a Leaflet VectorGrid to make choropleths. However, I sometimes call setFeatureStyle on the vector grid layer before all the tiles have finished loading (for example, if the GeoJSON or processing time takes longer than loading data for the choropleths).
Before pull request #38, this would simply set the new features to the default style I defined when I created the VectorGrid layer.
After pull request #38, the new features become unstyled (Leaflet default style).
var styleOverride = this._overriddenStyles[id] = {}
for (var tileKey in this._vectorTiles) {
var tile = this._vectorTiles[tileKey];
var features = tile._features;
var data = features[id];
if (data) {
styleOverride[data.layerName] = layerStyle;
// ...
Since the new tiles haven't loaded yet, this._vectorTiles may contain old tiles or be empty altogether. This means that calling setFeatureStyle with the new ids will not bind any overridden styles to this._overriddenStyles, but instead bind empty objects. When the tiles do load in, this causes the features to be unstyled.
I'm submitting a PR to hopefully address this (and one other quirk that I found). (edit: here is the PR - #42)
Using latest
master
at 330acf2.I want to bind some data to a Leaflet VectorGrid to make choropleths. However, I sometimes call
setFeatureStyle
on the vector grid layer before all the tiles have finished loading (for example, if the GeoJSON or processing time takes longer than loading data for the choropleths).Before pull request #38, this would simply set the new features to the default style I defined when I created the VectorGrid layer.
After pull request #38, the new features become unstyled (Leaflet default style).
I think I've narrowed down the reason. In Leaflet.VectorGrid.js:
Since the new tiles haven't loaded yet,
this._vectorTiles
may contain old tiles or be empty altogether. This means that callingsetFeatureStyle
with the new ids will not bind any overridden styles tothis._overriddenStyles
, but instead bind empty objects. When the tiles do load in, this causes the features to be unstyled.I'm submitting a PR to hopefully address this (and one other quirk that I found). (edit: here is the PR - #42)