Skip to content

Commit

Permalink
rename layers property from layer to layers
Browse files Browse the repository at this point in the history
and accept only an array of strings.

fix #2230
  • Loading branch information
ansis committed Mar 15, 2016
1 parent f65d807 commit 48f5993
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions js/data/feature_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ FeatureTree.prototype.query = function(args, styleLayersByID, returnGeoJSON) {
var matching = this.grid.query(minX - additionalRadius, minY - additionalRadius, maxX + additionalRadius, maxY + additionalRadius);
matching.sort(topDown);
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.layers, styleLayersByID, args.bearing, pixelsToTileUnits, returnGeoJSON);

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

return result;
};
Expand Down
8 changes: 0 additions & 8 deletions js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,6 @@ Style.prototype = util.inherit(Evented, {
},

queryRenderedFeaturesAsync: function(queryGeometry, params, classes, zoom, bearing, callback) {
if (params.layer) {
params.layerIDs = Array.isArray(params.layer) ? params.layer : [params.layer];
}

util.asyncAll(Object.keys(this.sources), function(id, callback) {
var source = this.sources[id];
if (source.queryRenderedFeaturesAsync) {
Expand All @@ -445,10 +441,6 @@ Style.prototype = util.inherit(Evented, {
},

queryRenderedFeatures: function(queryGeometry, params, classes, zoom, bearing) {
if (params.layer) {
params.layerIDs = Array.isArray(params.layer) ? params.layer : [params.layer];
}

var sourceResults = [];
for (var id in this.sources) {
var source = this.sources[id];
Expand Down
12 changes: 6 additions & 6 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,19 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
*
* @param {Point|Array<number>|Array<Point>|Array<Array<number>>} [pointOrBox] Either [x, y] pixel coordinates of a point, or [[x1, y1], [x2, y2]] pixel coordinates of opposite corners of bounding rectangle. Optional: use entire viewport if omitted.
* @param {Object} params
* @param {string|Array<string>} [params.layer] Only return features from a given layer or layers
* @param {Array<string>} [params.layers] Only query features from layers with these layer IDs.
* @param {Array} [params.filter] A mapbox-gl-style-spec filter.
* @param {featuresCallback} callback function that receives the results
*
* @returns {Map} `this`
*
* @example
* map.queryRenderedFeaturesAsync([20, 35], { layer: 'my-layer-name' }, function(err, features) {
* map.queryRenderedFeaturesAsync([20, 35], { layers: ['my-layer-name'] }, function(err, features) {
* console.log(features);
* });
*
* @example
* map.queryRenderedFeaturesAsync([[10, 20], [30, 50]], { layer: 'my-layer-name' }, function(err, features) {
* map.queryRenderedFeaturesAsync([[10, 20], [30, 50]], { layers: ['my-layer-name'] }, function(err, features) {
* console.log(features);
* });
*/
Expand All @@ -342,16 +342,16 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
*
* @param {Point|Array<number>|Array<Point>|Array<Array<number>>} [pointOrBox] Either [x, y] pixel coordinates of a point, or [[x1, y1], [x2, y2]] pixel coordinates of opposite corners of bounding rectangle. Optional: use entire viewport if omitted.
* @param {Object} params
* @param {string|Array<string>} [params.layer] Only return features from a given layer or layers
* @param {Array<string>} [params.layers] Only query features from layers with these layer IDs.
* @param {Array} [params.filter] A mapbox-gl-style-spec filter.
*
* @returns {Array<Object>} features - An array of [GeoJSON](http://geojson.org/) features matching the query parameters. The GeoJSON properties of each feature are taken from the original source. Each feature object also contains a top-level `layer` property whose value is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature.
*
* @example
* var features = map.queryRenderedFeatures([20, 35], { layer: 'my-layer-name' });
* var features = map.queryRenderedFeatures([20, 35], { layers: ['my-layer-name'] });
*
* @example
* var features = map.queryRenderedFeaturesAsync([[10, 20], [30, 50]], { layer: 'my-layer-name' });
* var features = map.queryRenderedFeaturesAsync([[10, 20], [30, 50]], { layers: ['my-layer-name'] });
*/
queryRenderedFeatures: function(pointOrBox, params) {
if (!(pointOrBox instanceof Point || Array.isArray(pointOrBox))) {
Expand Down
10 changes: 5 additions & 5 deletions test/js/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,9 @@ test('Style#queryRenderedFeaturesAsync', function(t) {
}]
};

if (params.layer) {
if (params.layers) {
for (var l in features) {
if (params.layerIDs.indexOf(l) < 0) {
if (params.layers.indexOf(l) < 0) {
delete features[l];
}
}
Expand All @@ -987,8 +987,8 @@ test('Style#queryRenderedFeaturesAsync', function(t) {
});
});

t.test('filters by `layer` option', function(t) {
style.queryRenderedFeaturesAsync([{column: 1, row: 1, zoom: 1}], {layer: 'land'}, {}, 0, 0, function(err, results) {
t.test('filters by `layers` option', function(t) {
style.queryRenderedFeaturesAsync([{column: 1, row: 1, zoom: 1}], {layers: 'land'}, {}, 0, 0, function(err, results) {
t.error(err);
t.equal(results.length, 2);
t.end();
Expand Down Expand Up @@ -1039,7 +1039,7 @@ test('Style#queryRenderedFeaturesAsync', function(t) {
});

t.test('include multiple layers', function(t) {
style.queryRenderedFeaturesAsync([{column: 1, row: 1, zoom: 1}], {layer: ['land', 'landref']}, {}, 0, 0, function(err, results) {
style.queryRenderedFeaturesAsync([{column: 1, row: 1, zoom: 1}], {layers: ['land', 'landref']}, {}, 0, 0, function(err, results) {
t.error(err);
t.equals(results.length, 3);
t.end();
Expand Down

0 comments on commit 48f5993

Please sign in to comment.