コード例 #1
0
        private void getLayerInfos(Layer layer)
        {
            if (layer == null)
            {
                return;
            }
            string layerUrl = IdentifySupport.GetLayerUrl(layer);

            if (!string.IsNullOrWhiteSpace(layerUrl))
            {
                MapServiceLayerInfoHelper helper = new MapServiceLayerInfoHelper(layerUrl, layer, IdentifySupport.GetLayerProxyUrl(layer));
                helper.GetLayerInfosCompleted += (s, e) =>
                {
                    Collection <LayerInformation> gpResultMapServerLayerInfos = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetGPResultMapServerLayerInfos(layer);
                    Collection <LayerInformation> layerInfos = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetLayerInfos(layer);
                    if (gpResultMapServerLayerInfos != null)
                    {
                        Collection <int> layerIds = new Collection <int>();
                        foreach (LayerInformation layerInfo in layerInfos)
                        {
                            LayerInformation gpResultMapServerLayerInfo = gpResultMapServerLayerInfos.FirstOrDefault(p => p.ID == layerInfo.ID);
                            if (gpResultMapServerLayerInfo != null)
                            {
                                layerInfo.PopUpsEnabled = gpResultMapServerLayerInfo.PopUpsEnabled;
                                if (!string.IsNullOrEmpty(gpResultMapServerLayerInfo.DisplayField))
                                {
                                    layerInfo.DisplayField = gpResultMapServerLayerInfo.DisplayField;
                                }
                                if (layerInfo.PopUpsEnabled)
                                {
                                    layerIds.Add(layerInfo.ID);
                                }

                                foreach (FieldInfo field in layerInfo.Fields)
                                {
                                    FieldInfo gpField = gpResultMapServerLayerInfo.Fields.FirstOrDefault(p => p.Name == field.Name);
                                    if (gpField != null)
                                    {
                                        field.DisplayName     = gpField.DisplayName;
                                        field.VisibleOnMapTip = gpField.VisibleOnMapTip;
                                    }
                                }
                            }
                        }
                        ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIdentifyLayerIds(layer, layerIds);
                    }
                };
                helper.GetLayerInfos(null);
            }
        }
コード例 #2
0
        private void bindToMapServiceLayer(Layer layer)
        {
            if (layer == null)
            {
                return;
            }
            Collection <LayerInformation> layerInfos = LayerExtensions.GetLayerInfos(layer);

            if (layerInfos == null || layerInfos.Count < 1)
            {
                string layerUrl = IdentifySupport.GetLayerUrl(layer);
                if (!string.IsNullOrWhiteSpace(layerUrl))
                {
                    MapServiceLayerInfoHelper helper = new MapServiceLayerInfoHelper(layerUrl, Layer, IdentifySupport.GetLayerProxyUrl(layer));
                    helper.GetLayerInfosCompleted += helper_GetLayerInfosCompleted;
                    helper.GetLayerInfos(null);
                }
            }
            else
            {
                setMapServiceLayerDataContext(layerInfos);
            }
        }
