简体   繁体   English

如何在传单地图上正确绘制多边形(纬度/经度顶点和旋转度)?

[英]How to correctly draw a polygon (lat/lng vertices and rotation) on a Leaflet map?

I am trying to draw a moving polygon that represents a ship on a leaflet map. 我正在尝试在传单地图上绘制一个代表船的移动多边形。

The information I have (per frame) is the location of the polygon's "center" point (latitude/longitude) as well as it's dimensions (the distances between the vertices and the center point), as well as the rotation angle of the polygon. 我所拥有的信息(每帧)是多边形的“中心”点(纬度/经度)的位置以及其尺寸(顶点和中心点之间的距离)以及多边形的旋转角度。

I am able to add the polygon to the leaflet map, but the after applying a rotation and a translation, the polygon appears to be skewed. 我可以将多边形添加到传单地图中,但是在应用旋转和平移之后,多边形似乎出现了倾斜。

The exact process is: first I store an array of coordinates (vertex latitude/longitude which are the distances between 0,0 and the dimensions of the polygon) and every time I wanna draw the polygon, I copy the array then apply the rotation angle to all the coordinates (simple rotation around 0,0) then translate all the coordinates and draw the result. 确切的过程是:首先,我存储一个坐标数组(顶点纬度/经度是0,0与多边形尺寸之间的距离),每次我想绘制多边形时,我都会复制该数组,然后应用旋转角度到所有坐标(绕0,0进行简单旋转),然后平移所有坐标并绘制结果。

This is how the polygon looks like if I only apply the rotation: 如果仅应用旋转,则这是多边形的样子:

如果仅应用旋转,则多边形是这样的

This is how the polygon looks like if I apply the rotation and translation (no scaling): 如果我应用旋转和平移(不缩放),则多边形是这样的:

如果我应用旋转和平移,这就是多边形的样子

You are seeing distortion because on the spherical Mercator projection that Leaflet (like most web maps) uses, the aspect ratio of latitude and longitude is only 1:1 at the equator. 您会看到失真,因为在Leaflet(与大多数网络地图一样)使用的球形墨卡托投影上 ,赤道的纬度和经度的纵横比仅为1:1。 As you move toward the poles, a "square" of 1-degree on a side will appear increasingly stretched vertically. 当您朝两极移动时,侧面1度的“正方形”会越来越多地垂直伸展。

If you convert your lat/lon points to projected coordinates using L.Projection (specifically, using L.Projection.SphericalMercator.project(...) ), you can do your math in projected space, then convert back to lat/lon with L.Projection.SphericalMercator.unproject(...) when you add it to the map. 如果使用L.Projection (具体而言,使用L.Projection.SphericalMercator.project(...) )将纬度/经度点转换为投影坐标,则可以在投影空间中进行数学运算,然后使用L.Projection.SphericalMercator.unproject(...)添加到地图时。 Your polygon should then retain its shape. 然后,您的多边形应保持其形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM