在Google Maps API v3中获取多段线的界限 [英] Getting the bounds of a polyline in Google Maps API v3

查看:158
本文介绍了在Google Maps API v3中获取多段线的界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有简便的方法可以使用Google Maps API v3查找多段线的边界框?我正在研究一个项目,我需要在数据从地图中添加和删除时更新边界。这很简单,只要做bd.extend(point),其中bd是绑定对象,point是LatLng对象。问题是当我开始删除数据时,我希望它能够改变边界并放大。有没有内置的函数可以做到这一点,或者我需要为自己写点什么?

Is there any easy ways to find the bounding box of a polyline using Google Maps API v3? I'm working on a project where I need to update the bounds as data is added and removed from the map. This is pretty easy by just doing bd.extend(point) where bd is the bound object and point is a LatLng object. The problem is when I start removing data I would like it to change the bounds and zoom back in. Are there any built in functions that can do this or will I need to write something for myself?

推荐答案

V2 API GPolyline.getBounds() 方法来做到这一点。但是, v3 API 中似乎没有等效的方法。

The v2 API had the GPolyline.getBounds() method to do exactly this. However it appears that there is no equivalent method in the v3 API.

您可能想要通过覆盖 Polyline 的属性 MVCObject 为了在对象改变状态时得到通知。然后,您可以使用 LatLngBounds.extend() 的方法。

You may want to handle this by overriding the changed property of your Polyline MVCObject in order to be notified when the object changes state. Then you can calculate the bounding box using the LatLngBounds.extend() method that you suggested.

我认为Google有意在v3 API中省略了这些方法试图保持API轻量级。类似的省略讨论几天前,Stack Overflow GMap2.clearOverlays() 方法。

I think Google intentionally omitted such methods from the v3 API in an attempt to keep the API lightweight. A similar omission discussed a couple of days ago on Stack Overflow was the GMap2.clearOverlays() method.

这篇关于在Google Maps API v3中获取多段线的界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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