Hi,I am putting Identify tool from sample code SDK in a user control. I have followed one of the threads in here to create a dependency property for Map in user control. The identify result panel seems to work okay because it does display proper info. However, I am getting â??Object reference not set to an instance of an objectâ?? error from placing the graphic on graphic layer. I cannot figure out what is wrong. Thank you for your help,Here is what I have done.
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Identify1 control = d as Identify1;
Map newMap = e.NewValue as Map;
control.Map = newMap; // not sure if this is correct
newMap.MouseClick += control.QueryPoint_MouseClick;
}
private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
Map MyMap = this.Map;// not sure if this is correct
ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;
ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
{
Geometry = clickPoint,
MapExtent = MyMap.Extent,
Width = (int)MyMap.ActualWidth,
Height = (int)MyMap.ActualHeight,
LayerOption = LayerOption.visible,
SpatialReference = MyMap.SpatialReference
};
ArcGISDynamicMapServiceLayer myDyLayer = (ArcGISDynamicMapServiceLayer)MyMap.Layers["DynamicLayerOahu"];
string idurl = myDyLayer.Url;
IdentifyTask identifyTask = new IdentifyTask(idurl);
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
identifyTask.ExecuteAsync(identifyParams);
GraphicsLayer graphicsLayer = new GraphicsLayer();
graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics(); //This is where the error occurs
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = clickPoint,
Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphicsLayer.Graphics.Add(graphic);
}