0

I have a map with several areas denoted by a polygon. I want to enable some options and display some markers when the polygon is right in the middle of map and the right zoom level. How can I detect this. I can get the map bounds but have no idea how to use it to check if the polygon is in the map.

Thanks for the help!

4

1 回答 1

0

首先,您需要获取多边形的边界。使用此处getBounds描述的函数来获取多边形的边界。

// This will return an L.LatLngBounds object
var polygonBounds = polygon.getBounds();

然后,检查多边形的边界是否包含在地图的边界内。

// Getting the bounds of the map (you know how to do this)
var mapBounds = map.getBounds();
// Now, determine if the polygon bounds are within the map bounds
var contains = mapBounds.contains(polygonBounds);

如果地图边界完全包含您的多边形,则此contains布尔值现在将为 true,否则为 false。

于 2013-09-05T12:08:15.430 回答