How do I access my feature layers to pass them into a dijit?

382
4
Jump to solution
08-16-2019 04:31 AM
JamesHone1
New Contributor III

Hi, I have made use of the selectdijit and I know I need to pass in a feature layer as a param so it knows what to select from.

I just cant work out how to get my feature layers into a var to pass in, seems like it should be simple but I cant quite find out how to do it.

In all the examples I see they are creating the feature layer then adding it to the map so they already have the feature layer to pass about. As Im using WAB I am not creating the feature layers in code they are added to the map when we config the app. How do I get the feature layers in my map so I can pass them as arguments etc?

thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

James,

   If you look at the API Reference you will see that the LayerNode has a getLayerObject() method this is the actual layer object that can be passed.

LayerNode class—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers 

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

James,

   In WAB you use code like this to traverse the maps layers.

define([
...
'jimu/LayerInfos/LayerInfos',
'dojo/_base/array',
...
],
function(
...
LayerInfos, array,
...
) {

// Get all feature layers from the map
LayerInfos.getInstance(this.map, this.map.itemInfo)
.then(lang.hitch(this, function(layerInfosObj) {
var infos = layerInfosObj.getLayerInfoArray();
var options = [];
array.forEach(infos, function(info) {
console.info(info);
if(info.title === 'the title of the layer as seen in the layerlist widget') {

}
});
}));
0 Kudos
JamesHone1
New Contributor III

Thanks Robert I have seen code similar to this and I have used it to print out my layer structure in the console. I have also took a look at layerStructure as layerInfos is depreciating.

Im still slightly confused as to what I pass into the dijit, it requireds a FeatuerLayer, does the resulting LayerInfos contain the featuerlayers that I can pass in or just the info about them? how can get a feature layer to pass into the dijit from this?

Heres the code I have so far that prints my layers to the console, uses layerstructure instead of layerinfos but I assume they are similar.

    var layerStructure = new LayerStructure.getInstance();
console.log(layerStructure);
this._printLayerTree(layerStructure);

_printLayerTree: function(layerStructure) {
layerStructure.traversal(function(layerNode) {
var indent = "";
for(var i = 0; i < layerNode.getNodeLevel(); i++) {indent += " ";}
console.log(indent, layerNode.title);
});
},

Im trying to pass 3 feature layers into FeatureSetChooserForMultipleLayers dijit.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

James,

   If you look at the API Reference you will see that the LayerNode has a getLayerObject() method this is the actual layer object that can be passed.

LayerNode class—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers 

View solution in original post

JamesHone1
New Contributor III

thanks I will take a look at that

0 Kudos