Remove highlight from all layer

3807
5
Jump to solution
02-03-2020 03:57 AM
Vakhtang_Zubiashvili
Occasional Contributor III

Hi all,

Can someone point me how to remove highlight from all features on map? I have several layers (5 layers) and i want to remove highlight at once from all them.

Thank you in advance

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

This test app shows how to remove highlights from several layersviews at a time. 

Hope this helps,

-Undral

View solution in original post

5 Replies
Egge-Jan_Pollé
MVP Regular Contributor

Hi vakhtang zubiashvili,

Which version of the JavaScript API are you using, 3.x or 4.x?

I can provide you with a little example (using 4.13) where a parcel is highlighted when clicked and 'unhighlighted' when the popup is closed: Aan de slag met ArcGIS JavaScript - DKK Geocoder 

The relevant piece of code is shown below. But, as you can see from my notes, it was not me who figured this out. No it was Robert Scheitlin, GISP‌...

Is this example useful to you?

Cheers,

Egge-Jan

      // Make sure the clicked parcel is highlighted -  code sample provided by Robert Scheitlin, GISP on GeoNet
      view.popup.watch('selectedFeature', function(gra){
        if(gra){
          view.graphics.removeAll();
          let h = view.highlightOptions;
          gra.symbol = {
            type: "simple-fill", // autocasts as new SimpleFillSymbol()
            color: [h.color.r,h.color.g, h.color.b, h.fillOpacity],
            outline: {
              // autocasts as new SimpleLineSymbol()
              color: [h.color.r,h.color.g, h.color.b, h.color.a],
              width: 1
            }
          };
          view.graphics.add(gra);
        }else{
          view.graphics.removeAll();
        }
      });
      
      view.popup.watch('visible', function(vis){
        if(!vis){
          view.graphics.removeAll();
        }
      });
0 Kudos
Vakhtang_Zubiashvili
Occasional Contributor III

Hi Egge-Jan,

I use 4.14 version,

i tried view.graphics.removeAll(),

but it didn't work. It removes for one layer, but when i try to use it for

muktuple it doesn't work.

0 Kudos
Egge-Jan_Pollé
MVP Regular Contributor

Hi vakhtang zubiashvili,

Can you show us a sample of your code?

Egge-Jan

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

This test app shows how to remove highlights from several layersviews at a time. 

Hope this helps,

-Undral

KaiFriis
New Contributor

Thanks for the nudge in the right direction. I didn’t think about the fact that the highlight method is returning a value that I can use. On to the next ArcGIS problem. 

0 Kudos