In v3.x, we can use map.on("extent-change", function(){}); But in v4.x, it seems the event "extent-change" no longer exist. I tried to use:
view.watch('extent', function(newextent, oldextent) {
console.log(newextent);
});
But when I zoom once, the above console.log line executed 10 times. I don't want to execute a function 10 times when only pan/zoom once. Any idea how to do "extent-change" in v4.x?
Solved! Go to Solution.
Here is what I have that works for panning or zooming:
watchUtils.whenFalse(view, 'stationary', function(evt){
if(!view.stationary){
watchUtils.whenTrueOnce(view, 'stationary', function(evt){
console.log(view.extent);
});
}else{
watchUtils.whenFalseOnce(view, 'interacting', function(evt){
console.log(view.extent);
});
}
})
Here is what I have that works for panning or zooming:
watchUtils.whenFalse(view, 'stationary', function(evt){
if(!view.stationary){
watchUtils.whenTrueOnce(view, 'stationary', function(evt){
console.log(view.extent);
});
}else{
watchUtils.whenFalseOnce(view, 'interacting', function(evt){
console.log(view.extent);
});
}
})
Thanks! This works.