コード例 #3
0
        private void DoIdentify()
        {
            if (Map == null)
            {
                return;
            }

            if (PendingIdentifies > 0 && identifyTasks != null)
            {
                foreach (IdentifyTask task in identifyTasks)
                {
                    task.CancelAsync();
                }
            }
            identifyTasks = new List <IdentifyTask>();
            List <IdentifyParameters> parameters = new List <IdentifyParameters>();
            List <Layer> layers = new List <Layer>();
            List <GraphicsLayerResult> graphicsLayerResults = new List <GraphicsLayerResult>();

            identifyTaskResults = new List <object>();
            IdentifyTask identifyTask;

            _popupInfo = MapApplication.Current.GetPopup(null, null);

            // Watch for property changes on the view model. The one in particular that this event handler is interested
            // in is when the popupitem changes. When this happens we will want to then establish a new event handler for
            // when properties change of the popupitem. In particular, when the Graphic property changes so that we can
            // reconstruct the header value for the popup if the value that changed was the field used to display in the
            // header.
            _popupInfo.PropertyChanged += _popupInfo_PropertyChanged;

            for (int i = Map.Layers.Count - 1; i >= 0; i--)
            {
                Layer layer = Map.Layers[i];
                if (!ESRI.ArcGIS.Client.Extensibility.LayerProperties.GetIsPopupEnabled(layer))
                {
                    continue;
                }
                if (!layer.Visible)
                {
                    continue;
                }
                if (layer is ArcGISDynamicMapServiceLayer || layer is ArcGISTiledMapServiceLayer)
                {
                    Collection <int> layerIds = getIdentifyLayerIds(layer);

                    // If layer is a dynamic map service layer, get layer definitions
                    IEnumerable <LayerDefinition> layerDefinitions = null;
                    IEnumerable <TimeOption>      timeOptions      = null;
                    if (layer is ArcGISDynamicMapServiceLayer)
                    {
                        var dynamicLayer = (ArcGISDynamicMapServiceLayer)layer;
                        if (dynamicLayer.LayerDefinitions != null)
                        {
                            layerDefinitions = dynamicLayer.LayerDefinitions.Where(
                                l => layerIds.Contains(l.LayerID));
                        }

                        if (dynamicLayer.LayerTimeOptions != null)
                        {
                            timeOptions = dynamicLayer.LayerTimeOptions.Where(
                                to => layerIds.Contains(int.Parse(to.LayerId)));
                        }
                        else if (dynamicLayer.TimeExtent != null)
                        {
                            timeOptions = dynamicLayer.Layers.Select(l => new TimeOption()
                            {
                                LayerId = l.ID.ToString(),
                                UseTime = true
                            });
                        }
                    }

                    if ((layer.GetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.LayerInfosProperty) as Collection <LayerInformation>)
                        == null) //require layer infos
                    {
                        continue;
                    }
                    if ((layerIds != null && layerIds.Count > 0))
                    {
                        identifyTask = new IdentifyTask(IdentifySupport.GetLayerUrl(layer));
                        identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                        identifyTask.Failed           += IdentifyTask_Failed;

                        string proxy = IdentifySupport.GetLayerProxyUrl(layer);
                        if (!string.IsNullOrEmpty(proxy))
                        {
                            identifyTask.ProxyURL = proxy;
                        }

                        int width, height;
                        if (!int.TryParse(Map.ActualHeight.ToString(), out height))
                        {
                            height = 100;
                        }
                        if (!int.TryParse(Map.ActualWidth.ToString(), out width))
                        {
                            width = 100;
                        }
                        IdentifyParameters identifyParams = new IdentifyParameters()
                        {
                            Geometry         = clickPoint,
                            MapExtent        = Map.Extent,
                            SpatialReference = Map.SpatialReference,
                            LayerOption      = LayerOption.visible,
                            Width            = width,
                            Height           = height,
                            LayerDefinitions = layerDefinitions,
                            TimeExtent       = AssociatedObject.TimeExtent,
                            TimeOptions      = timeOptions
                        };
                        foreach (int item in layerIds)
                        {
                            identifyParams.LayerIds.Add(item);
                        }
                        identifyTasks.Add(identifyTask);
                        parameters.Add(identifyParams);
                        layers.Add(layer);
                    }
                }
                else if (layer is GraphicsLayer &&
                         ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetPopUpsOnClick(layer as GraphicsLayer))
                {
                    GraphicsLayer         graphicsLayer = layer as GraphicsLayer;
                    GeneralTransform      t             = GetTransformToRoot(Map);
                    IEnumerable <Graphic> selected      = Core.Utility.FindGraphicsInHostCoordinates(graphicsLayer, t.Transform(Map.MapToScreen(clickPoint)));
                    if (selected != null)
                    {
                        List <Graphic> results = new List <Graphic>(selected);
                        if (results.Count > 0)
                        {
                            graphicsLayerResults.Add(new GraphicsLayerResult()
                            {
                                Layer        = graphicsLayer,
                                Results      = results,
                                ClickedPoint = clickPoint
                            });
                        }
                    }
                }
            }
            PendingIdentifies = identifyTasks.Count + graphicsLayerResults.Count;
            if (PendingIdentifies > 0)
            {
                for (int i = 0; i < identifyTasks.Count; i++)
                {
                    identifyTasks[i].ExecuteAsync(parameters[i], new UserState()
                    {
                        ClickedPoint = clickPoint, Layer = layers[i]
                    });
                }
                for (int i = 0; i < graphicsLayerResults.Count; i++)
                {
                    reportResults(graphicsLayerResults[i]);
                }
            }
        }