Warm tip: This article is reproduced from serverfault.com, please click

其他-如何在仅给定1对[lat,lon]对的情况下在传单中绘制矩形标记,并且以米为单位设置大小a和b

(其他 - How to draw rectangle marker in leaflet given only 1 [lat,lon] pair and sizes a and b in meters)

发布于 2020-11-30 18:09:42

我需要在传单 map中的点周围绘制一个矩形。该点是一对[lat,lon],我具有以米为单位的矩形边的大小。我如何轻松地做到这一点?

Questioner
Eberson Santos
Viewed
0
PeaceLeka 2020-12-01 16:02:46

假设该点位于矩形的中心,则可以尝试使用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);