Clear Graphics Widget

1838
3
12-23-2016 03:21 PM
AdamVellutini
New Contributor III

Hello,

We have been asked for a widget that will clear all graphics on a map; including selected features and any graphics drawn by the draw widget.  We used to have one in a vendor supplied Silverlight application and users became used to it and are missing that functionality with our WAB applications.  First, I wanted to see if anyone is using a custom widget for this purpose.  I have not seen one posted anywhere.  It may be that we have to develop our own but I wanted to reach out first - in the event someone wants to share! 

Any ideas welcome.

Thanks,

Adam

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Adam,

   I have never seem such a widget shared. But building one would be as simple as looping through all the maps graphicslayers and clearing each.

              this.map.graphics.clear();
              arrayUtils.map(this.map.graphicsLayerIds, lang.hitch(this, function(glid){
                 var lyr = this.map.getLayer(glid);
                 if(lyr instanceof FeatureLayer){
                   lyr.clearSelection();
                 } else {
                   this.map.getLayer(glid).clear();
                 }
              }));
AdamVellutini
New Contributor III

Robert,

Thank you that code works great.  Unfortunately it has taken this long to get back on this project.  While this does clear any selected features and map graphics, I need to find a way to clear any search results from the eSearch widget results as well as from the attribute table.  That will be the next step in the process...  If you have any ideas or advice I would love to hear it!  Otherwise, thank you for the start.

Cheers,

Adam

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Adam,

   Are you saying that you want to remove the eSearch results from the map? If so then you would have to get an instance of the eSearch widget and execute the clear method.

define([
...
  'jimu/WidgetManager',
...
],
  function (
...
  WidgetManager
...
) {
  var wm = WidgetManager.getInstance();
  var esWidget = this.wManager.getWidgetByLabel("eSearch");
  esWidget.clear();
...

What do you mean by: 

as well as from the attribute table.
0 Kudos