Florian,
There is actually quite a bit involved in this... In your widget you need to require
'jimu/LayerInfos/LayerInfos' and its var LayerInfos
Then in the startup function:
startup: function() {
this.inherited(arguments);
if (this.map.itemId) {
LayerInfos.getInstance(this.map, this.map.itemInfo)
.then(lang.hitch(this, function(operLayerInfos) {
this.operLayerInfos = operLayerInfos;
}));
} else {
var itemInfo = this._obtainMapLayers();
LayerInfos.getInstance(this.map, itemInfo)
.then(lang.hitch(this, function(operLayerInfos) {
this.operLayerInfos = operLayerInfos;
}));
}
},
_obtainMapLayers: function() {
// summary:
// obtain basemap layers and operational layers if the map is not webmap.
var basemapLayers = [],
operLayers = [];
// emulate a webmapItemInfo.
var retObj = {
itemData: {
baseMap: {
baseMapLayers: []
},
operationalLayers: []
}
};
array.forEach(this.map.graphicsLayerIds, function(layerId) {
var layer = this.map.getLayer(layerId);
if (layer.isOperationalLayer) {
operLayers.push({
layerObject: layer,
title: layer.label || layer.title || layer.name || layer.id || " ",
id: layer.id || " "
});
}
}, this);
array.forEach(this.map.layerIds, function(layerId) {
var layer = this.map.getLayer(layerId);
if (layer.isOperationalLayer) {
operLayers.push({
layerObject: layer,
title: layer.label || layer.title || layer.name || layer.id || " ",
id: layer.id || " "
});
} else {
basemapLayers.push({
layerObject: layer,
id: layer.id || " "
});
}
}, this);
retObj.itemData.baseMap.baseMapLayers = basemapLayers;
retObj.itemData.operationalLayers = operLayers;
return retObj;
},
Then you can do this:
this.operLayerInfos.getLayerInfoById('Parcel Data_0').enablePopup();