So I'm pretty new to WebApp builder developer edition. I'm just trying to do a simple task to list the layer in the console log by clicking the button inside the widget.
This is what I have so far. it keeps saying "Uncaught TypeError: LayerInfos.getInstance is not a function" So I'm pretty sure it can't find 'jimu/LayerInfos/LayerInfos'. Also VisualStudioCode greys out the LayersInfos on line 8 when decalring the functions.
I'm using the xxxxxxxxx:3344/webappviewer/?config=sample-configs/config-demo.json to develop the app.
Could anyone help guide me. I think I'm missing something fundamental here.
Thanks,
define(['dojo/_base/declare',
'jimu/BaseWidget',
'jimu/LayerInfos/LayerInfos'
],
function(declare, BaseWidget, LayerInfos) { //LayerInfos gets greyed out in Microsoft Visual Studio
var clazz = declare([BaseWidget], {
templateString: '<div>This is adamsWidget!. ' +
'<input type="button" value="Get Map Id" data-dojo-attach-event="click:_test">.</div>',
_getMapId: function(){
//alert(this.map.id);
console.log("im in here!")
},
_test: function(LayerInfos) {
LayerInfos.getInstance(this.map, this.map.itemInfo).then(function(layerInfosObject){
layerInfosObject.getLayerInfoArray().forEach(function(layerInfo) {
console.log(layerInfo.title, layerInfo.id);
});
})
}
});
console.log("YsES")
return clazz;
});
Adam,
You issue is in your _test function.
//You have
_test: function(LayerInfos) {
//You need
_test: function() {
The issue is having LayerInfos as a parameter to you function means that it is expecting the method that calls the _test function to pass the LayerInfos parameter.