利用传单进行地图的区域估计

时间:2013-09-05 05:46:00

标签: javascript maps gis leaflet

我有一张地图,其中有几个区域由多边形表示。我想启用一些选项并在多边形位于地图中间和右缩放级别时显示一些标记。我怎么能发现这个。我可以获得地图边界但不知道如何使用它来检查多边形是否在地图中。

感谢您的帮助!

1 个答案:

答案 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。