Select to view content in your preferred language

Single vs. multiple FeatureLayers

2991
13
03-10-2011 11:41 AM
DonFreeman
Emerging Contributor
Suppose you have a map service containing a point layer and a line layer. Each of these layers is defined with a single symbol in the service. (This seems to be a requirement to get the map tip to work.) On the map we want to present these 2 layers with symbol colors representing the YEAR attribute from the service layer. This would be done with a custom renderer and associated symbol. If we are presenting 5 years worth of data with each year being a different color, would it be best to create a FeatureLayer for each year, or can all 5 years be presented in a single FeatureLayer (1 for points and 1 for lines)? Assume the years do not need to be manipulated individually. Is there a sample around that shows how to render different symbols within a layer based on the attribute data?

Thanks
0 Kudos
13 Replies
DominiqueBroux
Esri Frequent Contributor

Each of these layers is defined with a single symbol in the service. (This seems to be a requirement to get the map tip to work.)

No, I don't think so. You can use renderers and MapTips are still working.


would it be best to create a FeatureLayer for each year, or can all 5 years be presented in a single FeatureLayer

A single featurelayer is better since there will be only one query at the server side.

Is there a sample around that shows how to render different symbols within a layer based on the attribute data?

Did you look at this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#RenderersXAML

If you have to create the renderer by code, you can also look at this one : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Thematic_Interactive
0 Kudos
DonFreeman
Emerging Contributor
Thanks Dominique.
Well, I have been messing with maptips trying unsuccessfully to get them to work all week. Today I modified the service to drop the symbolization within the service and presto the maptip works. So my conclusion was that somehow the maptip was incompatible with a symbolized service. Here is an interesting experiment. The following code shows 2 layers taken from a single service. The only difference between these 2 layers is that one is symbolized and the other is not. You will see that the line layer which is symbolized will not show the data in the maptip. Whereas the point layer which is not symbolized does show the data. What would you conclude from this?
      <esri:FeatureLayer ID="ConstructionProjectsLines"
       DisableClientCaching="False"
       Url="http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_20111/MapServer/1" >
       <esri:FeatureLayer.MapTip>
        <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
         <StackPanel Margin="7">
          <StackPanel Orientation="Horizontal">
           <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
           <TextBlock Text="{Binding [ST_NAME]}" Foreground="Black" />
          </StackPanel>
         </StackPanel>
        </Border>
       </esri:FeatureLayer.MapTip>
      </esri:FeatureLayer>

      <esri:FeatureLayer ID="ConstructionProjectsPoints"
       DisableClientCaching="False"
       Url="http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_20111/MapServer/0" >
       <esri:FeatureLayer.MapTip>
        <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
         <StackPanel Margin="7">
          <StackPanel Orientation="Horizontal">
           <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
           <TextBlock Text="{Binding [ST_NAME]}" Foreground="Black" />
          </StackPanel>
         </StackPanel>
        </Border>
       </esri:FeatureLayer.MapTip>
      </esri:FeatureLayer>
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Looks like the fields returned by default are not the same if there is a renderer or if there is no renderer.

If you set OutFields="ST_NAME" (or OutFields="*"), you should be able to display it in the maptip.
0 Kudos
DonFreeman
Emerging Contributor
So Dominique, the sample you suggested looks like it would work for my situation but for some reason does not. Can you tell me what I have wrong? Here is my code.
<Grid.Resources>
   <esri2:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />
   <esri2:PictureMarkerSymbol x:Key="DefaultPictureSymbol" OffsetX="35" OffsetY="35" Source="component/Assets/images/identify.png" />
   <esri2:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Aqua" Style="Circle" />

   <esri2:SimpleMarkerSymbol x:Key="Year2011MarkerSymbol" Color="Green" Size="8" Style="Circle" />
   <esri2:SimpleMarkerSymbol x:Key="Year2012MarkerSymbol" Color="Blue" Size="8" Style="Circle" />
   <esri2:SimpleMarkerSymbol x:Key="Year2013MarkerSymbol" Color="Yellow" Size="8" Style="Circle" />
   <esri2:SimpleMarkerSymbol x:Key="Year2014MarkerSymbol" Color="Orange" Size="8" Style="Circle" />
   <esri2:SimpleMarkerSymbol x:Key="Year2015MarkerSymbol" Color="Red" Size="8" Style="Circle" />

   <esri:UniqueValueRenderer x:Key="MyUniqueValueRenderer" Attribute="CONSTYEAR" >
    <esri:UniqueValueRenderer.Infos>
     <esri:UniqueValueInfo Value="2011" Symbol="{StaticResource Year2011MarkerSymbol}" />
     <esri:UniqueValueInfo Value="2012" Symbol="{StaticResource Year2012MarkerSymbol}" />
     <esri:UniqueValueInfo Value="2013" Symbol="{StaticResource Year2013MarkerSymbol}" />
     <esri:UniqueValueInfo Value="2014" Symbol="{StaticResource Year2014MarkerSymbol}" />
     <esri:UniqueValueInfo Value="2015" Symbol="{StaticResource Year2015MarkerSymbol}" />
    </esri:UniqueValueRenderer.Infos>
   </esri:UniqueValueRenderer>

