设置地图边界

发布于 2025-01-07 13:32:11 字数 242 浏览 3 评论 0原文

我有一张地图,我希望它保持在一定的范围内。我允许使用 2 个缩放级别 5 和 8。在缩放级别 5 上,我能够通过在拖动事件时使用 setCenter() 函数设置地图中心来进行调整,从而防止地图移动。当我以缩放级别 8 放大时,我想防止用户将地图拖动到指定限制之外。限制是缩放级别 5 的界限。我尝试了一些方法,但没有成功。当我使用 fitbounds() 时,它把我踢回到缩放级别 5。我基本上只是想限制你在地图上可以走多远。任何帮助将不胜感激。

G

I have a map which I would like to stay within certain bounds. I have allowed for 2 zoom levels 5 and 8. On zoom level 5 I was able to keep the map from moving by setting the center of the map to adjust by using the setCenter() function on the event of a drag. When I am zoomed in at zoom level 8 I would like to prevent users from dragging the map outside designated limits. The limits are the bounds at zoom level 5. I have tried a few things but with no avail. When I used fitbounds() it kicked me back to zoom level 5. I basically just want to limit how far you can go on the map. Any help would be appreciated.

G

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2025-01-14 13:32:11

There is a method posted here http://econym.org.uk/gmap/range.htm that works with v2 of the Google Maps API. The technique should work with v3 as well. View source on the example page.

Also see the duplicate question here for refinements on the above method: Google Maps API V3: limit map bounds

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文