问题
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