openlayers中需要註冊縮放事件來解決,在該事件中監聽縮放後地圖的級別,當地圖級別小於設定的最小級別時放大地圖來解決。代碼為:
//設置地圖最小縮放級別為17級 map.events.register("zoomend", this, function (e) { if (map.getZoom() < 17) { //map.zoomTo(17); map.setCenter(map.getCenter(),17); } })
; openlayers3中,直接通過view的minZoom和maxZoom屬性來控制即可。
map.setView(new ol.View({ extent: mapExtent, projection: this.projection, zoom: 18, minZoom: 16, maxZoom: 23 }));
openlayers中需要註冊縮放事件來解決,在該事件中監聽縮放後地圖的級別,當地圖級別小於設定的最小級別時放大地圖來解決。代碼為:
//設置地圖最小縮放級別為17級 map.events.register("zoomend", this, function (e) { if (map.getZoom() < 17) { //map.zoomTo(17); map.setCenter(map.getCenter(),17); } })
; openlayers3中,直接通過view的minZoom和maxZoom屬性來控制即可。
map.setView(new ol.View({ extent: mapExtent, projection: this.projection, zoom: 18, minZoom: 16, maxZoom: 23 }));