Select to view content in your preferred language

GraphicsLayer takes on opacity from FeatureLayer

1697
13
Jump to solution
03-13-2018 12:45 PM
MKF62
by
Frequent Contributor

I'm trying to symbolize selections using a GraphicsLayer derived from a FeatureLayer. When I change the opacity of the FeatureLayer and get a graphic based on whatever polygon I have clicked on, it sets the opacity of the GraphicsLayer to the same as the FeatureLayer, even if I set the opacity to something different on the GraphicsLayer. 

When they click on a radio button here, the opacity of the FeatureLayer changes to reflect their choice:

        on(query('input[name="setOpacity"]'), "click", function (evt){
          var opacity = evt.target.id;
          switch(opacity){
            case "100-percent":
              featureLayer.opacity = 1;
              break;
            case "25-percent":
              featureLayer.opacity = .25;
              break;
            case "50-percent":
              featureLayer.opacity = .5;
              break;
            case "75-percent":
              featureLayer.opacity = .75;
              break;
          }
        });

Next, if I select a polygon on the map (via clicking), I create a new graphic of that polygon and set the symbol to be a blue outline. Then I add it to a GraphicsLayer, set the opacity to 1, and then add it to the map. But the opacity remains at 25/50/75 percent or whatever is selected by the user on the FeatureLayer. Is this happening because the graphic is derived from the FeatureLayer? Is there a way to fix this?

        view.on("click", function(evt){
          var screenPoint = {
            x: evt.x,
            y: evt.y
          };
          view.hitTest(screenPoint).then(getGraphics);
        });
        
        var graphicLyr = new GraphicsLayer({});
        
        function getGraphics(response){
          graphicLyr.removeAll();
          var selectionSymbol = {
            type: "simple-fill",
            style: "none",
            outline: {
              color: [56, 247, 247],
              width: 2
            }
          }
          var graphic = new Graphic({
            geometry: response.results[0].graphic.geometry,
            symbol: selectionSymbol
          });
          graphicLyr.add(graphic);
          graphicLyr.opacity = 1;
          map.add(graphicLyr);
        };‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

Molly,

   Your selection symbol is just the outline of the poly with no fill so are you saying that the outline is using the opacity of the original FeatureLayer?

0 Kudos
MKF62
by
Frequent Contributor

Yes, it's just an outline. Anytime I change the opacity on the FeatureLayer, the outline, which should be on the GraphicsLayer, also becomes transparent.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

   After modifying your code to use another layer I have determined that it is nothing in your code that is at fault and this seems to be a bug that you need to report to esri tech support ASAP.

0 Kudos
MKF62
by
Frequent Contributor

Thanks for all your help and testing Robert. I will submit a bug to ESRI.

0 Kudos