Skip to content

Commit

Permalink
Fix variable repurposing and out-of-order conditional (#3369)
Browse files Browse the repository at this point in the history
The `layer` variable was being used for both style layers and source layers. As a result, the fact that the `version === 1` conditional was being checked at the wrong point went unnoticed.

The `if (layer)` conditional was also misplaced, but fortunately it didn't matter because the prior loop already skips style layers whose source layer does not exist.
  • Loading branch information
jfirebaugh authored and mourner committed Oct 14, 2016
1 parent 3d1d6c0 commit f3ac2e5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ WorkerTile.prototype.parse = function(data, layerFamilies, actor, callback) {
var bucketsById = {};
var bucketsBySourceLayer = {};
var i;
var layer;
var sourceLayerId;
var bucket;

// Map non-ref layers to buckets.
var bucketIndex = 0;
for (var layerId in layerFamilies) {
layer = layerFamilies[layerId][0];
var layer = layerFamilies[layerId][0];

if (layer.source !== this.source) continue;
if (layer.ref) continue;
Expand Down Expand Up @@ -80,17 +79,15 @@ WorkerTile.prototype.parse = function(data, layerFamilies, actor, callback) {
// read each layer, and sort its features into buckets
if (data.layers) { // vectortile
for (sourceLayerId in bucketsBySourceLayer) {
if (layer.version === 1) {
var sourceLayer = data.layers[sourceLayerId];
if (sourceLayer.version === 1) {
util.warnOnce(
'Vector tile source "' + this.source + '" layer "' +
sourceLayerId + '" does not use vector tile spec v2 ' +
'and therefore may have some rendering errors.'
);
}
layer = data.layers[sourceLayerId];
if (layer) {
sortLayerIntoBuckets(layer, bucketsBySourceLayer[sourceLayerId]);
}
sortLayerIntoBuckets(sourceLayer, bucketsBySourceLayer[sourceLayerId]);
}
} else { // geojson
sortLayerIntoBuckets(data, bucketsById);
Expand Down

0 comments on commit f3ac2e5

Please sign in to comment.