1 | const sortFeatures = require('./sort_features');
|
2 | const mapEventToBoundingBox = require('./map_event_to_bounding_box');
|
3 | const Constants = require('../constants');
|
4 | const StringSet = require('./string_set');
|
5 |
|
6 | const META_TYPES = [
|
7 | Constants.meta.FEATURE,
|
8 | Constants.meta.MIDPOINT,
|
9 | Constants.meta.VERTEX
|
10 | ];
|
11 |
|
12 |
|
13 | module.exports = function(event, bbox, ctx) {
|
14 | if (ctx.map === null) return [];
|
15 |
|
16 | const box = (event) ? mapEventToBoundingBox(event, ctx.options.clickBuffer) : bbox;
|
17 |
|
18 | const queryParams = {};
|
19 | if (ctx.options.styles) queryParams.layers = ctx.options.styles.map(s => s.id);
|
20 |
|
21 | const features = ctx.map.queryRenderedFeatures(box, queryParams)
|
22 | .filter((feature) => {
|
23 | return META_TYPES.indexOf(feature.properties.meta) !== -1;
|
24 | });
|
25 |
|
26 | const featureIds = new StringSet();
|
27 | const uniqueFeatures = [];
|
28 | features.forEach((feature) => {
|
29 | const featureId = feature.properties.id;
|
30 | if (featureIds.has(featureId)) return;
|
31 | featureIds.add(featureId);
|
32 | uniqueFeatures.push(feature);
|
33 | });
|
34 |
|
35 | return sortFeatures(uniqueFeatures);
|
36 | };
|