Min/max zoom level in OpenLayers

2019-01-18 02:37发布

I'm using OpenLayers to display a map in a web page. I am using tiles from CloudMade, but the same issues occur with the Mapnik tiles from OpenStreetMap.

I'm trying to restrict the map so that the user cannot zoom all the way out to world view -- I want them to stay at roughly a city level zoom at minimum.

I have tried using the minZoomLevel / maxZoomLevel / numZoomLevels properties; only the maxZoomLevel and numZoomLevels properties seem to work, whereas the minZoomLevel property seems to be completely ignored.

Is there another way to accomplish this?

9条回答
淡お忘
2楼-- · 2019-01-18 03:29

The best answer I found (including an example) was at OpenLayers - limit the number of zoom levels. I don't paste it here, please see the instructions over there.

查看更多
Ridiculous、
3楼-- · 2019-01-18 03:31

Other answers here refer to OpenLayers versions prior to version 3.

With OpenLayers 3, you can use the maxZoom map option when initializing the map, as follows:

    var map = new ol.Map({
        target: 'mapcontainer-001',
        layers: layers,  // Layers need to be initialized previously
        view: new ol.View({
          center: ol.proj.transform([-5.12345, 42.12345], 'EPSG:4326', 'EPSG:3857'),
          zoom: 12,
          maxZoom: 19
        })
    });

More information can be found in OpenLayers documentation: http://openlayers.org/en/v3.0.0/doc/tutorials/concepts.html

查看更多
贼婆χ
4楼-- · 2019-01-18 03:34

minZoomLevel is not supported for XYZ layers, of which OSM is a subclass.

See the following tickets for workarounds:

查看更多
登录 后发表回答