web appbuilder

1416
10
Jump to solution
10-13-2017 01:41 PM
MonaBrisco
New Contributor III

Hello All,

I am trying to get a custom widget(CW) to work that uses a map click event.  The widget works as standalone but if also using the OOTB measurement widget(MW) I get weird behavior.  If I use the OOTB MW before I use the CW then I get expected behavior for both tools.  However, if I use the CW followed by the MW, when I close the CW the symbol it uses is cleared from the map but when using the MW the symbol replaces esri greenpin, the line segments disappear on dbl-clicks, and when MW is closed, the CW symbol remains.  Any ideas on how to resolve other than re-implement the OOTB MW(and I did not want to edit the OOTB MW code)?  I thought by using onClose() in CW to remove graphic/clear

map would resolve since graphic was removed(but looks like both widgets are bound to event).

Thanks in advance,

Mona

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Mona,

   The var for the event handler is in the wrong position:

this.own(tmp = on(myMap, "click", lang.hitch(this, this.on_myMapClick)));

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Mona,

   I sounds like you are forgetting to remove to map click event handler on your CW onClose Event. When you add the map on click event you can assign the click event handler to a var and then your you onClose you can call the .remove() method on the event.

0 Kudos
MonaBrisco
New Contributor III

Forgot to add…I received the error:

fail to close widget XY Tool. TypeError: Object doesn't support property or method 'remove'

So I am still researching…

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mona,

   Are you assigning a event handler var to your map click event? Maybe you should have some code here to make this easier.

0 Kudos
MonaBrisco
New Contributor III

Robert,

My 1st response with code didn't make it through I guess...apologies.

startup: function () {

...

   tmp = this.own(on(myMap, "click", lang.hitch(this, this.on_myMapClick)));

...

}

              onClose: function() {
                  console.log('onClose');
                  myMap.graphics.clear();
                  //console.dir(myMap);
                  //console.dir(graphicsLayer);
                  if(graphicsLayer)
                    graphicsLayer.remove(this._myMarkerSymbol);
                  myMap.setInfoWindowOnClick(true);
                  tmp.remove();
              },

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mona,

   The var for the event handler is in the wrong position:

this.own(tmp = on(myMap, "click", lang.hitch(this, this.on_myMapClick)));

MonaBrisco
New Contributor III

 Should have looked up syntax...

Thanks so much Robert I really appreciate it!

0 Kudos
MonaBrisco
New Contributor III

Robert,

If I close the widget and re-open to use, the widget is no longer functional.

If I wanted to re-use the tool n times after it is closed, is there another suggested workflow to implement?

Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mona,

   On open you need to re add the event listener if the tmp is null.

0 Kudos
MonaBrisco
New Contributor III

Robert,

Great! You’ve been awesome!

0 Kudos