Skip to content

Commit

Permalink
Aidan/cherry pick marker fix v2.9.0 (#11899)
Browse files Browse the repository at this point in the history
* Fix ignoring marker rotation for map-aligned markers on globe (#11889)

* Adding test for globe marker rotation
  • Loading branch information
SnailBones authored May 16, 2022
1 parent 3758092 commit 02891fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export default class Marker extends Evented {
const north = map.project(new LngLat(this._lngLat.lng, this._lngLat.lat + .001));
const south = map.project(new LngLat(this._lngLat.lng, this._lngLat.lat - .001));
const diff = south.sub(north);
return radToDeg(Math.atan2(diff.y, diff.x)) - 90;
return this._rotation + radToDeg(Math.atan2(diff.y, diff.x)) - 90;
}
return this._rotation - this._map.getBearing();
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,32 @@ test('Globe', (t) => {
t.end();
});

test('Markers on globe account for rotation', (t) => {
const map = createMap(t);
map.setProjection('globe');
map._domRenderTaskQueue.run();
const markerMap = new Marker({rotationAlignment: 'map', rotation: 45})
.setLngLat([0, 0])
.addTo(map);
const markerView = new Marker({rotation: 45})
.setLngLat([0, 0])
.addTo(map);

const rotationRegex = /rotateZ\(-?([0-9]+)deg\)/;

t.same(markerView.getElement().style.transform.match(rotationRegex)[1], 45);
t.same(markerMap.getElement().style.transform.match(rotationRegex)[1], 45);

map.setBearing(map.getBearing() + 180);
map._domRenderTaskQueue.run();

t.same(markerView.getElement().style.transform.match(rotationRegex)[1], 45);
t.same(markerMap.getElement().style.transform.match(rotationRegex)[1], 135);

map.remove();
t.end();
});

test('Snap To Pixel', (t) => {
const map = createMap(t);
const marker = new Marker({draggable: true})
Expand Down

0 comments on commit 02891fc

Please sign in to comment.