-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I get current coordinates of rectangle corners? #51
Comments
Take a look at what I suggested in #29 |
@w8r |
I see the same problem. Is the intent behaviour to not show the current coordinates on getLatLngs() while rotating or scaling? |
I also had to do this. This is what I came up with: // Fires on rotate/resize, not on drag.
poly.on("transform", function (e) {
const trans = poly.transform;
const coords = poly.getLatLngs()[0]; // pre-transform coordinates of polygon
const matrix = trans._matrix;
const map = poly._map;
function transform(coord) {
// the key is to project your lat/long coordinates to the layer's
// coordinate system, apply the transform, and then invert back
// to the lat/long coordinates
return map.layerPointToLatLng(
matrix.transform(map.latLngToLayerPoint(coord))
);
}
// I used ImageOverlay.Rotated from
// https://github.com/IvanSanchez/Leaflet.ImageOverlay.Rotated
// which gives a "reposition" function. But you can use transform(coords[i])
// generally to do your transformation.
overlay.reposition(
transform(coords[1]),
transform(coords[2]),
transform(coords[0])
);
}); |
When I try using the events (e.g.
rectangle.on('transform', (e) => { ... } )
), how can I get live coordinates of my rectangle as I scale/rotate it?When I move, I can access them via
rectangle.getLatLngs()
, but in event of rotate or scale the coordinates remain the same until I start the next zoom/rotate.I need this in order to properly rotate an imageOverlay linked to the rectangle.
The text was updated successfully, but these errors were encountered: