Select to view content in your preferred language

Indentify Task on a Graphics Layer

2328
6
Jump to solution
05-07-2014 12:27 PM
Cristian_Galindo
Frequent Contributor
DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far???


I have a graphics layer with several graphics, I wanto to implement an identify task, but it is asking for an URL, this layer is not associated to any service, so i dont know how to set that parameter.

Is there a way to implement that task?
0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus1
Deactivated User
IdentifyTask is designed to work with Map Services that has an service endpoint (can be local or online) so you cannot use it with in-memory GraphicsLayer. To achieve similar behavior, you need to implement query logic based on your needs directly against your GraphicsLayer. See FindGraphicsInHostCoordinates method, it might be useful while implementing it.

View solution in original post

0 Kudos
6 Replies
AnttiKajanus1
Deactivated User
IdentifyTask is designed to work with Map Services that has an service endpoint (can be local or online) so you cannot use it with in-memory GraphicsLayer. To achieve similar behavior, you need to implement query logic based on your needs directly against your GraphicsLayer. See FindGraphicsInHostCoordinates method, it might be useful while implementing it.
0 Kudos
Cristian_Galindo
Frequent Contributor
Hi,

I have some questions regarding the methos that you propose....

How is the tolerance of this?
how does it identify?

I have this question, because i draw in the graphics layer a series of polylines, the map tool tip is set, as you can see in the image the map tool tip is activated, in that position the identify tool is activated

[ATTACH=CONFIG]33760[/ATTACH]

but hte results, for each layer is:

[ATTACH=CONFIG]33761[/ATTACH]

initially i used the function

FindGraphicsInHostCoordinates(Point intersectingPoint, int maxHits)


then I try with
FindGraphicsInHostCoordinates(Rect intersectingRect, int maxHits)


and some times it works....


How can i setup the tolerace of this tool?
0 Kudos
AnttiKajanus1
Deactivated User
You define tolerance by using rectangle like you have done in second one. How big hitbox you are creating? When using point or very small rectangle it's usually hard to hit point and line graphics if they have small size/width. It might take couple iterations to get hit area correct for your users.

Another option is to use GraphicLayers mouse events if they suits in your workflow.
0 Kudos
Cristian_Galindo
Frequent Contributor
Hi!!!

I'm using a rectangle defined by the user:

[ATTACH=CONFIG]33778[/ATTACH]

As you can see, the map has geometries in it, they were drawn in a Graphics layer. After defining the rectangle, over an area that contains geometries, I would expect that they return something...but...this is my outcome:

[ATTACH=CONFIG]33779[/ATTACH]

Here is the code that I'm using:

 private void IdentifyTask(ESRI.ArcGIS.Client.Geometry.Geometry geom)
        {
            
            var initialMapPoint = new MapPoint(geom.Extent.XMin, geom.Extent.YMin);
            var finalMapPoint = new MapPoint(geom.Extent.XMax, geom.Extent.YMax);

            var initialPoint = this.myModelMap.MapToScreen(initialMapPoint);
            var finalpoint = this.myModelMap.MapToScreen(finalMapPoint);


            var intialRect = this.myModelMap.PointToScreen(initialPoint);
            var finalRect = this.myModelMap.PointToScreen(finalpoint);

            var generalTransform = this.myModelMap.TransformToVisual(Application.Current.MainWindow);
            var initialTransformedScreenPoint = generalTransform.Transform(intialRect);
            var finalTransformedScreenPoint = generalTransform.Transform(finalRect);

            var selectionRect = new Rect(initialTransformedScreenPoint, finalTransformedScreenPoint);
            var identifyResult = new Dictionary<string, IEnumerable<Graphic>>();

            
            this.IdentifyPointInLayer(identifyResult, this.VisibleLayers, selectionRect);
            
            foreach (var layer in identifyResult)
            {
                System.Text.StringBuilder displayString = new System.Text.StringBuilder();
                displayString.Append("Number of Graphics Selected: " + layer.Value.Count().ToString() + Environment.NewLine + Environment.NewLine);
                System.Windows.Forms.MessageBox.Show(displayString.ToString());
            }
        }

        private void IdentifyPointInLayer(Dictionary<string, IEnumerable<Graphic>> dictionary, LayerCollection layers, Rect point)
        {
            foreach (Layer layer in layers)
            {
                if (layer is GraphicsLayer)
                {
                    var identifyResultPerLayer = (layer as GraphicsLayer).FindGraphicsInHostCoordinates(point, 10);
                    dictionary.Add(layer.DisplayName, identifyResultPerLayer); 
                }

                if (layer is GroupLayer)
                {
                    this.IdentifyPointInLayer(dictionary, (layer as GroupLayer).ChildLayers, point);
                }
            }
        }


for the first method, the parameter geom is the rectangle that is the result of the draw over the map.

Am I performing the correct transformations?
0 Kudos
AnttiKajanus1
Deactivated User
I'm not sure if I follow all the translates correctly. You should just get rectangle points using MapToScreen and then use something like this:

Point screenPointRelativeToHost = map.TransformToVisual(Application.Current.MainWindow).Transform(screenPointRelativeToMap);

It seems that you are doing that point so issue might be in steps before that. For me it looks like you are doing at least one unnecessary step. Not sure if PointToScreen part is needed here.
0 Kudos
Cristian_Galindo
Frequent Contributor
you were correct!!!

I had an additional conversion, I works great
0 Kudos