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?
Solved! Go to Solution.
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
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
}
}
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
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?
@JoelBennett no not on extent change but on scale change Or a change in zoom level.
Also, here are some good example apps related to extent changes from the SDK:
https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/
https://developers.arcgis.com/javascript/latest/sample-code/event-explorer/
https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes/