[GIS] way to limit the overview map to a certain zoom level

openlayers-2web-mapping

The OpenLayers overview map control works great when I use standard options. I would like to limit the overview to one resolution, but I can't seem to find the right combination of values for the properties and mapOptions. Is there a way to force the overview map to stay at a single zoom level?

The example code below uses the "numZoomLevels : 1" option, but this has no effect.

function init() {
// start with a browser check. If it's IE6, transparent png's are not supported
var ua = $j.browser;
if(ua.msie && ua.version.slice(0, 1) == "6") {
    var imgtype = 'image/gif';
} else {
    var imgtype = 'image/png';
}

// Define a projection for the map
var proj = new OpenLayers.Projection("EPSG:4326");

// Define the map options and start with an empty control set
var mapOptions = {
    controls: [],  
    projection : new OpenLayers.Projection("EPSG:900913"),
    displayProjection : proj,
    units : "m",
    numZoomLevels : 20
};
// Create the map object
var map = new OpenLayers.Map('map', mapOptions);

 // Define the overview map options
var overviewOptions = {
    size : new OpenLayers.Size(300, 200),
    maximized : true,
    minRectSize : 0,
    autoPan : true,
    mapOptions : {
        projection : new OpenLayers.Projection("EPSG:900913"),
        displayProjection : proj,
        units : "m",
        resolutions : [90],
        numZoomLevels : 1  // this has no effect, the ov map still zooms in and out with the map
    }
};

// Add controls to the map
map.addControl(new OpenLayers.Control.OverviewMap(overviewOptions));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.PanZoomBar({panIcons : false}));
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({
    element : $('location')
}));

// Add layers
var gmap = new OpenLayers.Layer.Google("Google Streets", {
    numZoomLevels : 20
});

map.addLayers([gmap]);

// Start the map at a particular point
var point = new OpenLayers.LonLat(-118, 34);
point.transform(proj, map.getProjectionObject());
map.setCenter(point, 16);

}; // Ends the init()

Best Answer

You have an example (of how to change default options for overview map) online at this URL.

// create an overview map control with non-default options
    var controlOptions = {
        maximized: true,
        mapOptions: OpenLayers.Util.extend(mapOptions, {
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                 20037508.34, 20037508.34)
        }),
        layers: [jplOverview]
    }
    var overview2 = new OpenLayers.Control.OverviewMap(controlOptions);
    map2.addControl(overview2);

The wiki page gives also more samples. I guess what you are looking for is already done here :

  // If you'd like to have an overview map that doesn't zoom in and out at all, give it just one zoom level: 

  var options = {mapOptions: {numZoomLevels: 1}};
  map.addControl(new OpenLayers.Control.OverviewMap(options));

For information, Overview map Options are available on the documentation page.