AnsweredAssumed Answered

How to control FeatureLayerView Visiblity in JSAPI 4.9?

Question asked by rhughes522 on Dec 12, 2018

Hello,

 

I'm building a 3d application using the newest jsapi 4.93 and have an interesting conundrum.  This is an airspace application where 3d polygon are rendered using definition queries on the Feature Layers controlled through a dgrid implementation.  When no rows are selected in the grid, I am returning the layers to what I am calling the default Layer Visibility.  

 

The ordering of the layers and feature graphics in the scene is affecting the ability to see the outlines of the polygons.  I thought that I could control the order in which FeatureLayers are shown in the scene by first making them non-visible, then watching the FeatureLayerView for visible=false.  When all the FeatureLayerViews are non-visible.  I would, in ascending order, make the features visible.  If a lower elevation 3d polygon is visible before a higher elevation polygon, then the outline remains visible through the fill.  If a higher elevation polygon is visible then a lower elevation polygon made visible, the outline is not visible.  One issue I am having is that even when the FeatureLayerView has a visible=false, I can still see it in the browser when debugging which has me worried.

 

To continue testing this I will add a setTimeOut function to make each layer visible 1 sec apart.... then shorten that time delay until satisfied.

public getDefaultLayerVisibility() {
      // the default layer visibility is set on widget creation after results returned from GIS Server
      // each object in the array contains an order property that is used to sort the array
      // the def_viz property of each object was updated to false if none of the surfaces penetrate any of the features from that layer
    
      const group_layers = ["critical_3d", "part_77_group"];
       // first set all the layers' visibility to false
      const deferred = promiseUtils.eachAlways(group_layers.map((layer_id: string) => {
        const group_layer = this.scene.findLayerById(layer_id) as GroupLayer;
        return promiseUtils.eachAlways(group_layer.layers.map((lyr: FeatureLayer) => {
          const deferred = new Deferred();
          if (lyr.type === "feature") {
            this.view.whenLayerView(lyr).then((lyr_view: FeatureLayerView) => {
              whenFalseOnce(lyr_view, "visible", (result: boolean) => {
                deferred.resolve(result);
              });
            });
            lyr.visible = false;
          } else {
            deferred.resolve();
          }
          return deferred.promise;
        }));
      }));
      deferred.then((results: object) => {
        this.defaultLayerVisibility.forEach((obj: LayerVisibilityModel) => {
          const target_layer = this.scene.findLayerById(obj.id) as FeatureLayer;
         
          target_layer.definitionExpression = obj.def_exp;
          target_layer.visible = obj.def_visible;
          this.set3DSymbols(target_layer, false);
        });
      });

Outcomes