Adding a square polygon of a set size around a point using leaflet.js

五迷三道 提交于 2019-12-08 03:31:36

问题


Bit of a weird one I hope someone can help out with.

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.

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!

Does anyone have any thoughts? It'd be lovely to just say L.polygon then pass in a centre point and a square size.

Thanks,

Tayler


回答1:


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())


来源:https://stackoverflow.com/questions/36041765/adding-a-square-polygon-of-a-set-size-around-a-point-using-leaflet-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!