Any subsitute for extent-change in Arcgis Javascript 4?

643
5
Jump to solution
01-23-2023 10:18 AM
ADITYAKUMAR1
Occasional Contributor III

Hi ,

  I was working on Arcgis Javascript 3 with the below code.

on(this.map, "extent-change", lang.hitch(this, this.myfunction));

 

The above line called myfunction during load of the map .But now I am working with ArcGIS JavaScript 4. Any idea how to replicate the same in version 4?

 

0 Kudos
1 Solution

Accepted Solutions
ADITYAKUMAR1
Occasional Contributor III

Hi @JoelBennett , @Noah-Sager 

   Thanks for the response. I managed to do it in a different way.

map.View.watch("zoom", (evt) => {
if (Number.isInteger(evt)) {
this.myfunction();
}
});

 

Its working for now but this doesnt work when we work with custom base maps.I am not sure why it only works with default basemap gallery.

Thanks

Aditya Kumar

View solution in original post

0 Kudos
5 Replies
JoelBennett
MVP Regular Contributor

When migrating to 4.x, I found it best to replace this by watching the MapView.stationary property, in which case yours would translate to something like:

mapView.watch("stationary", this.myFunction.bind(this));

 

and elsewhere, something like:

myFunction: function(newValue, oldValue, propertyName, target) {
	if (newValue) {
		var extent = target.extent;

		//etc
	}
}

 

ADITYAKUMAR1
Occasional Contributor III

Hi @JoelBennett , @Noah-Sager 

   Thanks for the response. I managed to do it in a different way.

map.View.watch("zoom", (evt) => {
if (Number.isInteger(evt)) {
this.myfunction();
}
});

 

Its working for now but this doesnt work when we work with custom base maps.I am not sure why it only works with default basemap gallery.

Thanks

Aditya Kumar

0 Kudos
JoelBennett
MVP Regular Contributor

The 3.x "extent-change" event will fire when the user pans the map, but your 4.x solution will not.  Is that what you intend?

0 Kudos
ADITYAKUMAR1
Occasional Contributor III

@JoelBennett no not on extent change but on scale change Or a change in zoom level. 

0 Kudos