From 21d6a2a6f5059ff28437402147d837ee5f5badf8 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Wed, 10 May 2023 22:06:25 +0200 Subject: userLocationMarker: Compensate for map rotation Compensate for the map rotation when drawing the user location marker (when it has a heading set). --- src/userLocationMarker.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/userLocationMarker.js b/src/userLocationMarker.js index 26fcc8d4..fbc4a851 100644 --- a/src/userLocationMarker.js +++ b/src/userLocationMarker.js @@ -98,6 +98,8 @@ export class UserLocationMarker extends MapMarker { this._updateLocation(); this.connect('notify::visible', this._updateAccuracyCircle.bind(this)); + this._mapView.map.viewport.connect('notify::rotation', + () => this._updateLocation()); } _hasBubble() { @@ -129,20 +131,26 @@ export class UserLocationMarker extends MapMarker { } vfunc_snapshot(snapshot) { + snapshot.save(); + if (this.place.location.heading > -1) { // rotate around the center of the icon - let {x, y, width, height} = this.get_allocation(); + let width = this.get_width(); + let height = this.get_height(); let point = new Graphene.Point(); + let rotation = this.place.location.heading + + this._mapView.map.viewport.rotation * 180 / Math.PI; point.init(width / 2, height / 2); snapshot.translate(point); - snapshot.rotate(this.place.location.heading); + snapshot.rotate(rotation); point.init(-width / 2, -height / 2); snapshot.translate(point); } this.snapshot_child(this._image, snapshot); super.vfunc_snapshot(snapshot); + snapshot.restore(); } } -- cgit v1.2.1