Select to view content in your preferred language

Highlight on FeatureLayer

581
1
Jump to solution
09-09-2021 03:23 AM
PaoloF
by
Occasional Contributor

Hi everyone into Community.

I have an Angular application where I load portalID item derivede from DXF file as FeatureLayer and I highlight layer polygons according to selection.

I woud like to dinamically change color before highlighting the resulting feature, but setting it in highlightOptions of the mapView doesn't affet the result.

The following is the code I wrote:

public highlight(filter: string) {
    console.log(this.mapView.highlightOptions.color);
    this.mapView.highlightOptions.color = new Color('green');
    console.log(this.mapView.highlightOptions.color);
    this.mapView.whenLayerView(this.featureLayer).then((layerView) => {
      const query: Query = new Query();
      query.returnGeometry = true;
      query.outFields = ['*'];
      query.where = "Text='" + filter + "'";
      this.featureLayer.queryFeatures(query).then((result) => {
        if (this.highlightState) {
          this.highlightState.remove();
        }
        console.log(this.mapView.highlightOptions.color);
        this.highlightState = layerView.highlight(result.features) as Handle;
      });
    });
  }

As you can see, I added console.log instruction to check the setting when I call the function and I try to change its value: during execution when I enter first time into the function I see that setting is initialized as made in mapView definition (RED), it's correctly modified to GREEN, but the highlight item is always shown in RED.
When I call again the function, the setting is GREEN from the beginning, but highlight is in RED.

May any of you explain what I'm doing wrong?
Thanks in advance, best regards.

0 Kudos
1 Solution

Accepted Solutions
PaoloF
by
Occasional Contributor

Hi everyone.

I solved by myself the issue I post this morning in following way:

 

this.mapView.set('highlightOptions', { color });

 

 where color is a string variable containing the color I desire to show.

View solution in original post

1 Reply
PaoloF
by
Occasional Contributor

Hi everyone.

I solved by myself the issue I post this morning in following way:

 

this.mapView.set('highlightOptions', { color });

 

 where color is a string variable containing the color I desire to show.