我需要在传单 map中的点周围绘制一个矩形。该点是一对[lat,lon],我具有以米为单位的矩形边的大小。我如何轻松地做到这一点?
假设该点位于矩形的中心,则可以尝试使用Leaflet.GeometryUtil的目标来查找边界,然后根据边界添加矩形。未经测试。
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);
完美的工作,谢谢!
伟大的。没关系!