Skip to content

Commit

Permalink
add layer property when creation geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Mar 7, 2016
1 parent dd2838d commit f5bc540
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
19 changes: 14 additions & 5 deletions js/data/feature_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ FeatureTree.prototype.query = function(result, args, styleLayersByID, returnGeoJ

var matching = this.grid.query(minX - additionalRadius, minY - additionalRadius, maxX + additionalRadius, maxY + additionalRadius);
var match = this.featureIndexArray.at(0);
this.filterMatching(result, matching, match, queryGeometry, filter, params.layerIds, styleLayersByID, args.bearing, pixelsToTileUnits, returnGeoJSON);
this.filterMatching(result, matching, match, queryGeometry, filter, params.layerIDs, styleLayersByID, args.bearing, pixelsToTileUnits, returnGeoJSON);

var matchingSymbols = this.collisionTile.queryRenderedSymbols(minX, minY, maxX, maxY, args.scale);
var match2 = this.collisionTile.collisionBoxArray.at(0);
this.filterMatching(result, matchingSymbols, match2, queryGeometry, filter, params.layerIds, styleLayersByID, args.bearing, pixelsToTileUnits, returnGeoJSON);
this.filterMatching(result, matchingSymbols, match2, queryGeometry, filter, params.layerIDs, styleLayersByID, args.bearing, pixelsToTileUnits, returnGeoJSON);

if (!returnGeoJSON) {
result = result.arrayBuffer;
Expand Down Expand Up @@ -194,6 +194,7 @@ FeatureTree.prototype.filterMatching = function(result, matching, match, queryGe
}

var styleLayer = styleLayersByID[layerID];
if (!styleLayer) continue;

var translatedPolygon;
if (styleLayer.type !== 'symbol') {
Expand Down Expand Up @@ -228,7 +229,9 @@ FeatureTree.prototype.filterMatching = function(result, matching, match, queryGe

if (returnGeoJSON) {
var geojsonFeature = new GeoJSONFeature(feature, this.z, this.x, this.y);
geojsonFeature.layer = layerID;
geojsonFeature.layer = styleLayer.serialize({
includeRefProperties: true
});
result.push(geojsonFeature);
} else {
result.emplaceBack(match.featureIndex, match.sourceLayerIndex, match.bucketIndex, l);
Expand All @@ -237,7 +240,7 @@ FeatureTree.prototype.filterMatching = function(result, matching, match, queryGe
}
};

FeatureTree.prototype.makeGeoJSON = function(result, featureIndexArray) {
FeatureTree.prototype.makeGeoJSON = function(result, featureIndexArray, styleLayers) {
if (!this.vtLayers) {
if (!this.rawTileData) return [];
this.vtLayers = new vt.VectorTile(new Protobuf(new Uint8Array(this.rawTileData))).layers;
Expand All @@ -260,8 +263,14 @@ FeatureTree.prototype.makeGeoJSON = function(result, featureIndexArray) {
}

var feature = cachedFeatures[featureIndex] = cachedFeatures[featureIndex] || sourceLayer.feature(featureIndex);

var styleLayer = styleLayers[this.numberToLayerIDs[indexes.bucketIndex][indexes.layerIndex]];
if (!styleLayer) continue;

var geojsonFeature = new GeoJSONFeature(feature, this.z, this.x, this.y);
geojsonFeature.layer = this.numberToLayerIDs[indexes.bucketIndex][indexes.layerIndex];
geojsonFeature.layer = styleLayer.serialize({
includeRefProperties: true
});
result.push(geojsonFeature);
}
};
Expand Down
2 changes: 1 addition & 1 deletion js/source/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ exports._queryRenderedVectorFeatures = function(queryGeometry, params, classes,
collisionTile: collisionTile.data,
rawTileData: tileIn.tile.rawTileData.slice()
}, function(err_, data) {
if (data) tileIn.tile.featureTree.makeGeoJSON(features, data);
if (data) tileIn.tile.featureTree.makeGeoJSON(features, data, styleLayers);
callback();
}, tileIn.tile.workerID);
}.bind(this), function() {
Expand Down
16 changes: 3 additions & 13 deletions js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Style.prototype = util.inherit(Evented, {
var error = null;

if (params.layer) {
params.layerIds = Array.isArray(params.layer) ? params.layer : [params.layer];
params.layerIDs = Array.isArray(params.layer) ? params.layer : [params.layer];
}

util.asyncAll(Object.keys(this.sources), function(id, callback) {
Expand All @@ -419,18 +419,8 @@ Style.prototype = util.inherit(Evented, {
});
}.bind(this), function() {
if (error) return callback(error);

callback(null, features
.filter(function(feature) {
return this._layers[feature.layer] !== undefined;
}.bind(this))
.map(function(feature) {
feature.layer = this._layers[feature.layer].serialize({
includeRefProperties: true
});
return feature;
}.bind(this)));
}.bind(this));
callback(null, features);
});
},

_remove: function() {
Expand Down

0 comments on commit f5bc540

Please sign in to comment.