internal static void ShowPopup(Graphic graphic, Layer layer, int? layerId = null)
        {
            OnClickPopupInfo popupInfo = GetPopup(new[]{graphic}, layer, layerId);

            if (graphic.Geometry is MapPoint)
                ShowPopup(popupInfo, (MapPoint)graphic.Geometry);
            else if (graphic.Geometry is Polygon)
            {
                if (!string.IsNullOrEmpty(MapApplication.Current.Urls.GeometryServiceUrl))
                {
                    GeometryService geometryService = new GeometryService(MapApplication.Current.Urls.GeometryServiceUrl);
                    geometryService.LabelPointsCompleted += (s, args) =>
                    {
                        if (args.Results != null && args.Results.Count > 0)
                            ShowPopup(popupInfo, (MapPoint)args.Results[0].Geometry);
                        else
                            ShowPopup(popupInfo, graphic.Geometry);
                    };
                    geometryService.Failed += (s, args) =>
                    {
                        ShowPopup(popupInfo,graphic.Geometry);
                    };
                    geometryService.LabelPointsAsync(new[] { graphic });
                }
                else
                {
                    ShowPopup(popupInfo,graphic.Geometry);
                }
            }
            SyncPreviousDisplayMode(popupInfo);
        }
        internal static void ShowPopup(Graphic graphic, Layer layer, int?layerId = null)
        {
            OnClickPopupInfo popupInfo = GetPopup(new[] { graphic }, layer, layerId);

            if (graphic.Geometry is MapPoint)
            {
                ShowPopup(popupInfo, (MapPoint)graphic.Geometry);
            }
            else if (graphic.Geometry is Polygon)
            {
                if (!string.IsNullOrEmpty(MapApplication.Current.Urls.GeometryServiceUrl))
                {
                    GeometryService geometryService = new GeometryService(MapApplication.Current.Urls.GeometryServiceUrl);
                    geometryService.LabelPointsCompleted += (s, args) =>
                    {
                        if (args.Results != null && args.Results.Count > 0)
                        {
                            ShowPopup(popupInfo, (MapPoint)args.Results[0].Geometry);
                        }
                        else
                        {
                            ShowPopup(popupInfo, graphic.Geometry);
                        }
                    };
                    geometryService.Failed += (s, args) =>
                    {
                        ShowPopup(popupInfo, graphic.Geometry);
                    };
                    geometryService.LabelPointsAsync(new[] { graphic });
                }
                else
                {
                    ShowPopup(popupInfo, graphic.Geometry);
                }
            }
            SyncPreviousDisplayMode(popupInfo);
        }
 void GeometryService_SimplifyCompleted(object sender, GraphicsEventArgs e)
 {
     geometryService.LabelPointsAsync(e.Results);
 }
예제 #4
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);
                    }
                }
            }
        }