无论缩放级别如何为平移设置相同的边界

无论缩放级别如何为平移设置相同的边界

本文介绍了谷歌地图API V3:无论缩放级别如何为平移设置相同的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用google map api创建了一个自定义地图(幻想地图),默认情况下,平移是无限的。
我的地图非常有限,我不希望用户能够在其外部平移,无论放大。



我读了一个关于它的线程此处:



这很好,但不知何故,它不适合每个缩放级别。



您可以在这里用相同的代码清楚地看到问题:



在此示例中,在默认缩放级别下,您可以看到地图最右上角的一些地块( 卑尔根)。
但是放大得越多,这些土地就越离开地图,变得无法到达。
这正是我用我自己的地图使用相同的脚本得到的结果...
如果我将badaries设置为默认缩放级别,则缩放越多,地图的边缘越不可触及。

是否有任何解决方法可以保持完全相同的boudaries,无论缩放级别如何?



感谢

这个例子的工作方式是测试视图的中心位于边界......所以边界实际上比Bergen小......极限的右上角实际上是在视图中心的海洋中在变焦时,所以当你放大时,中心位于同一个位置,右上角变得更近。



解决方案是取代中心检查(

  if((allowedBounds.contains(map.getBounds()))... 

如果你在外面,你可以直接使用map.panToBounds(allowedBounds)。



应该努力......试一试,让我们知道你是否仍然有问题,并且我会仔细研究一下。



编辑:哇..老问题...哦:)


I have created a custom map (fantasy map) with google map api V3 and, by default, the panning is unlimited.My map beeing very limited, I don't want the user to be able to pan outside it, whatever the zoom.

I read a thread about it here: How do I limit panning in Google maps API V3?

It's good but, somehow, it doesn't work well for every zoom level.

You can see the problem very clearly here with the same code: http://econym.org.uk/gmap/example_range.htm

On this example, at the default zoom level, you can see some lands on the extreme top right of the map ("Bergen").But the more you zoom, the more these lands get out of the map and become unreachable.That's exactly what I get with my own map with the same script...If I set boudaries at my default zoom level, the more I zoom, the more the edges of the map get out of reach.

Is there any workaround in order to keep the exact same boudaries, whatever the zoom level?

Thank you.

解决方案

I'm not 100% sure that i'm following your questions.. but I'll try. The way this example works is to test that the centre of the view is in the bounds... so the bounds is actually smaller then Bergen... The upper right corner of the limit is actually in the ocean in the centre of the view at the at zoom.. so when you zoom in, the centre is in the same spot and the upper right becomes closer.

The solution would be to replace the centre check with a bounds check..

if((allowedBounds.contains(map.getBounds()))...

The you can then just map.panToBounds(allowedBounds) if you're outside.

Should work.. give it a try and let us know if you still have problems and I'll take a closer look.

EDIT: wow.. old question... oh well :)

这篇关于谷歌地图API V3:无论缩放级别如何为平移设置相同的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:07