Layer List - Last Layer Dynamically Added is "Untitled layer"

826
14
08-30-2018 05:44 PM
RyanCoodey
Regular Contributor

Running on the WAB built into Portal 10.6 (think that is WAB 2.6) and have a Local Scene added to an app. Used the GUI to create the app and add the widgets. Built out most the custom widget but have a few issues, one of which is with the Layer List not updating properly.

So the custom widget is just adding in some new FeatureLayers and setting their definitionExpressions (example below). The Layer List seems to refresh fine for all the layers except for the last. I have tried a variable number of layers added and it is always only the last one. The last layer shows as "Untitled layer" in the list and the visibility toggle doesn't even work. The data from the layer shows up though. Any ideas?

Example of adding a layer:

     layer = new FeatureLayer({
      title: configLayer.title,
      url: configLayer.url,
      returnZ: true, //Need to manually set as it is not pulled in from the service
      definitionExpression: "ID = 66544" //This is actually set in code just below
     });
     this.sceneView.map.add(layer);

Things I have tried:

  • making sure the layers were loaded: layer.load();
  • making sure the layers were refreshed: layer.refresh();
  • get an instance of the WidgetManager, find the LayerList and refresh()
  • this.sceneView.extent = this.sceneView.extent; (saw this potential trick in another post)
  • Add a dummy layer at the end and then remove after "layerview-create"

FYI, the Ledged widget updates just fine with the layers title.

Thanks a lot for any ideas!

0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Ryan,

   Can I see the loop code that you are adding these layers in?

0 Kudos
RyanCoodey
Regular Contributor

Hi Robert Scheitlin, GISP‌, for sure, thanks a lot for the help. Here is the entire function (not fully tested or finished as trying to get past this issue):

applyButtonClicked: function () {

   //Set expression on layers and add any missing layers
   for(i in this.config.layers)
   {
    configLayer = this.config.layers;
    
    //Get layer matching config layer
    layer = null
    //Get layer if already exists in map
    for(j in this.sceneView.map.allLayers.items) {
     currentLayer = this.sceneView.map.allLayers.items;
     if(currentLayer.title == configLayer.title)
      layer = currentLayer;
    }
    //Create layer if it does not already exist
    if(layer == null) {
     layer = new FeatureLayer({
      title: configLayer.title,
      url: configLayer.url,
      id: "TestLayer_" + i, //Doesn't seem to matter if this is set
      returnZ: true //Need to manually set as it is not pulled in from the service
     });
     
     //Add new layer to map
     this.sceneView.map.add(layer);
    }
    
    //Clear any previous expressions
    layer.definitionExpression = configLayer.query;
    
    //Build expression
    //Set direct input values (currenlty must be filterType: = or like)
    if(configLayer.hasOwnProperty("inputIndexs")) {
     for(j in configLayer.inputIndexs)
      layer.definitionExpression = layer.definitionExpression.replace("{" + j + "}",  document.getElementById(configLayer.inputIndexs + "TextBox").value);
    }
    //Set lookups from other layer values (currenlty must be filterType: in)
    else if(configLayer.hasOwnProperty("layerIndexs")) {
     for(j in configLayer.layerIndexs) {
      for(k in this.sceneView.map.allLayers.items) //Find the layer to query {
       currentLookupLayer = this.sceneView.map.allLayers.items;
       //currentLookupLayer.refresh();
     
       if(currentLookupLayer.title == this.config.layers[configLayer.layerIndexs.index].title) {
        query = currentLookupLayer.createQuery();
        query.outFields = [configLayer.layerIndexs.field];
        currentLookupLayer.queryFeatures(query).then(lang.hitch(layer, function(result) {
         valueList = ""
         for(l in result.features) {
          if(l > 0)
           valueList += ",";
          valueList += result.features.attributes[Object.keys(result.features.attributes)[0]];
         }
         
         this.definitionExpression = this.definitionExpression.replace("{" + j + "}", valueList);
        }));
        
        break;
       }
      }
     }
    }
   }
},

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ryan,

   When I add a new layer to the map I always use the "name" property and the private "_titleForLegend" property too.

0 Kudos
RyanCoodey
Regular Contributor

Tried setting both "name" and "_titleForLegend" but same issue unfortunately. Thanks so much for the idea though!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ryan,

   I don't work with 3D, but looking through some code I would try add this:

topic.publish('sceneViewChanged', this.sceneView); after adding new layers.

0 Kudos
RyanCoodey
Regular Contributor

Tried adding that in a few different places, still no luck unfortunately . Thanks for the idea though!

0 Kudos
RyanCoodey
Regular Contributor

After playing around with it some more I think it is a bug with the LayerList. I added a second button to the widget UI, and when that is clicked would remove the last layer from the map. After removing a layer, the next to last changes to "Untitled Layer". So its like the last is always going to be that. I'm thinking to open a support ticket with ESRI to confirm this is a bug. A workaround would still be nice though.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ryan,

   I just did some testing by adding a couple of layer from a widget end then removing one after 30 seconds and I did not see that behavior.

0 Kudos
RyanCoodey
Regular Contributor

Hmm, the plot thickens. And you did that via "sceneView.map"?

0 Kudos