Skip to content

Commit

Permalink
Fix data-driven property evaluation in queryRenderedFeatures (#10074)
Browse files Browse the repository at this point in the history
* Copy serialized layers before evaluating props

* Add a regression test
  • Loading branch information
osvodef authored Nov 13, 2020
1 parent 8066104 commit ee6136c
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/data/feature_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DictionaryCoder from '../util/dictionary_coder';
import vt from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import GeoJSONFeature from '../util/vectortile_to_geojson';
import {arraysIntersect, mapObject} from '../util/util';
import {arraysIntersect, mapObject, extend} from '../util/util';
import {OverscaledTileID} from '../source/tile_id';
import {register} from '../util/web_worker_transfer';
import EvaluationParameters from '../style/evaluation_parameters';
Expand Down Expand Up @@ -214,7 +214,7 @@ class FeatureIndex {
featureState = sourceFeatureState.getState(styleLayer.sourceLayer || '_geojsonTileLayer', id);
}

const serializedLayer = serializedLayers[layerID];
const serializedLayer = extend({}, serializedLayers[layerID]);

serializedLayer.paint = evaluateProperties(serializedLayer.paint, styleLayer.paint, feature, featureState, availableImages);
serializedLayer.layout = evaluateProperties(serializedLayer.layout, styleLayer.layout, feature, featureState, availableImages);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[
{
"geometry": {
"type": "LineString",
"coordinates": [
[
13.406662344932556,
52.49845542419487
],
[
13.406715989112854,
52.49853706825692
],
[
13.407037854194641,
52.499007335102704
],
[
13.40782642364502,
52.50002296369735
],
[
13.409215807914734,
52.50175045812034
]
]
},
"type": "Feature",
"properties": {
"class": "main",
"oneway": 0,
"osm_id": 4612696,
"type": "secondary"
},
"id": 4612696,
"layer": {
"id": "road",
"type": "circle",
"source": "mapbox",
"source-layer": "road",
"paint": {
"circle-radius": 10
},
"layout": {}
},
"source": "mapbox",
"sourceLayer": "road",
"state": {
"stateA": 10
}
},
{
"geometry": {
"type": "LineString",
"coordinates": [
[
13.404956459999084,
52.50075446300568
],
[
13.405857682228088,
52.500525870779285
],
[
13.40782642364502,
52.50002296369735
],
[
13.41029942035675,
52.49939268890719
],
[
13.410347700119019,
52.49937962612168
],
[
13.410476446151733,
52.49934370344147
],
[
13.410674929618835,
52.499291452217875
],
[
13.4122896194458,
52.498840782836766
]
]
},
"type": "Feature",
"properties": {
"class": "street",
"oneway": 0,
"osm_id": 4612752,
"type": "residential"
},
"id": 4612752,
"layer": {
"id": "road",
"type": "circle",
"source": "mapbox",
"source-layer": "road",
"paint": {
"circle-radius": 50
},
"layout": {}
},
"source": "mapbox",
"sourceLayer": "road",
"state": {
"stateA": 50
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": 8,
"metadata": {
"skipLayerDelete": true,
"test": {
"height": 256,
"operations": [
[
"setFeatureState",
{
"source": "mapbox",
"sourceLayer": "road",
"id": 4612696
},
{
"stateA": 10
}
], [
"setFeatureState",
{
"source": "mapbox",
"sourceLayer": "road",
"id": 4612752
},
{
"stateA": 50
}
]
],
"queryGeometry": [
10,
100
]
}
},
"center": [
13.418056,
52.499167
],
"zoom": 14,
"sources": {
"mapbox": {
"type": "vector",
"maxzoom": 14,
"tiles": [
"local://tiles/{z}-{x}-{y}.mvt"
]
}
},
"layers": [
{
"id": "road",
"type": "circle",
"source": "mapbox",
"source-layer": "road",
"paint": {
"circle-radius": ["feature-state", "stateA"]
},
"interactive": true
}
]
}

0 comments on commit ee6136c

Please sign in to comment.