Magezilla
Magezilla

Reputation: 25

Leaflet - how to rotate latlong 90degrees?

Wrong
enter image description here

Right
enter image description here

Ive got a CRS.simple map made from x y coordinates. When inserted with markers, they go as the 1st image shows, but they should go as they are in the 2nd image. How do i get that rotation to happen?

Upvotes: 0

Views: 409

Answers (1)

Falke Design
Falke Design

Reputation: 11338

The CRS.Simple coords are in the format [y,x]

You can switch them with following:

var yx = L.latLng;

var xy = function(x, y) {
    if (L.Util.isArray(x)) {    // When doing xy([x, y]);
        return yx(x[1], x[0]);
    }
    return yx(y, x);  // When doing xy(x, y);
};

https://leafletjs.com/examples/crs-simple/crs-simple.html#this-is-not-the-latlng-youre-looking-for

Update

Mirror the coords with adding a minus:

var yx = L.latLng;

var xy = function(x, y) {
    if (L.Util.isArray(x)) {    // When doing xy([x, y]);
        return yx(-x[1], -x[0]);
    }
    return yx(-y, -x);  // When doing xy(x, y);
};

Upvotes: 1

Related Questions