0

I try to automatically zoom map to maximum extent of layer after adding layer to map. I tried to code like this.

var layer = OpenLayers.Layer.WMS(.......);

map.addLayer(layer);

map.zoomToExtent(layer.getDataExtent());

But it doesnt' work. I also changed like this

map.zoomToExtent(layer.getMaxExtent());

It still doesn't work. What can I do to solve this issue.

0

getDataExtent() does not work with a WMS layer, there is more info in the answer given here: How to get layer extent in OpenLayers or zoom to WMS layer extent?

  • Thanks you, But those answers doesn't solve my problem – sigman Aug 5 '15 at 14:43
  • The linked answer has a suggestion: "You can call the GetCapabilities request on the WMS endpoint. This gives you an XML response, which can be parsed to read the bbox of the appropriate Layer" – Mart Aug 7 '15 at 8:53

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