Openlayers 3 - limit possible zoom levels on the map

Viewed 10930

I need to keep the zoom level between certain levels (5-19) and not allow the user to zoom in/out any further. I've tried setting the minZoom/maxZoom properties of the view, and also the minResolution/maxResolution, but it doesn't seem to work.

Here is the code:

map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM( {crossOrigin: null} )
        })
    ],
    target: 'map',
    controls: ol.control.defaults({
        attributionOptions: ({
            collapsible: false
        })
    }),
    view: new ol.View({
        center: [0, 0],
        zoom: 5,
        minZoom: 5,
        maxZoom: 19,
        minResolution: 4891.96981025128,
        maxResolution: 39135.75848201024,
        projection: new ol.proj.get("EPSG:900913")
    })
}); 

I've tried it using just the settings for minZoom/maxZoom, just the ones for minResolution/maxResolution or all of them... nothing happens, I am stil able to zoom further.

Edit: it was "zoom: 5", not "zoom: 2" in the code above.

2 Answers
Related