I have an OpenLayers project that is using Google Maps for the base layer. Maybe I'm going about this the wrong way, but I think what I'm trying to do is pretty simple. I just need to set the minimum zoom level of a Google map dynamically based on a given bounding box.

This document describes how to set zoom levels, but it seems that for 3rd party layers like Gmaps, you can't use the minExtent/maxExtent features (this would be ideal).

Also, is there a way to figure out which Google zoom level corresponds to a given bounding box before the map is initialized?

I tried:


... but this throws an exception if called before the map is initialized. I can call it after the map is initialized, but then there seems to be no way to set the minZoomLevel on the Gmap without completely borking the zoom consistency between layers and ending up with something like this (where there is clearly no zoom consistency between layers):

See a jsfiddle example here

enter image description here

  • do you have a live link? think the projection/transform needs to be set. like gis-lab.info/share/DR/sandbox/drag.html – Mapperz Mar 14 '13 at 14:15
  • probably this could help: stackoverflow.com/questions/8988453/… 1. get the current bounding box 2. access to the google map layer, set it's min zoom level please do let me know if i'm wrong, just trying to help. ;) – nasrulhazim Mar 15 '13 at 3:00
  • Mapperz, I added a jsfiddle example of what I'm talking about. As soon as you zoom in or out on the map, the zoom consistency between layers is off. – Joel Mar 15 '13 at 17:38
  • nasrulhazim, This is exactly what I tried and it is causing the zoom level inconsistency between layers. Check out the jsfiddle example I added to the problem description: jsfiddle.net/bXg3y/1 – Joel Mar 15 '13 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.