In this lab you will create a custom widget for Web AppBuilder.
Create a New Default (2D)app in Web App Builder. Give it a title Custom Widget App
and click OK
.
Click the Plateau Theme and click Save
.
Click the widgets folder (e.g., webappbuilder\server\apps\1\widgets) for the application you just created.
Download the Simple Graphic zip, unzip it and copy the folder to the widgets directory.
Click the SimpleGraphic folder and edit Widget.js to update the function definition and extend the BaseWidget class:
function(declare, BaseWidget, SimpleMarkerSymbol, Graphic) {
var clazz = declare([BaseWidget], {
templateString: '<div><input type="button" value="click me to add a graphic!" data-dojo-attach-event="click:_addGraphic"></div>',
//Add a point at center of extent
_addGraphic: function() {
var centerPoint = this.map.extent.getCenter();
var symbol = SimpleMarkerSymbol();
var myGraphic = new Graphic(centerPoint, symbol);
this.map.graphics.add(myGraphic);
}
});
{
"uri": "widgets/SimpleGraphic/Widget",
"position": {
"left": 55,
"top": 45,
"width": 250,
"height": 210
}
},
Your code should look like this: