The problem is that the map does not have predefined zoom levels, that is why getZoom
is -1
.
Usually zoom levels are set in the basemap. Just to test, try using a basemap in your code you will see that works as expected,
var map = new Map("map", {
basemap: "topo",
extent: bounds,
minZoom: 5,
maxZoom: 8
});
In the case you don't have zoom levels, you can use scale instead of zoom, that will work in your code. Simplifying calculations you can use,
zoom level 5 ~ 1:15.000.000
zoom Level 8 ~ 1:2.000.000
So it would be something like this,
var map = new Map("map", {
extent: bounds,
minScale: 15000000,
maxScale: 2000000
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…