使用leaflet.js在点周围添加设置大小的正方形多边形 [英] Adding a square polygon of a set size around a point using leaflet.js
问题描述
我有点奇怪,希望有人能帮忙.
Bit of a weird one I hope someone can help out with.
在传单中,一旦用户输入了经/纬度并在地图上添加了一个点,我希望能够在该点周围再添加一个10公里的正方形.
In leaflet, once the user has entered a lat/lng and added a point to the map I want to be able to also add a 10km square around that point.
我尝试环顾四周以找到x平方公里的角的计算方法,但没有挖掘任何东西.但是肯定有一种更简单的方法!
I've tried looking around for a calculation to find the corners of the square x Km away but haven't dug anything up. But surely there's an easier way!
有人有什么想法吗?只是说L.polygon然后传递中心点和正方形大小真是太好了.
Does anyone have any thoughts? It'd be lovely to just say L.polygon then pass in a centre point and a square size.
谢谢
泰勒
推荐答案
在半径为5000米的所需纬度/经度上初始化L.Circle
,获取边界并使用它们来初始化L.Rectangle
:>
Initialize a L.Circle
on your desired latitude/longitude with a radius of 5000 meters, grab the boundaries and use them to initialize a L.Rectangle
:
new L.Rectangle(new L.Circle([0, 0], 5000).getBounds())
这篇关于使用leaflet.js在点周围添加设置大小的正方形多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!