I'm new to the arcGis JS API.
I'm trying to implement some fairly trivial and fundamental logic and came to the realization that there is a rather weak eventing system in the API. I want to confirm my findings here.
In trying to implement a callback to trigger upon a zoom action, research led me to eventually find a sample code where extent changes are detected via a watcher on a MapView property.
From this example: ArcGIS API for JavaScript Sandbox
watchUtils.whenTrue(view, "stationary", function() { // Get the new extent of the view only when view is stationary. if (view.extent) { } })
Really? An event as significant as zoom, drag are all inferred by watching the stationary flag?
This article seems to confirm as such. Disable all zooming on the view | ArcGIS API for JavaScript 4.5
Or are there other APIs that I have missed? Thanks.
Hi Yang,
You don't really need to watch both properties. You can just watch for `stationary` and keep some info around:
function whenZoomChange(view, callback) {
let oldScale;
view.watch('stationary', (isStationary) => {
if (!isStationary) {
oldScale = view.scale;
}
else {
if (oldScale !== view.scale) {
callback();
}
}
});
});
On the academic discussion, we made the choice to favor watching properties over events as it gives more control over events.
- Events don't give us access to the current state of the emitter. If your code gets a mapview object and it's already zooming, without a property expressing that you cannot know it, while `stationary` gives out this information.
- Having events AND properties just blows up the API with redundant information.
Understood, that would give you guys more control over the API system then.