custom modules loading last since GE 4.10 en Viewer 2.11.1
Hi,
I have some custom libraries which depend on events (e.g. mapLoaded). Up until the last release, my custom libraries loaded fast enough to capture those events.
Since the last releases of essentials and HTML5 viewer, my custom libraries load after the site is already initialised and thus cannot capture the needed events.
Is there any way to make sure my custom libraries are loaded first?
0
-
I'm afraid that there likely is no way to force your custom libraries to load before the code in the Mapping library, which is what would be required for this to work as-is. Map initialization has been moved earlier in the initialization process as of 2.11 to speed up viewer load times, and even if your module was the very next thing to load it might not reliably capture the 'mapLoaded' event as it fires.
However, it is possible, with some minor changes, to code a module that does not care when it is initialized, even if it needs to listen to events that only occur once during startup. To do this, it is recommended to use the Promise returning methods attached to the ViewerApplication object instead of listening to these events directly.
For example, do this if you need to interact with the ESRI map on startup:this.app.waitUntilMapLoaded().then(() => { // The esri map will be initialized at this point and available at this.app.map // However, it may be that not all of the site layers have been added yet. }If the map is not yet loaded, the method will wait until it is before executing the code in the function. If the map is already loaded, the code in the function will execute immediately. Now the module can be loaded at any time, and does not have a requirement that it be loaded before the map in order to catch this event.
There are a number of other methods provided that behave in the same way. Here are some of the more useful ones:
waitUntilSiteInitialized -- The Site object has been fully initialized and is ready to go. The viewer UI and map may not be though, so don't use this if you are concerned about those.
waitUntilSiteServiceLayersLoaded -- All layers in the site have been populated in the ESRI map. A little bit later than the above 'mapLoaded' event, as it waits for both initialization and for the site layers to be populated.
waitUntilApplicationReady -- Absolutely every startup task is done, and the viewer, including the UI, is finalized and ready to go. If you are unsure, or something doesn't seem to work properly otherwise, use this one.0 -
Thanks Jonathan, promises were the solution to my problem.
I just want to add that arrow functions are not supported by IE11 for other users who encounter the same problem. I ended up using slightly different syntax in my constructors which is compatible for all common browsers:
var _this = this;
this.app.waitUntilSiteServiceLayersLoaded().then(function () {
_this.siteServiceLayersLoaded(_this.app.site);
});0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
2 Kommentare