Skip to content

Commit

Permalink
Fix Query point translation for multi-point geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
Asheem Mamoowala committed Nov 12, 2018
1 parent c708474 commit 050f6f4
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/style/query_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export function translate(queryGeometry: Array<Array<Point>>,
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);
Expand All @@ -41,7 +40,7 @@ export function translate(queryGeometry: Array<Array<Point>>,
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);
}
Expand Down
90 changes: 90 additions & 0 deletions test/integration/query-tests/circle-translate/box/expected.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
47 changes: 47 additions & 0 deletions test/integration/query-tests/circle-translate/box/style.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}

0 comments on commit 050f6f4

Please sign in to comment.