Select to view content in your preferred language

Fill Symbol not working with Identify Task

1084
5
03-24-2011 08:52 AM
NaveenMaram
Emerging Contributor
Hi All,

I am working on creating an application where i will be having a cached map service with 4 layers( Country, state, county and zip code levels) in it. my requirement is we need to bind this service to the silverlight application and when we zoom to each level and click on state or county or zip code levels, at each level we need to able to select single or multiple state or county or zip code and fetch the values from db and bind to grid. And also i need to highlight the selected state or county or zip with different colors and borders.

I have used the IdentifyTask to achieve this, i am able to get the results i required and i am able to display in the results grid, but the problem i am facing is i am not able to highlight the selected country or state or county or zip with diffrent colors. i have used fillSymbol for this, I am not sure what the problem is, for your refference i am pasting my code below

private void MyMap_Click(object sender, Map.MouseEventArgs e)
{
ESRI.ArcGIS.Client.Geometry.MapPoint clickpoint = e.MapPoint;
ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
{
Geometry = clickpoint,
MapExtent = MyMap.Extent,
Width = (int)MyMap.Width,
Height = (int)MyMap.Height,
LayerOption = LayerOption.visible
};
IdentifyTask identifyTask = new IdentifyTask("http://10.12.12334/ArcGIS/rest/services/France/MapServer");
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
identifyTask.ExecuteAsync(identifyParams);
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Graphic graphic = new Graphic()
{
Geometry = clickpoint,
Symbol = ResultsFillSymbol
};
graphicsLayer.Graphics.Add(graphic);

}
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
{
if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
{
EditArea.Visibility = Visibility.Visible;
foreach (IdentifyResult result in args.IdentifyResults)
{
txtName.Text = result.Value.ToString();
string[] strZoomLevel = result.LayerName.ToString().Split('.');
for (int i = 0; i < strZoomLevel.Length; i++)
{
if (i == 2){txtZoomLevel.Text = strZoomLevel.ToString();}
}
}
}
else
{
EditArea.Visibility = Visibility.Collapsed;
}
// MyDrawSurface.IsEnabled = false;
}

private void IdentifyTask_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Identified failed. Error: " + e.Error);
}

XAML:
<Grid x:Name="LayoutRoot">
<Grid.Resources>
<esriSymbols:FillSymbol x:Name="DefaultFillSymbol" >
<esriSymbols:FillSymbol.ControlTemplate>
<ControlTemplate>
<Path x:Name="Element" IsHitTestVisible="False" Fill="#66FF0000"
Stroke="Red" StrokeThickness="1"/>
</ControlTemplate>
</esriSymbols:FillSymbol.ControlTemplate>
</esriSymbols:FillSymbol>
<esriSymbols:FillSymbol x:Name="ResultsFillSymbol">
<esriSymbols:FillSymbol.ControlTemplate>
<ControlTemplate x:Name="CustomPolygonTemplate">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Fill).(Color)"
To="#880000FF" Duration="0:0:0.1" />
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Fill).(Color)"
To="#8800FFFF" Duration="0:0:0.1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Fill).(Color)"
To="#8800FFFF" Duration="0:0:0.1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="Element" Stroke="Blue" Fill="#880000FF"
StrokeStartLineCap="Round" StrokeThickness="2"
StrokeLineJoin="Round" StrokeEndLineCap="Round" />
</Grid>
</ControlTemplate>
</esriSymbols:FillSymbol.ControlTemplate>
</esriSymbols:FillSymbol>
</Grid.Resources>
<esri:Map x:Name="MyMap" Background="White" Width="2000" Height="2200" Margin="-600,-130,0,10" MouseClick="MyMap_Click" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="BaseMapLayer"
Url="http://10.12.12334/ArcGIS/rest/services/France/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicLayer"></esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map>
<Grid HorizontalAlignment="Right" x:Name="EditArea" Height="250" VerticalAlignment="Bottom" Margin="0,10,10,0" Visibility="Collapsed" >

<Rectangle Fill="#ee4b7ba7" Stroke="White" RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
<Rectangle.Effect>
<DropShadowEffect/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#FFFFFFFF" Stroke="Black" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
<Grid>
<Grid.RowDefinitions >
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="30,20,20,30" x:Name="EditDetails">
<Grid VerticalAlignment="Top" >
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions >
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="CustomareaName" Width="120" Grid.Row="0" Grid.Column="0"
Text="Custom area Name:" TextAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Bottom" />
<TextBox x:Name="txtName" Grid.Row="0" Grid.Column="1" Height="20" />
<TextBlock x:Name="Zoomlevel" Width="120" Grid.Row="1" Grid.Column="0"
Text="Zoom Level:" TextAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Bottom" />
<TextBox x:Name="txtZoomLevel" Grid.Row="1" Grid.Column="1" />
</Grid>

