使用小叶在地图视点中的面积估计 [英] area estimation in viewpoint of map using leaflet

查看:102
本文介绍了使用小叶在地图视点中的面积估计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图,其中有多个区域用多边形表示.我想启用一些选项,并在多边形位于地图中间和正确的缩放级别时显示一些标记.我怎么能检测到这一点.我可以获取地图边界,但不知道如何使用它来检查多边形是否在地图中.

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.

感谢您的帮助!

推荐答案

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

First, you'll need to get the bounds of your polygon. Use the getBounds function described here to get the bounds of your polygon.

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

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

Then, check to see if the bounds of your polygon are contained within the bounds of your map.

// 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.

This contains boolean will now be true if the map bounds completely contains your polygon, and false if it does not.

这篇关于使用小叶在地图视点中的面积估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