AnsweredAssumed Answered

Is there a signal for when a layer is finished loading?

Question asked by ibroad on May 5, 2017
Latest reply on May 5, 2017 by LDanzinger-esristaff

The app I'm making is for recording tree trimming and spray locations and their status. On the home screen I have 2 buttons, one that activates the "Trimming Mode" and the other activates the "Spraying mode".


Depending on what mode is active, I want certain layers visible and others hidden.


I don't have any map layers load until the "View map" button is clicked, this way the geodatabase isn't locked, and I'm able to delete the geodatabase, and generate a new one if needed.


The problem I'm having is when I click the "View map" button, the layers take a bit of time to load initially, so they aren't available for me to change the visibility.


I've looked for a signal that would alert when a layer is finished loading, but I haven't found anything.


When the "View map" button is clicked, and if the geodatabase exists locally, then I load it into the map using:


localGDB = ArcGISRuntimeEnvironment.createObject("Geodatabase", {path: System.userHomePath + "/ArcGIS/Runtime/Data/Vegetation.geodatabase", autoLoad: true}, mapView)

localGDB.loadStatusChanged.connect(function() {
     if (localGDB.loadStatus === Enums.LoadStatusLoaded) {

          for (var i = 0; i < localGDB.geodatabaseFeatureTables.length; i++) {
               var featureTable = localGDB.geodatabaseFeatureTables[i];
               var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {labelsEnabled: true});
               featureLayer.featureTable = featureTable;


And then immediately after that I was doing something like:


var error = map.operationalLayers.forEach(function(element, index, array) {
    if (activeMode === "Spraying") {
        if ( === "SprayingLog") {
               element.visible = true;
          } else if ( === "TrimmingLog"){
               element.visible = false;
if (error) {


But it doesn't work the first time because the layers aren't loaded yet. What's the correct way to handle this?