Select to view content in your preferred language

How to create feature layer symbology

3381
9
01-12-2011 12:36 PM
DonFreeman
Emerging Contributor
Hi -
I am trying to set up a feature layer with symbology that overrides the default symbology that is defined in the map service. My code is below but the map still displays with the default red circle rather than the green diamond. Can someone see what I am doing wrong? Other than the symbology issue it seems to work OK.
Thanks
<Grid Name="MapGrid" Grid.Row="0">
   <Grid.Resources>
    <esriSymbols:SimpleMarkerSymbol x:Name="MyMarkerSymbol" Color="Green" Style="Diamond" Size="10" />    
   </Grid.Resources>
  
   <esri:Map x:Name="MyMap" Grid.RowSpan="2" >
    <esri:Map.Layers>

     <esri:ArcGISDynamicMapServiceLayer ID="SchoolSearch3" 
      Url="http://198.182.104.173/ArcGIS/rest/services/SchoolSearch3/MapServer"
      VisibleLayers="0,1" />

     <esri:FeatureLayer ID="MyFeatureLayer" 
      Url="http://198.182.104.173/ArcGIS/rest/services/BikeCounts_Test/MapServer/0"
      MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
      DisableClientCaching="True"
      Mode="OnDemand"
      OutFields="*" 
      SelectionColor="Yellow"     
      FeatureSymbol="{StaticResource MyMarkerSymbol}"
      Where="1=1" 
      />
     
    </esri:Map.Layers>
   </esri:Map>

  </Grid>
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
The FeatureLayer's Renderer trumps FeatureSymbol. Since the service already defines a Renderer, the FeatureSymbol is ignored. The only way you can override the Renderer defined by the service is to create your own renderer.

For example:
Under Resources...
  <esri:SimpleRenderer x:Key="MyRenderer">
   <esri:SimpleRenderer.Symbol>
    <esri:SimpleMarkerSymbol Color="Red" Style="Circle" Size="10"/>
   </esri:SimpleRenderer.Symbol>
  </esri:SimpleRenderer>


FeatureLayer..
<esri:FeatureLayer Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0"
          Renderer="{StaticResource MyRenderer}"/>
0 Kudos
DonFreeman
Emerging Contributor
Jennifer -
Thanks. That looks simple enough. I will give it a try. Is there a way to create the service so that it doesn't define a built in renderer?

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
I'm not sure, I have not created a service but you might want to check this documentation: http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#/Authoring_fea.... "Defining a symbology" under Setting up the Map Document.
0 Kudos
DonFreeman
Emerging Contributor
The FeatureLayer's Renderer trumps FeatureSymbol. Since the service already defines a Renderer, the FeatureSymbol is ignored. The only way you can override the Renderer defined by the service is to create your own renderer.

For example:
Under Resources...
  <esri:SimpleRenderer x:Key="MyRenderer">
   <esri:SimpleRenderer.Symbol>
    <esri:SimpleMarkerSymbol Color="Red" Style="Circle" Size="10"/>
   </esri:SimpleRenderer.Symbol>
  </esri:SimpleRenderer>


FeatureLayer..
<esri:FeatureLayer Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0"
          Renderer="{StaticResource MyRenderer}"/>



Jenn -
Thanks so much. I tried your code and it works fine for me except now the selection color is inoperative. How would you provide for that? Would I need another renderer with a different symbol? My code:
<Grid Name="MapGrid" Grid.Row="0">
   <Grid.Resources>    
    <esri:SimpleRenderer x:Key="MyRenderer">
     <esri:SimpleRenderer.Symbol>
      <esriSymbols:SimpleMarkerSymbol x:Name="MyMarkerSymbol" Color="Green" Style="Diamond" Size="10" />
     </esri:SimpleRenderer.Symbol>
    </esri:SimpleRenderer>
   </Grid.Resources>
  
   <esri:Map x:Name="MyMap" Grid.RowSpan="2" >
    <esri:Map.Layers>

     <esri:ArcGISDynamicMapServiceLayer ID="SchoolSearch3" 
      Url="http://198.182.104.173/ArcGIS/rest/services/SchoolSearch3/MapServer"
      VisibleLayers="0,1" />

    <esri:FeatureLayer ID="MyFeatureLayer" 
      Url="http://198.182.104.173/ArcGIS/rest/services/BikeCounts_Test/MapServer/0"
      MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
      DisableClientCaching="True"
      Mode="OnDemand"
      OutFields="*" 
      SelectionColor="Cyan"     
      Renderer="{StaticResource MyRenderer}"
      Where="1=1" 
      />
     
    </esri:Map.Layers>
   </esri:Map>

  </Grid>
0 Kudos
DominiqueBroux
Esri Frequent Contributor

I tried your code and it works fine for me except now the selection color is inoperative. How would you provide for that? Would I need another renderer with a different symbol?


You can keep the same renderer but use a symbol managing the 'Selected' state.

Example coming from the interactive samples:
<esriSymbols:MarkerSymbol x:Key="SelectMarkerSymbol" >
<esriSymbols:MarkerSymbol.ControlTemplate>
<ControlTemplate>
<Ellipse x:Name="Element" Width="15" Height="15" StrokeThickness="10" 
Stroke="Green" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element" 
Storyboard.TargetProperty="(Ellipse.Stroke).(SolidColorBrush.Color)"
To="Cyan" Duration="00:00:0.25"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Ellipse>
</ControlTemplate>
</esriSymbols:MarkerSymbol.ControlTemplate>
</esriSymbols:MarkerSymbol>
 
0 Kudos
DonFreeman
Emerging Contributor
Thanks Dominique. This certainly works although I find it extremely complex for such a simple task. (Oh well, that's ESRI) What would you do if you wanted a shape other than ellipse? Perhaps Square or Diamond. I can't seem to get them to work.
0 Kudos
DanielWalton
Frequent Contributor
For square use Rectangle instead of Ellipse. For diamond use

[HTML]
<Rectangle RenderTransformOrigin=".5,.5">
<Rectangle.RenderTransform>
<RotateTransform Angle="45" />
</Rectangle.RenderTransform>
</Rectangle>
[/HTML]

The complexity isn't just ESRI's fault. Blame Microsoft too. 🙂
0 Kudos
DonFreeman
Emerging Contributor
Thanks Dan. Yes, MS is equally to blame if not more so.
0 Kudos
DonFreeman
Emerging Contributor
Now that I have the ability to modify the feature symbols, I would like to know if the following is possible or feasible. My map contains a point layer drawn from a Map service (not a feature service). There is a second table (Table2) which is associated with the point layer in a 1 to many relationship. The user clicks a point on the map and the related records (usually 2) are shown in a datagrid below the map. The user can edit the records in Table2 to "claim" the point. If both of the records associated with a point have been claimed I would like to either remove the point from the map or display it with a different color symbol so that subsequent users will readily see that the point has been taken and it is no longer available for editing.

The technique I have in mind is on page load to iterate through the points and for each point to query Table2. If no records match the unclaimed criteria then the point symbol for that point would be changed indicating that it has been claimed. Does this sound like it would be a reasonable undertaking and if so could someone get me started on how to do it?
Thanks
0 Kudos