Skip to content Skip to sidebar Skip to footer

Google Maps Api V3: How To Set Same Boundaries For Panning, Whatever The Zoom Level

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 outs

Solution 1:

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 :)

Post a Comment for "Google Maps Api V3: How To Set Same Boundaries For Panning, Whatever The Zoom Level"