1

I am using the code that the documentation provides here:

require(["esri/views/View"], (View) => {
view.on("click", function(event){
  view.hitTest(event).then(function(response){
    if (response.results.length) {
      let graphic = response.results.filter(function (result) {
        return result.graphic.layer === states;
      })[0].graphic;
    
     view.whenLayerView(graphic.layer).then(function(layerView){
       layerView.highlight(graphic);    
     });
    }
  });
});
});

I want to know how I could adjust the color based on the currently selected color. For example, how would I detect the current highlighted color and base the new one off of that. For example:

if (color == currentColor) {
  highlightOptions = {
    new color for highlightOptions 
  }

1 Answer 1

1

You can get current select color from view.highlightOptions.color property and you can set select color by changing value of this property.

Code below increments current blue channel of select color for clicked feature on each click by 20:

const view = new SceneView({
  map: webScene,
  container: "viewDiv",
  highlightOptions: {
    color: [255, 0, 0],
    fillOpacity: 0.4
  }
});

view.on("click", function(event){
  view.hitTest(event).then(function(response){
    if (response.results.length) {
      let graphic = response.results.filter(function (result) {
        return result.graphic.layer.declaredClass == "esri.layers.FeatureLayer";
      })[0].graphic;
    
      view.whenLayerView(graphic.layer).then(function(layerView) {
        var color = view.highlightOptions.color;
        var blue = color.b + 20;
        if (blue > 255) blue = 0;
        view.highlightOptions = {
          color: [255, 0, blue]
       };
       layerView.highlight(graphic);    
     });
    }
  });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.