我有一张地图,其中有几个区域由多边形表示。我想启用一些选项并在多边形位于地图中间和右缩放级别时显示一些标记。我怎么能发现这个。我可以获得地图边界但不知道如何使用它来检查多边形是否在地图中。
感谢您的帮助!
答案 0 :(得分:0)
首先,您需要获取多边形的边界。使用here描述的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。