Flex viewer set line colour for selected feature

4462
4
Jump to solution
01-07-2015 07:39 PM
KoseWong
New Contributor

Greetings,

I use querytask to select polyline feature, but the selected feature colour just the same of all other features in the same layer. I tried to set the colour use:

<esri:SimpleLineSymbol id="lineSymbol"
  alpha="0.4"
  color="0x0000FF"
  width="2">

But it is no effect.

I add code in querytask onResult function using

graphicsLayer.symbol = sfs;

Also no effect.

Is there an example for set colour for polyline selected feature(s), the sample I found both for polygon features.

Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Kose,

  Here is the code fixed:

queryTask.execute(query, new AsyncResponder(onQueryResult, onQueryFault)); 

function onQueryResult(resultSet:FeatureSet, token:Object = null):void  
  {  
      graphicsLayer.clear();  
      if (resultSet.features.length == 0){  
          Alert.show("No feature returned, please try again.");  
      }else{  
          var finalExtent:Extent;  
          var stGraphic:Graphic = resultSet.features[0];  
          finalExtent = Polyline(stGraphic.geometry).extent;  
          resultLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0x0000FF, 0.4, 2);
          graphicsLayer.symbol = resultLineSymbol;
          for each (var graphic:Graphic in resultSet.features){
              stGraphic = new Graphic(graphic.geometry);
              graphicsLayer.add(graphic);  
              finalExtent = finalExtent.union(Polyline(graphic.geometry).extent);
          }   
          map.extent = finalExtent;
      }
  }

function onQueryFault(faultInfo:Object, token:Object = null):void  
  {  
      Alert.show(faultInfo.toString());  
  } 

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Kose,

  Without seeing your code, all I can do is guess based on your minimal code shared. One thing that sticks out is

graphicsLayer.symbol = sfs;

Normally people use sfs for a Simple Fill Symbol and not a SImpleLineSymbol. Also the graphicsLayer symbol will be ignored if the actual graphic gets a symbol assigned in the code.

0 Kudos
KoseWong
New Contributor

Hello Robert,

Thanks for your explanation, sorry to provide piece of code.

The related code as follows:

queryTask.execute(query, new AsyncResponder(onQueryResult, onQueryFault));

function onQueryResult(resultSet:FeatureSet, token:Object = null):void 

  { 

      graphicsLayer.clear(); 

      if (resultSet.features.length == 0) 

      { 

          Alert.show("No feature returned, please try again."); 

      } 

      else 

      { 

          var finalExtent:Extent; 

          var stGraphic:Graphic = resultSet.features[0]; 

          finalExtent = Polyline(stGraphic.geometry).extent; 

          stGraphic = new Graphic();

          for each (var graphic:Graphic in resultSet.features) 

          { 

              stGraphic.geometry = graphic.geometry;

              //resultLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0x0000FF, 0.4, 2); // this line no use, right?

              graphicsLayer.add(graphic); 

              finalExtent = finalExtent.union(Polyline(graphic.geometry).extent);  

              graphicsLayer.symbol = sfs;

          }  

          map.extent = finalExtent;

      }

  }

function onQueryFault(faultInfo:Object, token:Object = null):void 

  { 

      Alert.show(faultInfo.toString()); 

  }

There is no other code to set the symbol. Is there something wrong with my code?

Thank you so much.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kose,

  Here is the code fixed:

queryTask.execute(query, new AsyncResponder(onQueryResult, onQueryFault)); 

function onQueryResult(resultSet:FeatureSet, token:Object = null):void  
  {  
      graphicsLayer.clear();  
      if (resultSet.features.length == 0){  
          Alert.show("No feature returned, please try again.");  
      }else{  
          var finalExtent:Extent;  
          var stGraphic:Graphic = resultSet.features[0];  
          finalExtent = Polyline(stGraphic.geometry).extent;  
          resultLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0x0000FF, 0.4, 2);
          graphicsLayer.symbol = resultLineSymbol;
          for each (var graphic:Graphic in resultSet.features){
              stGraphic = new Graphic(graphic.geometry);
              graphicsLayer.add(graphic);  
              finalExtent = finalExtent.union(Polyline(graphic.geometry).extent);
          }   
          map.extent = finalExtent;
      }
  }

function onQueryFault(faultInfo:Object, token:Object = null):void  
  {  
      Alert.show(faultInfo.toString());  
  } 
0 Kudos
KoseWong
New Contributor

Hi Robert,

It works! Thank you very very much!!

0 Kudos