Hi Franky,
Note that map levels are predefined scales at which tiled images are created. For example:
Level | Scale |
---|
1 | 16,000,000 |
2 | 8,000,000 |
3 | 4,000,000 |
4 | 2,000,000 |
etc | |
This is important as the map level value increases as you zoom in. However, the map scale value decreases as you zoom in.
To use dynamic map layers and map scale you will need to change the streetLvlZoom variable to a scale value and also update the map click and zoom-end handler functions.
var streetLvlZoom = 5000;
Also, change the way you create the map:
map = new Map("mapDiv", {
center: [151.15,-33.86],
scale:250000 // Use scale when creating the map
});
Modify the map click handler to test the map scale and not the zoom level:
// Zoom in to local area
map.on("click", function(e){
// Notice that this is now a 'greater than' test
if (map.getScale() > streetLvlZoom){
map.centerAt(e.mapPoint);
map.setScale(streetLvlZoom);
}
});
Modify the map zoom-end handler to test the map scale and not the zoom level:
// Check if draw buttons should be enabled when zoom level changes
map.on("zoom-end", function(e){
var scale = Math.floor(map.getScale())
var drawBtns = document.getElementById("draw-btns").children;
for(var i = 0; i < drawBtns.length; i++) {
// disable btns if map scale > minimum required scale
drawBtns.disabled = (scale > streetLvlZoom);
}
});
As mentioned previously the map level value increases as you zoom in. However, the map scale value decreases as you zoom in. This means that when checking to disable buttons - instead of checking if the zoom level is less than the streetLvlZoom, you need to check if the map scale is greater than the streetLvlZoom.
Also, note the use of the floor function. I have noticed that when setting the map scale to 1:5000 and then checking map.getScale() you end up with a value like 1:5000:000000000704. This ends up messing with the scale > streetLvlZoom test and the buttons remain disabled.
This should fix the problem where the zoom is going in the opposite direction.
This modified example should work even if you also use a tiled base map with your dynamic map service layer.
Example using tiled map service basemap.
Example using dynamic map service basemap.
Owen