in 4.x, how to catch "extent-change" event?

1478
2
Jump to solution
01-11-2018 02:29 PM
XiaowenHuang
New Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

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);
          });
        }
      })

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

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);
          });
        }
      })

View solution in original post

XiaowenHuang
New Contributor

Thanks! This works.

0 Kudos