Select to view content in your preferred language

Identify Tool in UserControl

569
2
09-20-2011 01:39 PM
WalterKuong_-_DIT
Emerging Contributor
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);
        }


0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();  //This is where the error occurs


At first glance, there is no layer with "MyGraphicsLayer" as ID in your map.
How is created the map?
0 Kudos
WalterKuong_-_DIT
Emerging Contributor
At first glance, there is no layer with "MyGraphicsLayer" as ID in your map.
How is created the map?


Hi Dominique,

I have setup the "MyGraphicsLayer" in the MainPage.xaml as a graphicslayer along with one Tile and one Dynamic layer, and the Dynamic layer is the layer that I used to do Identify with.  Assuming that the "Map" has been passed to this control from MainPage correctly, I thought I can specified the graphics layer as such.

Thank you,
0 Kudos