[OpenLayers-Users] How to set zoom level dynamically?

Rainer Kluge rkluge50 at web.de
Sat Dec 1 09:01:20 PST 2012


Hello,

I want to display a map with two different zoom levels, 3 zoom levels for the 
whole map extend and 6 levels for a detailed section in the center of the 
extent. I do this with a zoomend event handler, in which I set restrictedExtend 
to the detail area when the user zooms to level 4.

map.events.register('zoomend', this, function (event) {
     var zLevel = map.getZoom();
     if( restricted && zLevel < detailZoom) {
        restricted = false;
        map.setOptions({restrictedExtent: fullExtent});
      }
      if( !restricted && zLevel == detailZoom){
        restricted = true;
        map.setOptions({restrictedExtent: detailExtend});
      }
});

This works fine but makes the map 'jump' to the detail area when the user zooms 
in while the mouse is outside the detailed area. Therefore I am looking for a 
way to disable zooming in while the cursor is outside the detail area. I know 
how to track the mouse position, but did not find a way to limit the minimum 
zoom level dynamically. Any hints are welcome.

Rainer



More information about the Users mailing list