From a99c168caa99b9319a5dab1d4a83353dd780c4e0 Mon Sep 17 00:00:00 2001 From: ryanhamley Date: Tue, 3 Jul 2018 12:24:54 -0700 Subject: [PATCH] Set tile#queryPadding per feature --- src/source/tile.js | 8 +-- .../multiple-layers/expected.json | 16 +++++ .../circle-radius/multiple-layers/style.json | 51 ++++++++++++++++ .../multiple-layers/expected.json | 36 +++++++++++ .../multiple-layers/style.json | 61 +++++++++++++++++++ .../multiple-layers/expected.json | 36 +++++++++++ .../fill-translate/multiple-layers/style.json | 55 +++++++++++++++++ .../line-width/multiple-layers/expected.json | 22 +++++++ .../line-width/multiple-layers/style.json | 54 ++++++++++++++++ 9 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 test/integration/query-tests/circle-radius/multiple-layers/expected.json create mode 100644 test/integration/query-tests/circle-radius/multiple-layers/style.json create mode 100644 test/integration/query-tests/fill-extrusion-translate/multiple-layers/expected.json create mode 100644 test/integration/query-tests/fill-extrusion-translate/multiple-layers/style.json create mode 100644 test/integration/query-tests/fill-translate/multiple-layers/expected.json create mode 100644 test/integration/query-tests/fill-translate/multiple-layers/style.json create mode 100644 test/integration/query-tests/line-width/multiple-layers/expected.json create mode 100644 test/integration/query-tests/line-width/multiple-layers/style.json diff --git a/src/source/tile.js b/src/source/tile.js index f58acd7b36d..ac54e9992df 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -185,7 +185,7 @@ class Tile { this.queryPadding = 0; for (const id in this.buckets) { const bucket = this.buckets[id]; - this.queryPadding = Math.max(this.queryPadding, painter.style.getLayer(bucket.layerIds[0]).queryRadius(bucket)); + this.queryPadding = Math.max(this.queryPadding, painter.style.getLayer(id).queryRadius(bucket)); } if (data.iconAtlasImage) { @@ -434,8 +434,8 @@ class Tile { const vtLayers = this.latestFeatureIndex.loadVTLayers(); - for (const i in this.buckets) { - const bucket = this.buckets[i]; + for (const id in this.buckets) { + const bucket = this.buckets[id]; // Buckets are grouped by common source-layer const sourceLayerId = bucket.layers[0]['sourceLayer'] || '_geojsonTileLayer'; const sourceLayer = vtLayers[sourceLayerId]; @@ -444,7 +444,7 @@ class Tile { bucket.update(sourceLayerStates, sourceLayer); if (painter && painter.style) { - this.queryPadding = Math.max(this.queryPadding, painter.style.getLayer(bucket.layerIds[0]).queryRadius(bucket)); + this.queryPadding = Math.max(this.queryPadding, painter.style.getLayer(id).queryRadius(bucket)); } } } diff --git a/test/integration/query-tests/circle-radius/multiple-layers/expected.json b/test/integration/query-tests/circle-radius/multiple-layers/expected.json new file mode 100644 index 00000000000..7ea5f07d1c0 --- /dev/null +++ b/test/integration/query-tests/circle-radius/multiple-layers/expected.json @@ -0,0 +1,16 @@ +[ + { + "geometry": { + "type": "Point", + "coordinates": [ + 0, + 0 + ] + }, + "type": "Feature", + "properties": {}, + "id": 1, + "source": "mapbox", + "state": {} + } +] diff --git a/test/integration/query-tests/circle-radius/multiple-layers/style.json b/test/integration/query-tests/circle-radius/multiple-layers/style.json new file mode 100644 index 00000000000..5d6bfa18cb5 --- /dev/null +++ b/test/integration/query-tests/circle-radius/multiple-layers/style.json @@ -0,0 +1,51 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 100, + "height": 100, + "queryGeometry": [ + 30, + 30 + ] + } + }, + "sources": { + "mapbox": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "id": 1, + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ 0, 0] + } + } + ] + } + } + }, + "layers": [ + { + "id": "circle", + "type": "circle", + "source": "mapbox", + "paint": { + "circle-color": "red" + } + }, + { + "id": "circle2", + "type": "circle", + "source": "mapbox", + "paint": { + "circle-color": "yellow", + "circle-radius": 50, + "circle-opacity": 0.5 + } + } + ] +} diff --git a/test/integration/query-tests/fill-extrusion-translate/multiple-layers/expected.json b/test/integration/query-tests/fill-extrusion-translate/multiple-layers/expected.json new file mode 100644 index 00000000000..a9d7bf3b86a --- /dev/null +++ b/test/integration/query-tests/fill-extrusion-translate/multiple-layers/expected.json @@ -0,0 +1,36 @@ +[ + { + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 0, + 0 + ], + [ + 0, + 10.012129557908153 + ], + [ + 10.01953125, + 10.012129557908153 + ], + [ + 10.01953125, + 0 + ], + [ + 0, + 0 + ] + ] + ] + }, + "type": "Feature", + "properties": {}, + "id": 1, + "source": "mapbox", + "state": {} + } +] diff --git a/test/integration/query-tests/fill-extrusion-translate/multiple-layers/style.json b/test/integration/query-tests/fill-extrusion-translate/multiple-layers/style.json new file mode 100644 index 00000000000..8bb07969133 --- /dev/null +++ b/test/integration/query-tests/fill-extrusion-translate/multiple-layers/style.json @@ -0,0 +1,61 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 50, + "height": 50, + "queryGeometry": [ + 20, 30 + ] + } + }, + "sources": { + "mapbox": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "id": 1, + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [[ + [0, 0], + [0, 10], + [10, 10], + [10, 0], + [0, 0] + ]] + } + } + ] + } + } + }, + "layers": [ + { + "id": "fill-extrusion", + "type": "fill-extrusion", + "source": "mapbox", + "paint": { + "fill-extrusion-color": "orange", + "fill-extrusion-height": 20, + "fill-extrusion-base": 0, + "fill-extrusion-opacity": 0.5 + } + }, + { + "id": "fill-extrusion2", + "type": "fill-extrusion", + "source": "mapbox", + "paint": { + "fill-extrusion-color": "white", + "fill-extrusion-height": 20, + "fill-extrusion-base": 0, + "fill-extrusion-opacity": 0.5, + "fill-extrusion-translate": [-15, 15] + } + } + ] +} diff --git a/test/integration/query-tests/fill-translate/multiple-layers/expected.json b/test/integration/query-tests/fill-translate/multiple-layers/expected.json new file mode 100644 index 00000000000..a9d7bf3b86a --- /dev/null +++ b/test/integration/query-tests/fill-translate/multiple-layers/expected.json @@ -0,0 +1,36 @@ +[ + { + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 0, + 0 + ], + [ + 0, + 10.012129557908153 + ], + [ + 10.01953125, + 10.012129557908153 + ], + [ + 10.01953125, + 0 + ], + [ + 0, + 0 + ] + ] + ] + }, + "type": "Feature", + "properties": {}, + "id": 1, + "source": "mapbox", + "state": {} + } +] diff --git a/test/integration/query-tests/fill-translate/multiple-layers/style.json b/test/integration/query-tests/fill-translate/multiple-layers/style.json new file mode 100644 index 00000000000..e444a0c3de3 --- /dev/null +++ b/test/integration/query-tests/fill-translate/multiple-layers/style.json @@ -0,0 +1,55 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 50, + "height": 50, + "queryGeometry": [ + 20, 30 + ] + } + }, + "sources": { + "mapbox": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "id": 1, + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [[ + [0, 0], + [0, 10], + [10, 10], + [10, 0], + [0, 0] + ]] + } + } + ] + } + } + }, + "layers": [ + { + "id": "original-fill", + "type": "fill", + "source": "mapbox", + "paint": { + "fill-color": "red" + } + }, + { + "id": "offset-fill", + "type": "fill", + "source": "mapbox", + "paint": { + "fill-color": "white", + "fill-translate": [-15, 15] + } + } + ] +} diff --git a/test/integration/query-tests/line-width/multiple-layers/expected.json b/test/integration/query-tests/line-width/multiple-layers/expected.json new file mode 100644 index 00000000000..4ce10c7d33d --- /dev/null +++ b/test/integration/query-tests/line-width/multiple-layers/expected.json @@ -0,0 +1,22 @@ +[ + { + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 0, + 0 + ], + [ + 50.009765625, + 0 + ] + ] + }, + "type": "Feature", + "properties": {}, + "id": 1, + "source": "mapbox", + "state": {} + } +] diff --git a/test/integration/query-tests/line-width/multiple-layers/style.json b/test/integration/query-tests/line-width/multiple-layers/style.json new file mode 100644 index 00000000000..7a94a9b9cfc --- /dev/null +++ b/test/integration/query-tests/line-width/multiple-layers/style.json @@ -0,0 +1,54 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 64, + "height": 64, + "queryGeometry": [ + 45, + 16 + ] + } + }, + "sources": { + "mapbox": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "id": 1, + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [ + [ 0, 0], + [ 50, 0] + ] + } + } + ] + } + } + }, + "layers": [ + { + "id": "line", + "type": "line", + "source": "mapbox", + "paint": { + "line-width": 5 + } + }, + { + "id": "line2", + "type": "line", + "source": "mapbox", + "paint": { + "line-color": "white", + "line-width": 50, + "line-opacity": 0.3 + } + } + ] +}