Raruto/leaflet-rotate

Question: is there a way to rotate around an arbitrairy point? (not the center)

BasieP opened this issue · 2 comments

Hi there,

Great plugin, works as promised and i'm a happy user.

But we are building some sort of navigation app, and we want to rotate the map around a point in the bottom center of the map.
This way you see a lot of the map ahead of you and not so much of the roads that have passed. (which in our case is usefull)

Am I missing an option? should I use some trickery? or is it simply not possible?

is there a way to rotate around an arbitrairy point? (not the center)

I'm not 100% sure but (out of the box) I don't think so .

In any case, there are already many utility functions within the L.Map class that you can also use as a starting point to achieve that goal.

For example:

/**
* Change map rotation
*
* @param {number} theta map degrees
*
* @since leaflet-rotate (v0.1)
*/
setBearing: function(theta) {
if (!L.Browser.any3d || !this._rotate) { return; }
var bearing = L.Util.wrapNum(theta, [0, 360]) * L.DomUtil.DEG_TO_RAD,
center = this._getPixelCenter(),
oldPos = this._getRotatePanePos().rotateFrom(-this._bearing, center),
newPos = oldPos.rotateFrom(bearing, center);
// CSS transform
L.DomUtil.setPosition(this._rotatePane, oldPos, bearing, center);
this._pivot = center;
this._bearing = bearing;
this._rotatePanePos = newPos;
this.fire('rotate');
},

👋 Raruto

thanks, I'll have to dive into that. The lingo of leaflet is new to me. Lots of inheritance but hard to figure out where there the actual code is 🤣