</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="top" >
<Button Height="25" Content="Define as custom area" x:Name="UnionButton" Width="150"
IsEnabled="False" />
<Button Height="25" Content="Modify" x:Name="ModifyButton" Width="70"
Visibility="Collapsed" />
<Button Height="25" Content="Delete" x:Name="DeleteButton" Width="70"
Visibility="Collapsed" />
</StackPanel>
</Grid>
</Grid>

</Grid>

If i am using simpleMarkersymbol or simplelinesymabol then i am able to display, but not the fill Symbol. Could some one help me in this please.

Thanks in advance!!

Naveen.
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
If Marker and Line Symbol worked, then maybe the IdentifyResults.Feature is Point or Polyline geometry.

Maybe you can determine the geometry type before you set the symbol. Something like:
foreach (var result in e.IdentifyResults)
{
 Symbol symbol = null;
 if (result.Feature.Geometry is MapPoint)
  symbol = this.LayoutRoot.Resources["RedMarkerSymbol"] as Symbol;
 else if (result.Feature.Geometry is Polyline)
  symbol = this.LayoutRoot.Resources["RedLineSymbol"] as Symbol;
 else if(result.Feature.Geometry is Polygon)
  symbol = this.LayoutRoot.Resources["RedFillSymbol"] as Symbol;
}
0 Kudos
NaveenMaram
Emerging Contributor
If Marker and Line Symbol worked, then maybe the IdentifyResults.Feature is Point or Polyline geometry.

Maybe you can determine the geometry type before you set the symbol. Something like:
foreach (var result in e.IdentifyResults)
{
 Symbol symbol = null;
 if (result.Feature.Geometry is MapPoint)
  symbol = this.LayoutRoot.Resources["RedMarkerSymbol"] as Symbol;
 else if (result.Feature.Geometry is Polyline)
  symbol = this.LayoutRoot.Resources["RedLineSymbol"] as Symbol;
 else if(result.Feature.Geometry is Polygon)
  symbol = this.LayoutRoot.Resources["RedFillSymbol"] as Symbol;
}


Hi Jeneffier,

Thanks for reply.

Yep you are correct i am using geomentary as Map point, but i don't want to use simplemarkersymbol. I need to use fill symbol.

If we have mappoint as geomentary then how can we use fill symbol. could you please guide me in this. or if you have any help links please forward it.

Thanks in advance.

Naveen
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Yep you are correct i am using geomentary as Map point, but i don't want to use simplemarkersymbol. I need to use fill symbol.
If we have mappoint as geomentary then how can we use fill symbol. could you please guide me in this.


If you want to use a fill symbol with a map point you have first to convert the map point to a polygon or envelope geometry (that support fill symbol).

Something like:
var env = new Envelope(point.X - 1000, point.Y - 1000, point.X + 1000, point.Y + 1000) { SpatialReference = point.SpatialReference };
graphic = new Graphic()
{
    Geometry = env,
    Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphicsLayer.Graphics.Add(graphic);


That being said I am not sure you need this conversion, if you are identifying 'States' or 'Counties' you shoud directly get polygon geometries.
0 Kudos
NaveenMaram
Emerging Contributor
If you want to use a fill symbol with a map point you have first to convert the map point to a polygon or envelope geometry (that support fill symbol).

Something like:
var env = new Envelope(point.X - 1000, point.Y - 1000, point.X + 1000, point.Y + 1000) { SpatialReference = point.SpatialReference };
graphic = new Graphic()
{
    Geometry = env,
    Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphicsLayer.Graphics.Add(graphic);


That being said I am not sure you need this conversion, if you are identifying 'States' or 'Counties' you shoud directly get polygon geometries.


Thanks for the reply,

I got it worked. I have changed the below code

foreach (IdentifyResult identifyResult in args.IdentifyResults)
            {
                ESRI.ArcGIS.Client.Graphic graphic = new Graphic()
                    {
                        Geometry = identifyResult.Feature.Geometry,
                        Symbol = ResultsFillSymbol
                    };
                graphicsLayer.Graphics.Add(graphic);
               
            }
             
I have one more question. How can we allow user to select multiple countries or states or zip in graphics layer. If you have any samples or any guide line please let me know.

Thanks In advance.

Naveen
0 Kudos
JenniferNery
Esri Regular Contributor
You can look at the following samples:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection

The second sample will also work with GraphicsLayers as long as you provide them an ID. You will also need to define symbols that distinguish between the two VisualStates (selected/unselected). Similar to this: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics
0 Kudos