Hi
I have an awful web app that is mainly legacy code I wrote many years back, but functions and the users use it all the time
WE're moving stuff around and at the moment the desktops are at a different site to the data so I'm hitting latency issues.
I have this code
//return the layer descriptions and © text into arrays - we use this later for the info dialog to generate hyperlinks and © text
dojo.forEach(dynamicMapServiceLayer.layerInfos, function (layer) {
var requestHandle = esri.request({
url: mapservice2 + "/" + layer.id + "?f=json",
handleAs: "json",
load: function (data) {
LayerAttach[layer.id] = data.hasAttachments;
console.debug(dynamicMapServiceLayer.layerInfos[layer.id])
LayerDescriptions[layer.id] = data.description;
dynamicMapServiceLayer.layerInfos[layer.id].copyrightText = data.copyrightText;
},
}, { useProxy: true });
});
Which I have on the Onload event of the main dynamic map It reads extra stuff from the rest data of the service that I use to create hyperlinks (as good old ArcIMS did)
All worked fine until this latency hit. I have a sub-site that on start up takes a feature passed in the URL, finds the extent of that feature, then passes that into a ID task on the main service. The output uses the arrays/data produced in the above routine. With the latency I am getting results of the ID task back before I get all the info from the above code.
I have vague knowledge of defers and the like so surely I should add to each loop above a wait until the data is back until stepping forward, or a wait until everything is back
Any advice welcomed.
In the short term I've given those users who use this sub-site Chrome, which can handle things faster and not get caught up.
Cheers
ACM
Adrian,
To work with deferred you use .then to execute something after the deferred is returned:
requestHandle.then(function(evt){
//now do something
});
you also may want to consider dojo/promise/all if that is available in the version of the API you are using
Thanks - that is helpful and it helps me understand a bit more. However, I really need to wrap the entire onLoad function up to give it a "then" - I've got to move onto other stuff right now, but I've just found this post https://community.esri.com/thread/30458 which looks super useful. This one also looks promising Connect to onExtentChange with deferred web maphttps://community.esri.com/thread/65042