Is it possible to listen for map updates?

2067
4
Jump to solution
02-05-2017 01:58 PM
StanLambert
New Contributor II

In the 3.1x version of the Javascript API I could attach listeners to the 'update-start' and 'update-end' events of the Map. This was extremely useful for showing and hiding a "loading" indicator so that the user was not sitting there wondering if anything was going on while a large map layer was being rendered.

It looks like this was taken away in the 4.x version. I have tried using some of the events that are described in the "watch for changes" sample but I cannot achieve the same functionality with these. You can see what I mean by running that sample. You will see that all of the events complete before the map is visually updated. With this sample, the difference is minimal but I have layers that may take several seconds to load even after all of these events have completed.

The 'update-start' and 'update-end' events of the Map component in 3.1x worked nicely for this. Is there anything similar in the 4.x version? I know the answer. Had to ask anyway.

1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

I wonder if watching the 'updating' property gives you what you need?

View | API Reference | ArcGIS API for JavaScript 4.2 

View solution in original post

0 Kudos
4 Replies
StanLambert
New Contributor II

A couple of follow up questions:

1. Is it possible to attach a listener to the export request that retrieves the images for the map? The process of loading the layer is fairly quick. The export request can take several seconds and nothing is shown on the map until it has completed.

2. Is the source code for the 4.2 version of the Javascript framework available?

0 Kudos
JohnGrayson
Esri Regular Contributor

I wonder if watching the 'updating' property gives you what you need?

View | API Reference | ArcGIS API for JavaScript 4.2 

0 Kudos
StanLambert
New Contributor II

Thank you John. I'm still getting used to the differences between the 3.x and 4.x versions of the API but watching that property does exactly what I need. I kept looking for events to watch instead of properties. By using the plain old JavaScript setInterval() to start watching that property I can show a loading indicator until the property turns back to false, then hide the loading indicator and clear the interval.  Works great.

0 Kudos
JohnGrayson
Esri Regular Contributor

No need for setInterval(), just watch the property:

view.watch("updating", function(updating){
  console.info("View Updating: ", updating);
});

Accessor | API Reference | ArcGIS API for JavaScript 4.2