I am trying to create a Web AppBuilder custom widget. The goal of the widget is to allow a user to fill in 3 text boxes (an ID and X,Y coordinates), and then when they click a button on the widget, the data will be submitted (using .applyEdits on a particular feature layer). See attached screenshot of widget.
But I am having trouble figuring out how to correctly access the map object from within a button click event. Here is basically what I am trying to do in a simplified way:
startup: function() { this.inherited(arguments); // This alert can access the map graphics layer ID's. alert ("Show ID's (this works): " + this.map.graphicsLayerIds) on(dom.byId("widget_button"), "click", function() { // This alert results in error. alert ("Show map ID (this DOES NOT work): " + this.map.graphicsLayerIds) }); }
I'm sure it has to do with scoping, and I've tried different ways, but am not having much success. If someone could tell me how to properly access the map object--especially the map graphics layers--in a button click event, I would appreciate it. Thanks.
Solved! Go to Solution.
Tom this is how I do it. below startup write
var mymap = this.map;
now you can just use mymap within other functions.
Tom this is how I do it. below startup write
var mymap = this.map;
now you can just use mymap within other functions.
That worked. Thank you.