From 050f6f4fd22b747c1800552b2a85ebc0a589a5f4 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Fri, 9 Nov 2018 17:11:21 -0800 Subject: [PATCH] Fix Query point translation for multi-point geometry --- src/style/query_utils.js | 5 +- .../circle-translate/box/expected.json | 90 +++++++++++++++++++ .../circle-translate/box/style.json | 47 ++++++++++ 3 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 test/integration/query-tests/circle-translate/box/expected.json create mode 100644 test/integration/query-tests/circle-translate/box/style.json diff --git a/src/style/query_utils.js b/src/style/query_utils.js index e1ab51eea4c..81ee4f6de2b 100644 --- a/src/style/query_utils.js +++ b/src/style/query_utils.js @@ -29,8 +29,7 @@ export function translate(queryGeometry: Array>, if (!translate[0] && !translate[1]) { return queryGeometry; } - - const pt = Point.convert(translate); + const pt = Point.convert(translate)._mult(pixelsToTileUnits); if (translateAnchor === "viewport") { pt._rotate(-bearing); @@ -41,7 +40,7 @@ export function translate(queryGeometry: Array>, const ring = queryGeometry[i]; const translatedRing = []; for (let k = 0; k < ring.length; k++) { - translatedRing.push(ring[k].sub(pt._mult(pixelsToTileUnits))); + translatedRing.push(ring[k].sub(pt)); } translated.push(translatedRing); } diff --git a/test/integration/query-tests/circle-translate/box/expected.json b/test/integration/query-tests/circle-translate/box/expected.json new file mode 100644 index 00000000000..9539d0b183a --- /dev/null +++ b/test/integration/query-tests/circle-translate/box/expected.json @@ -0,0 +1,90 @@ +[ + { + "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, + "source": "mapbox", + "sourceLayer": "road", + "state": {} + }, + { + "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, + "source": "mapbox", + "sourceLayer": "road", + "state": {} + } +] \ No newline at end of file diff --git a/test/integration/query-tests/circle-translate/box/style.json b/test/integration/query-tests/circle-translate/box/style.json new file mode 100644 index 00000000000..ef76b5184db --- /dev/null +++ b/test/integration/query-tests/circle-translate/box/style.json @@ -0,0 +1,47 @@ +{ + "version": 8, + "metadata": { + "test": { + "height": 256, + "queryGeometry": [ + [ + 30, + 130 + ], [ + 35, + 131 + ] + ] + } + }, + "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-translate": [ + 20, + 30 + ], + "circle-radius": 10 + }, + "interactive": true + } + ] +} \ No newline at end of file