[GIS] How to zoomToExtent and then zoom out

html5javascriptopenlayers-2

I use openlayers 2.12

I use HTML5's geolocation API to get the coords and then I insert them in a layer as feature (point). After that, I zoom in , since the layer has no other feature.

map.zoomToExtent(geoloc.getDataExtent());

geoloc is the name of the layer…

My problem is, how do I zoom-out automatically after the zoomToExtent?

Because the map zooms in too much and I can see just the point and very little details. It would be more user-friendly to zoom out a bit

Thanks

Best Answer

If you want to ZoomTo a specific ZoomLevel , you can use Map.zoomTo like this:

map.zoomTo(level); \\where level is an integer, indicating the zoom level

If you just want to Zoom out one level, you can use Map.zoomOut like this:

map.zoomOut()