Select to view content in your preferred language

How select symbol of graphiclayer added in runtime?

2908
4
01-12-2011 02:14 PM
StefhanCampos
Deactivated User
Hi, i added many symbols on graphiclayer in runtime. Now i want draw a rectacle or polygon and get all symbols of graphiclayer in rect/polygon area(something like contains drawobject), how i can do that?

ps:cannot use new api feature "Editor".
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
I'm sorry I did not understand the question. Are you trying to use Draw (similar to this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DrawGraphics) ? And you are trying to set or get the graphic symbol?
0 Kudos
StefhanCampos
Deactivated User
I'm sorry I did not understand the question. Are you trying to use Draw (similar to this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DrawGraphics) ? And you are trying to set or get the graphic symbol?


i create a layer in tuntime and add graphics:
 MyMap.Layers.Add(new GraphicsLayer() { ID = "MyGraphicsLayer"});
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = args.Geometry,
                Symbol = _activeSymbol,
            };
            graphicsLayer.Graphics.Add(graphic);


now i want search this graphics, eg: Draw a retacle, and get all points  in this area. i will use:FindGraphicsInHostCoordinates ??
0 Kudos
DanielWalton
Frequent Contributor
Take a look at the Draw sample that Jennifer posted. In the method Draw_Complete(), you have access to a graphic object that represents the shape you just drew. You can use this shape to interrogate the features in any other graphicslayer. Here's a useful bit of code for doing that (taken from the ESRI Contrib project😞
        public static bool IsPointInPolygon( PointCollection points, MapPoint point )
        {
            int i;
            int j = points.Count - 1;
            bool inPoly = false;

            for( i = 0; i < points.Count; i++ )
            {
                if( points[ i ].X < point.X && points[ j ].X >= point.X
                  || points[ j ].X < point.X && points[ i ].X >= point.X )
                {
                    if( points[ i ].Y + ( point.X - points[ i ].X ) / ( points[ j ].X - points[ i ].X ) * ( points[ j ].Y - points[ i ].Y ) < point.Y )
                    {
                        inPoly = !inPoly;
                    }
                }
                j = i;
            }
            return inPoly;
        }


You can call Graphic.Select() or whatever on any graphics objects that fall inside the shape.
0 Kudos
JenniferNery
Esri Regular Contributor
If you want to select graphics by drawing a rectangle around them, you can use the Editor.Select command. Try the "New Selection" button in this SDK Sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave. This also works for GraphicsLayer. Note, however that the Symbol you use need to define SelectionStates to be able to distinguish between Selected and Unselected states as in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics.

And yes, another way is to use FindGraphicsInHostCoordinates http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.GraphicsLa... to return you the graphics contained in the rectangle.
0 Kudos