Business Console 10.11 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Getting Started | Using Third Party Libraries | Coding the Gadget Controller
 
Coding the Gadget Controller
Provide appropriate logic in the gadget controller to invoke the locateInMap function.
Add the following code to the gadget controller file to receive location from the same gadget and then plot the map.
1. Add an empty location variable and bind it to scope to add a text box in the user interface to capture location.
init:function(){
.....
this.$scope.locations=[{location:''}];
2. Add the following code in the defineScope block of the gadget controller to add or remove text box on the user interface when the + or - icon is clicked:
defineScope : function() {
var _this = this;
this.$scope.addRow=function(){
var row={location:''};
_this.$scope.locations.push(row);
}

this.$scope.removeRow=function($index){
_this.$scope.locations.splice($index, 1);
}

this.$scope.clearLocation=function(){
_this.$scope.hideMarkers();
}
}
3. Add the following code in the defineScope block to plot the locations on the map.
defineScope : function() {
.......
this.$scope.publishLocation=function(){
//Check to remove empty locations
var locations=[];
for(var key in _this.$scope.locations){
if(_this.$scope.locations.hasOwnProperty(key)){
if(_this.$scope.locations[key].location!==''){
locations.push(_this.$scope.locations[key]);
}
}
}

_this.$scope.locateInMap(locations);

};
}