Ejemplo n.º 1
0
        private void MarkerSymbols_QueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
        {
            //Create centroid for all US States
            FeatureSet featureSet = e.FeatureSet;

            GraphicsLayer graphicsLayer = null; // layerDemo6.Layer as GraphicsLayer;

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in featureSet.Features)
                {
                    ESRI.ArcGIS.Client.Geometry.Polygon polygon = feature.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                    if (polygon == null)
                    {
                        return;
                    }
                    polygon.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326);

                    Graphic graphic;
                    //Getting the center point of the polygon MBR:
                    ESRI.ArcGIS.Client.Geometry.MapPoint featureCentroid = feature.Geometry.Extent.GetCenter();
                    bool pointInPolygon = featureCentroid.IsWithin(polygon);
                    if (pointInPolygon)
                    {
                        graphic = new Graphic()
                        {
                            Geometry = featureCentroid,
                        };
                    }
                    else
                    {
                        graphic = new Graphic()
                        {
                            Geometry = polygon,
                            Symbol   = null
                        };
                    }

                    //Assigning attributes from the feature to the graphic:
                    foreach (string key in feature.Attributes.Keys)
                    {
                        //for (int i = 0; i < pieChartMarkerSymbol.Fields.Count; i++)
                        //{
                        //    if (pieChartMarkerSymbol.Fields[i].FieldName == key)
                        //        graphic.Attributes.Add(key, feature.Attributes[key]);
                        //}
                    }
                    graphicsLayer.Graphics.Add(graphic);

                    //Using the geometry service to find a new centroid in the case the
                    //calculated centroid is not inside of the polygon:
                    if (!pointInPolygon)
                    {
                        GeometryService geometryService = new GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
                        List <Graphic>  graphicsList    = new List <Graphic>();
                        graphicsList.Add(graphic);
                        geometryService.LabelPointsCompleted += MarkerSymbols_GeometryService_LabelPointsCompleted;
                        geometryService.LabelPointsAsync(graphicsList);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static bool Contains(this ESRI.ArcGIS.Client.Geometry.Polygon polygon, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint)
 {
     return(mapPoint.IsWithin(polygon));
 }