and here is my layer
<esri:FeatureLayer ID="ConstructionProjectsPoints"
       DisableClientCaching="False"
       Url="http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_20111/MapServer/0" 
        Renderer="{StaticResource MyUniqueValueRenderer}"
           Where="CONSTYEAR = 2011" >
       <esri:FeatureLayer.MapTip>
        <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
         <StackPanel Margin="7">
          <StackPanel Orientation="Horizontal">
           <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
           <TextBlock Text="{Binding [ST_NAME]}" Foreground="Black" />
          </StackPanel>
         </StackPanel>
        </Border>
       </esri:FeatureLayer.MapTip>
      </esri:FeatureLayer>

Note I only have 1 year in the Where clause just to keep it simple and I wasn't sure how to build the or. If you drop the renderer the points come in just fine. With the renderer they do not display. The CONSTYEAR field is type short.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You need to add OutFields="CONSTYEAR,ST_NAME"     (or ="*")
0 Kudos
DonFreeman
Emerging Contributor
You need to add OutFields="CONSTYEAR,ST_NAME"     (or ="*")


Ah Ha! Thanks.
Any insight into my custom renderer attempt?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Any insight into my custom renderer attempt?

Should work as well as soon as the fields used by the renderer are in OutFields.
What is the remaining issue?
0 Kudos
DonFreeman
Emerging Contributor
My problem is that when I apply the renderer the points do not display at all.
     <esri:FeatureLayer ID="ConstructionProjectsPoints"
       DisableClientCaching="False"
       Url="http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_2011/MapServer/0" 
       Where="CONSTYEAR = 2011"
       OutFields="*"
       Renderer="{StaticResource MyUniqueValueRenderer}"
        >
       <esri:FeatureLayer.MapTip>
        <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
         <StackPanel Margin="7">
          <StackPanel Orientation="Horizontal">
           <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
           <TextBlock Text="{Binding [ST_NAME]}" Foreground="Black" />
          </StackPanel>
         </StackPanel>
        </Border>
       </esri:FeatureLayer.MapTip>
      </esri:FeatureLayer>
0 Kudos
JenniferNery
Esri Regular Contributor
Looking at your map service, the attribute CONSTYEAR expects value of type Int16, which is why your UniqueValueRenderer.Infos are not matched.
CONSTYEAR (Type: esriFieldTypeSmallInteger, Alias: CONSTYEAR)


You would have to change your UniqueValueRenderer.Infos to:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
 <esri:UniqueValueInfo Symbol="{StaticResource Year2011MarkerSymbol}">
  <esri:UniqueValueInfo.Value>
   <sys:Int16>2011</sys:Int16>
  </esri:UniqueValueInfo.Value>      </esri:UniqueValueInfo> 


However, it seems that type Int16 is not found or supported in XAML for Silverlight. I was getting XamlParseException and the type Int16, which is found in the intellisense cannot be found at run-time.

You might need to define your custom renderer in code-behind or update the current renderer.
private void FeatureLayer_Initialized(object sender, System.EventArgs e)
{
 UniqueValueRenderer uvr = (sender as FeatureLayer).Renderer as UniqueValueRenderer;
 foreach (var info in uvr.Infos)
 {
  if ((Int16)info.Value == (Int16)2011)
   info.Symbol = this.LayoutRoot.Resources["Year2011MarkerSymbol"] as Symbol;
  else if ((Int16)info.Value == (Int16)2012)
   info.Symbol = this.LayoutRoot.Resources["Year2012MarkerSymbol"] as Symbol;
  else if ((Int16)info.Value == (Int16)2013)
   info.Symbol = this.LayoutRoot.Resources["Year2013MarkerSymbol"] as Symbol;
  else if ((Int16)info.Value == (Int16)2014)
   info.Symbol = this.LayoutRoot.Resources["Year2014MarkerSymbol"] as Symbol;
  else if ((Int16)info.Value == (Int16)2015)
   info.Symbol = this.LayoutRoot.Resources["Year2015MarkerSymbol"] as Symbol;
 }
}
0 Kudos