1
var map1 = new OpenLayers.Map('firstmap');
var wms1;
var state1="<%=state%>";
var cql_filter1="st_nm='"+state1+ "'";
wms1 = new OpenLayers.Layer.WMS( "OpenLayers WMS",
       "http://localhost:8083/geoserver/wms", {layers: 'india:india', 
       'CQL_Filter': cql_filter1,center: [22.2587, 71.1924],
        zoom: 4
        } );

map1.addLayer(wms1);
map1.zoomToMaxExtent();
console.log(map1.getZoom());

The output of map1.getZoom() is 0 and map is also not zoomed so how should I set zoom?

3

The default maxExtent of a map with a default projection is the world. center and zoom can be set as map options or by centering the map:

var map1 = new OpenLayers.Map('firstmap');
var wms1;
var state1="<%=state%>";
var cql_filter1="st_nm='"+state1+ "'";
wms1 = new OpenLayers.Layer.WMS( "OpenLayers WMS",
       "http://localhost:8083/geoserver/wms", {
          layers: 'india:india', 
          'CQL_Filter': cql_filter1
        } );

map1.addLayer(wms1);
map1.setCenter(new OpenLayers.LonLat(22.2587, 71.1924).transform(
        new OpenLayers.Projection('EPSG:4326'), map.getProjectionObject()
  ), 4);
console.log(map1.getZoom());
  • Thanks a lot. It worked – nzare Jul 8 at 3:31
1

Zoom is not a valid WMS parameter so will be ignored by the server. Also once you call map1.zoomToMaxExtent(); you will get whatever zoom level matches the full extent of your map (possibly that of the WMS layer).

Your Answer

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

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