I need to draw a rectangle around a point in leaflet map. The point is a pair [lat,lon] and I have the sizes of the sides of the rectangle in meters. How can I easily do that?
Assuming the point will be in the center of the rectangle, you can try use the Leaflet.GeometryUtil's destination to find bounds add rectangle based on the bounds. Not tested.
var latlng = L.latLng(lat, lon);
//Assuming rectangle has side A and side B
hypotenuse = Math.sqrt((0.5*lengthofA)**2 + (0.5*lengthofB)**2)
swAngle = 90 + Math.atan(lengthofA/lengthofB)*180/Math.PI
neAngle = 0 - Math.atan(lengthofA/lengthofB)*180/Math.PI
var southWest = destination(latlng, swAngle, hypotenuse) //returns point L.latlng
var northEast = destination(latlng, neAngle, hypotenuse)
var bounds = L.latLngBounds(southWest, northEast);
var rectangle = L.rectangle(bounds).addTo(map);
Works perfectly, thank you!
Great. You welcome!