Unable to access zoom level outside watchUtils.watch in ESRI

274
1
03-04-2021 02:08 AM
MahaK
by
New Contributor

Hi,

My code is like below

watchUtils.watch(this.mapView, "zoom", function (zoom) {
this.zoomLevel = zoom;
});
 
I want to access this.zoomLevel outside the watchUtils block as and when it is triggered.
But it is giving undefined.
 
PS: I have tried getter setter methods, and this.zoomLevel is declared globally.still facing the issue.
 
Can anyone suggest the solution?
 
 
0 Kudos
1 Reply
KenBuja
MVP Honored Contributor

You have to use lang.hitch to make sure "this" is retaining the correct context when being used in the function

watchUtils.watch(this.mapView, "zoom", lang.hitch(this, function (zoom) {
  this.zoomLevel = zoom;
}));
0 Kudos