Select to view content in your preferred language

Change background color of highlighted feature layer ArcGIS JavaScript

686
1
02-13-2023 12:07 AM
aggarwalarpit93
New Contributor II

I have a feature layer and I am highlighting the feature of the feature layers on click. It is working fine.

Now what I want is, I want to change the background color / fill some color in that highlighted polygon feature.

Here is the code where I am highlighting the feature:

 

let highlight;
let highlightIds = [];

view.whenLayerView(districtLayer).then(function(layerView){
    view.on("click", (event) => {
        const params = {
            location: event.mapPoint
        };
        locator.locationToAddress(serviceUrl, params).then(function(response) { // Show the address found
            
            const district = response.attributes.Subregion;

            // remove all highlights first
            if(highlight) {
                highlight.remove();
            }

            // check if district is already highlighted
            let district_id = districtIds.indexOf(district) + 1;
            if(highlightIds.includes(district_id)){
                highlightIds.splice(highlightIds.indexOf(district_id), 1);
            }else{
                highlightIds.push(district_id);
            }

            // hightlight only the selected districts
            highlight = layerView.highlight(highlightIds);

            // code here to fill background color

        }, function(err) { // Show no address found
            console.log("No address found.", evt.mapPoint);
        });
    });
});
0 Kudos
1 Reply
Christer
New Contributor II

If you just want to change the standard highlight color you can access  `highlightOptions` of the view. 

 

view.highlightOptions = {}

 

 
0 Kudos