Accessing the map object from within a button click event

3858
2
Jump to solution
05-19-2015 10:23 AM
TomFlahive
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
TimWitt2
MVP Alum

Tom this is how I do it. below startup write

var mymap = this.map;

now you can just use mymap within other functions.

View solution in original post

2 Replies
TimWitt2
MVP Alum

Tom this is how I do it. below startup write

var mymap = this.map;

now you can just use mymap within other functions.

TomFlahive
New Contributor III

That worked.  Thank you.

0 Kudos