Select to view content in your preferred language

ArcGIS JavaScript API: How to retrieve the first FeatureLayer from WebScene?

961
2
Jump to solution
10-18-2018 06:44 PM
JamesHolden
Emerging Contributor

Hey everyone, I am currently pulling the FeatureLayer by its name and applying ElevationInfo onto it.

        map3D.when(function(){            
            // Retrieve FeatureLayer from WebScene            
            var featureLayer3D = map3D.layers.find(function(layer){              
               return layer.title === "Env 09092018";  
            });             

            // Define elevationInfo and set it on the layer            
            var currentElevationInfo = {              
               mode: "absolute-height",              
               offset: -20,              
               unit: "meters"            
            };             
            
            featureLayer3D.elevationInfo = currentElevationInfo;
        });

I was wondering is there a way to retrieve by calling the first FeatureLayer as opposed to calling by the name(Env 09092018) itself? Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

James,

   Just use getItemAt(0).

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#getItemAt 

        map3D.when(function(){            
            // Retrieve FeatureLayer from WebScene            
            var featureLayer3D = map3D.layers.getItemAt(0);

            // Define elevationInfo and set it on the layer            
            var currentElevationInfo = {              
               mode: "absolute-height",              
               offset: -20,              
               unit: "meters"            
            };             
            
            featureLayer3D.elevationInfo = currentElevationInfo;
        });

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

James,

   Just use getItemAt(0).

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#getItemAt 

        map3D.when(function(){            
            // Retrieve FeatureLayer from WebScene            
            var featureLayer3D = map3D.layers.getItemAt(0);

            // Define elevationInfo and set it on the layer            
            var currentElevationInfo = {              
               mode: "absolute-height",              
               offset: -20,              
               unit: "meters"            
            };             
            
            featureLayer3D.elevationInfo = currentElevationInfo;
        });
JamesHolden
Emerging Contributor

How can I have not thought of that, got it to work! Thanks so much for your help Robert!

0 Kudos