AnsweredAssumed Answered

How to display the fields of a layer

Question asked by Sara_EL_MALKI on Sep 14, 2018
Latest reply on Sep 14, 2018 by rscheitlin

Hello guys,

I'm new to developing with arcGIS web app-builder,

I want to show the layers added on the map (they're coming from my arcGIS server map service) and once I choose a layer, its fields will be displayed in the other list drop-down, such a widget is available on the app-builders docs but it's not working for me, maybe because it's only for 'ArcGIS Feature Layer', you can find it here:

Create a ListView widget—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers 

 

define([
'dojo/_base/declare',
'jimu/BaseWidgetSetting',
'dojo/_base/lang',
'dojo/_base/array',
'dijit/_WidgetsInTemplateMixin',
'jimu/LayerInfos/LayerInfos',
'dijit/form/Select'
],
function(declare, BaseWidgetSetting, lang, array, _WidgetsInTemplateMixin, LayerInfos) {

return declare([BaseWidgetSetting, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-listview-setting',

postCreate: function(){
//the config object is passed in
this.setConfig(this.config);
},

setConfig: function(config){
// this.textNode.value = config.configText;
// Update header text
//you can change the default string named "headerText" defined at nls/string.js with a variable defined in config.json
this.headerTextNode.value = config.widgetHeaderText;

// 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) {
// if(info.originOperLayer.layerType === 'ArcGISFeatureLayer') {
options.push({
label: info.title,
value: info.id
});
// }
});
this. layerSelect.set('options', options);

this.layerSelect.on('change', lang.hitch(this, function(value) {

//alert('value of layerId is :' +value);
var selectedLayer = layerInfosObj.getLayerInfoById(value);
console.log("selectedLayer: "+selectedLayer); // [Object Object]

console.log("selectedLayer.layerObject: "+selectedLayer.layerObject); // [Object Object]
console.log("selectedLayer.layerObject.fields: "+selectedLayer.layerObject.fields); //undefined
console.log("selectedLayer.layerObject0: "+selectedLayer.layerObject[0]); //undefined
console.log("selectedLayer.layerObject1: "+selectedLayer.layerObject[1]); //undefined
if(selectedLayer) {
var fieldOptions = array.map(selectedLayer.layerObject.fields, function(field) {
return {
label: field.alias || field.name,
value: field.name
}
});
this.thumbnailSelect.set('options', fieldOptions);
this.titleSelect.set('options', fieldOptions);
}

}));
}));
},

getConfig: function(){
//WAB will get config object through this method
/*return {
configText: this.textNode.value
};*/
//WAB will get config object through this method
return {
widgetHeaderText: this.headerTextNode.value,
layerId: this.layerSelect.get('value'),
thumbnailField: this.thumbnailSelect.get('value'),
titleField: this.titleSelect.get('value')
};
}
});
});

 

When using Breakpoints while debugging, I can't find the "Fields" property in the layerObject object, where I can find it ?

Robert Scheitlin, GISP

Outcomes