谷歌地图API 3缩小fitBounds [英] google maps API 3 zooms out on fitBounds

查看:122
本文介绍了谷歌地图API 3缩小fitBounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个调用map.fitBounds的问题。我正在尝试使用backbone.js路由器来保存url中的地图边界。我希望能够为url添加书签,并且以后地图看起来完全一样。



我注意到调用 map.fitBounds(map.getBounds ())将永远缩小。我希望它不会改变地图。



这是正常的行为吗?如何执行此操作以便地图从一步到另一步看起来是一样的?



谢谢

解决方案

Google Map API的这个问题曾经讨论过很多次。请参阅:



功能 map.fitBounds()设置视口以包含边界。但是 map.getBounds()函数返回一些额外的边距视图边界(请注意,这是正常行为,没有错误)。放大的边界不再适合先前的视口,因此地图会缩小。



解决您的问题的一个简单方法是使用地图中心和缩放级别。查看函数 map.getCenter() map.setCenter() map.getZoom ) map.setZoom()


I've run into a problem where calling map.fitBounds seems to zoom out. I'm trying to use the backbone.js router to save the map bounds in the url. I want to be able to bookmark the url and later have the map look exactly the same.

I noticed calling map.fitBounds(map.getBounds()) in the console will always zoom out. Where as I would like it to not change the map.

Is this normal behaviour? How can I enforce this so the map will look the same from one step to the next?

Thanks

解决方案

This problem of Google Map API was discussed few times. See:

Function map.fitBounds() sets the viewport to contain the bounds. But map.getBounds() function returns the viewport bounds with some extra margin (note that this is normal behaviour and no bug). The enlarged bounds no longer fits in the previous viewport, so the map zooms out.

A simple solution to your problem is to use the map center and the zoom level instead. See functions map.getCenter(), map.setCenter(), map.getZoom() and map.setZoom().

这篇关于谷歌地图API 3缩小fitBounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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