How do I use a widget to clear or remove drawings and layers?

1503
7
Jump to solution
07-16-2019 07:25 AM
MichaelMitchell5
New Contributor III

I've copied the geoprocessing widget and set it up in web appbuilder to run a geoprocessing service that asks the user for an input polygon.  After a successful run I want the tool to clear the map graphics and close the widget window.

It's asynchronous so I'm editing the onJobComplete method within Widget.js.

I followed instructions here to close the widget panel and that's working successfully.

It appears the widget uses a draw tools box within the editor.  I'm not sure if I should just "click" the clear button or if there is a better solution..

How can I click the button using the attach-point name btnClear?

Thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Michael,

   In your widget you just call 

this.drawBox._onClickClear();

View solution in original post

7 Replies
MichaelMitchell5
New Contributor III

I can sort through all the this.map.graphicsLayerIds but I can't get anything for this.map.layers.  It's undefined.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michael,

   In your widget you just call 

this.drawBox._onClickClear();
MichaelMitchell5
New Contributor III

I got an error and it shows that drawBox is undefined.  What exactly is "this" referring to in this context?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michael,

  This refers to the current code scope.  You need to use lang.hitch to maintain current code scope to the widget itself.

MichaelMitchell5
New Contributor III

Thanks Robert, 

I had to do a bit of reading on lang.hitch.

The widgets onJobComplete is called using lang.hitch().  I attempt to call this.drawBox_onClickClear() within onJobComplete but "this" has no reference to drawBox.  It does have a reference to drawTools and drawTools[0] is the drawBox.

this.drawTools[0]._onClickClear() did the trick.

Is there a more elegant way to reference that?

I appreciate your help.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Actually no that is the correct way, as the GP widget can have multiple drawBox widgets it maintains them in an array unlike other widgets.

Don't forget to mark this question as answered.

0 Kudos
LeoLiu1
Occasional Contributor

Hi Michael,

Just in case you need loop layers in the map object, use this.map_layers would work.

0 Kudos