Select to view content in your preferred language

GraphicsLayer not display even though contains graphics...

3191
1
08-19-2013 06:08 AM
YurongTan
Regular Contributor
I have a GraphicsLayer "MySelectedPoint" to hold a selected point feature with a different symbol to distinguish it from the underlying graphics layer, but the selected point does not display nor is it visible.  I spent some time looking around for an answer, but couldn't figure out what I missed.   Here is the code:

Two marker symbols (smaller solid red and larger blue cross).  The red one is for the underlying graphicslayer "MyGraphicsLayer" and the blue larger one cross is for the selected graphic in "MySelectedPoint" layer.
<Grid.Resources>
<esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Size="30" Color="Blue" Style="Cross" />
<esri:SimpleMarkerSymbol x:Key="SimpleMarkerSymbol" Size="14" Color="Red" Style="Circle" />


<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000">
<esri:GraphicsLayer ID="MyGraphicsLayer" Opacity="0.8" />
<esri:GraphicsLayer ID="MySelectedPoint"/>


When a record is selected in the DataGrid table, the graphic corresponding to the selected record is cloned and add to the "MySelectedPoint" graphicslayer which does not display even thoug there is a record/graphic in it with cordinates and symbology.
private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid myTargetPoint = sender as DataGrid;
int mySelection = myTargetPoint.SelectedIndex;
if (mySelection > -1)
{
  GraphicsLayer mySelectedPoint = MyMap.Layers["MySelectedPoint"] as GraphicsLayer;
  mySelectedPoint.ClearGraphics();

    Graphic thisPoint = (Graphic)FindDetailsDataGrid.SelectedItems[0];
    if (thisPoint != null)
  {
   Graphic myPoint = new Graphic();
   myPoint.Geometry = thisPoint.Geometry.Extent.Clone();
   myPoint.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol;

   mySelectedPoint.Graphics.Add(myPoint);
   mySelectedPoint.Visible = true;
   mySelectedPoint.Opacity = 1.0;
  }
}

}

What do I miss here?  Thanks
0 Kudos
1 Reply
YurongTan
Regular Contributor
DataGrid dataGrid = sender as DataGrid;
int selectedIndex = dataGrid.SelectedIndex;
if (selectedIndex > -1)
{
GraphicsLayer MyFlashGraphicPoint = MyMap.Layers["MyFlashingGraphicPoint"] as GraphicsLayer;
Graphic xgraphic = (Graphic)FindDetailsDataGridCAP.SelectedItem;
if (xgraphic != null)
{
  if (xgraphix.TYPE == "POINT")
  {
   double flareAtX = xgraphic.Geometry.Extent.XMin;
   double flareAtY = xgraphic.Geometry.Extent.YMin;
   MyMap.PanTo(xgraphic.Geometry);

   MyFlashGraphicPoint = null;
   MyFlashGraphicPoint = (ESRI.ArcGIS.Client.GraphicsLayer)(MyMap.Layers["MyFlashingGraphicPoint"]);
   ESRI.ArcGIS.Client.GraphicCollection esriGraphicsCollection = MyFlashGraphicPoint.Graphics;

   Graphic myFlash = esriGraphicsCollection[0];
   ESRI.ArcGIS.Client.Geometry.MapPoint oldPoint = null;
   oldPoint = (ESRI.ArcGIS.Client.Geometry.MapPoint)myFlash.Geometry;

   ESRI.ArcGIS.Client.Geometry.MapPoint myFlarePoint = new ESRI.ArcGIS.Client.Geometry.MapPoint();
   myFlarePoint.X = flareAtX;
   myFlarePoint.Y = flareAtY;

   myFlash.Geometry = myFlarePoint;
   FlashingGraphicPoint.Visible = true;  // The point is a strobe of different colors
  }
  else
  {
   // a polygon area will flashing
  }
}
}
0 Kudos