Hello, I'm trying to limit the zoom levels of my OpenLayers application. I want to make max zoom level to be 14 using standard zoom levels (nothing fancy like fractional zooms and resolutions) and that is all. I've read this article: http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels I've tried tons of combinations of maxExtent, minExtent, maxResolution, minResolution, numZoomLevels and so on... the user is always able to go beyond ZL 14 :( Here is my map definition: var options = { projection: new OpenLayers.Projection("EPSG:900913"), units: "m", controls: [ new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.Permalink(), new OpenLayers.Control.Attribution(), new OpenLayers.Control.Navigation(), new OpenLayers.Control.ScaleLine() ], displayProjection: new OpenLayers.Projection("EPSG:4326") } map = new OpenLayers.Map("mapdiv",options); map.addLayer(new OpenLayers.Layer.OSM()); |
I'd register an event on movestart (which includes zooming) and prevent zooming if the map's zoomlevel is higher than a certain value
I didn't test this, so you propably need to enhance the event handling function answered 21 Jun '12, 09:07 frabron Okay, the first issue was that the event name is 'movestart', not 'zoomstart'. I've changed that and the handler is firing, but I can't stop the event propagation. I keep getting event.stop is not a function. I tried OpenLayers.Event.stop(e) but that seems to do nothing at all. How to get the event from the handler function? The callback argument seem to contain 2 properties - dom element and object (that is not OpenLayers.Event object) and that is all.
(26 Jun '12, 14:49)
ivanatora
|
For tile based layers you can set zoomOffset and resolutions. See Wiki Restricting the bounds & zoom levels and example Isle of Wight Paths. Setting maxResolution and numZoomLevels along with serverResolutions should also work, see Bing Tiles with a Subset of Resolutions Example. For convenience, I use the serverResolutions array defined in the Bing layer, which corresponds to OSM resolutions (apart from extending to level 21):
answered 21 Jun '12, 23:16 ikonor |
I found the simplest way to restrict the maxZoom levels for a XYZ layer was to override the getNumZoomLevels method:
answered 09 Jun '16, 11:48 Vijay Rajbhar |