AnsweredAssumed Answered

JavaScript API Scope from Web AppBuilder Widget.js

Question asked by cstidham on Oct 3, 2017
Latest reply on Oct 4, 2017 by rscheitlin

I'm new to customizing widgets and haven't been able to access some methods that are specific to the JavaScript API that according to a development summit session should be accessible.

 

I'm working on a custom widget that was created from the CustomWidget template directory.  For learning purposes I'm trying to simply show or hide a layer using the snippet below that was included in a developer summit session:

 

this.projectsLayer = this.map.getLayer('LayerName');

this.projectsLayer.show();

 

This is contained within the onOpen attribute / event.

 

onOpen: function(){
this.inherited(arguments);
console.log('onOpen');
this.projectsLayer = this.map.getLayer('LayerName');
this.projectsLayer.show();

},

 

In the developer summit session it was stated that since this widget is inheriting from BaseWidget it should have access to the map instance.  When I run this application in Chrome the developer tools console shows the error: TypeError: Cannot read property 'show' of undefined.  this.map in the console displays the HTML of the map.  Trying this.map.getBasemap() or this.map.getLayersVisibleAtScale() both trigger TypeError: this.map.getBasemap or  this.map.getLayersVisibleAtScale is not a function.

 

I'm unsure if these methods are outside the scope of BaseWidget or if I am somehow missing a reference.

 

The beginning of Widget.js is unchanged:

define(['dojo/_base/declare', 'jimu/BaseWidget'],
function(declare, BaseWidget) {

 

Any help with this is appreciated.

Outcomes