0

This question already has an answer here:

I would like there to be only 3 levels of zoom available in the WMS that is displayed in my OpenLayers.Map (from level 6 to level 8).

demolayer2 = new OpenLayers.Layer.WMS(
    "abc...","http://localhost:8080/geoserver/gwc/service/wms",
    {
      layers: 'def...', 
      transparent:"true", 
      format: 'image/png', 
      numZoomLevels: 3, 
      minZoomLevel: 6},
   {isBaseLayer:false},    
   {tileSize: new OpenLayers.Size(256,256)}
);

map.addLayer(demolayer2);

map.addControl(new OpenLayers.Control.LayerSwitcher(
   {'div':OpenLayers.Util.getElement('layerswitcher')})
);

map.zoomToExtent(new OpenLayers.Bounds(
    -4.601615515076983,39.8769407866263,-3.0527184873294764,41.16710732525929)
);

marked as duplicate by Mapperz Jun 9 '14 at 16:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jun 9 '14 at 15:47

This question came from our site for professional and enthusiast programmers.

1

You have to send a resolutions array, appropriate to your projection, in the options that you send to the map constructor, as it is the map, rather than the WMS, that determines the zoom levels. The resolutions are in map units per pixel, so this will most likely be degrees or meters.

So, for example, to restrict your map to 3 zoom levels with map units per pixel of 10, 5, 1, you would use something like:

var mapOptions = {
    maxExtent: new OpenLayers.Bounds(-4.601615515076983,39.8769407866263,-3.0527184873294764,41.16710732525929)),
    units: 'degrees',
    resolutions: [10, 5, 1]
    fractionalZoom: false,
    tileSize: new OpenLayers.Size(256, 256),
    projection: new OpenLayers.Projection("EPSG:4326"),
    displayProjection: new OpenLayers.Projection("EPSG:4326")
};

Then you pass these options to the map constructor:

var map = new OpenLayers.Map("map", mapOptions);

where map is the div containing the map. Note you also set fractionalZoom to false, so you can only zoom to those 3 zoom levels. Set this to true if you want fractional zoom within those 3 zoom levels. The resolutions are in map units per pixel, which in your case looks to be degrees of lat/lon. I leave it to you to work out what the appropriate resolutions are for zoom levels 6, 7 and 8.

Not the answer you're looking for? Browse other questions tagged or ask your own question.