AnsweredAssumed Answered

Access to the widget instance using 'this'

Question asked by alexyshr on Nov 22, 2017
Latest reply on Nov 28, 2017 by alexyshr

I am trying to configure a personalized widget for ArcGis Javascript Api 4.5.

 

My issue is related to the use of 'this' (a MapView) inside of method on() of esri/views/View

 

I used this.view.on inside a private method of my widget named onViewChange(). I attached all the TypeScript code.

 

It looks like this:

 

@property()
@renderable()
view: MapView;

....

 

private _onViewChange() {
      
this.view.on('pointer-up', function(response){
      this.centroanteriorgeoX = this.state.longitudanterior,   \\Here 'this' is undefined
      this.centroanteriorgeo = {
         x: this.state.longitudanterior,
         y: this.state.latitudanterior,
      };
});

this.centroanteriorpla = {  \\Here this works fine!!
      x: this.state.xanterior,
      y: this.state.yanterior,
};
...
};

 

I have access to 'this' inside the private onViewChange method but outside this.view.on

access to this is ok

 

I can't use 'this' inside of this.view.on because it is undefined.

How can I use and change properties of 'this' (MapView) inside Mapview.on, inside a private method, inside a new widget class that extends Accessor?

this is undefined

 

I tryed to do the same inside this.view.watch, but I have the same problem.

 

Cheers!!

Alexys 

Attachments

Outcomes