private async void mapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                incidentOverlay.Visibility = Visibility.Collapsed;
                incidentOverlay.DataContext = null;

                var identifyTask = new IdentifyTask(new Uri(_trafficLayer.ServiceUri));

                IdentifyParameter identifyParams = new IdentifyParameter(e.Location, mapView.Extent, 5, (int)mapView.ActualHeight, (int)mapView.ActualWidth)
                {
                    LayerIDs = new int[] { 2, 3, 4 },
                    LayerOption = LayerOption.Top,
                    SpatialReference = mapView.SpatialReference,
                };

                var result = await identifyTask.ExecuteAsync(identifyParams);

                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    incidentOverlay.DataContext = result.Results.First();
                    incidentOverlay.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Identify Error");
            }
        }
        private async void mapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                incidentOverlay.Visibility  = Visibility.Collapsed;
                incidentOverlay.DataContext = null;

                var identifyTask = new IdentifyTask(new Uri(_trafficLayer.ServiceUri));

                IdentifyParameter identifyParams = new IdentifyParameter(e.Location, mapView.Extent, 5, (int)mapView.ActualHeight, (int)mapView.ActualWidth)
                {
                    LayerIDs         = new int[] { 2, 3, 4 },
                    LayerOption      = LayerOption.Top,
                    SpatialReference = mapView.SpatialReference,
                };

                var result = await identifyTask.ExecuteAsync(identifyParams);

                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    incidentOverlay.DataContext = result.Results.First();
                    incidentOverlay.Visibility  = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Identify Error");
            }
        }
        // Identify features at the click point
        private async void mapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;
                resultsGrid.DataContext = null;

                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.Add(new Graphic(e.Location));

                IdentifyParameter identifyParams = new IdentifyParameter(e.Location, mapView.Extent, 2, (int)mapView.ActualHeight, (int)mapView.ActualWidth)
                {
                    LayerOption = LayerOption.Visible,
                    SpatialReference = mapView.SpatialReference,
                };

                IdentifyTask identifyTask = new IdentifyTask(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));

                var result = await identifyTask.ExecuteAsync(identifyParams);

                resultsGrid.DataContext = result.Results;
                if (result != null && result.Results != null && result.Results.Count > 0)
                    titleComboBox.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Identify Sample");
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        private async Task RunIdentify(MapPoint mp)
        {
            IdentifyParameter identifyParams = new IdentifyParameter(mp, mapView1.Extent, 2, (int)mapView1.ActualHeight, (int)mapView1.ActualWidth)
            {
                LayerOption      = LayerOption.Visible,
                SpatialReference = mapView1.SpatialReference,
            };

            IdentifyTask identifyTask = new IdentifyTask(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                                                                 "Demographics/ESRI_Census_USA/MapServer"));

            progress.IsActive = true;

            try
            {
                TitleComboBox.ItemsSource = null;
                ResultsGrid.ItemsSource   = null;
                var result = await identifyTask.ExecuteAsync(identifyParams);

                GraphicsLayer graphicsLayer = mapView1.Map.Layers["MyGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.Add(new Graphic()
                {
                    Geometry = mp
                });

                var _dataItems = new List <DataItem>();
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    foreach (var r in result.Results)
                    {
                        Feature feature = r.Feature;
                        string  title   = r.Value.ToString() + " (" + r.LayerName + ")";
                        _dataItems.Add(new DataItem()
                        {
                            Title = title,
                            Data  = feature.Attributes
                        });
                    }
                }
                TitleComboBox.ItemsSource = _dataItems;
                if (_dataItems.Count > 0)
                {
                    TitleComboBox.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                progress.IsActive = false;
            }
        }
        private async Task RunIdentify(MapPoint mp)
        {
            IdentifyParameter identifyParams = new IdentifyParameter()
            {
                Geometry = mp,
                MapExtent = MyMap.Extent,
                Width = (int)MyMap.ActualWidth,
                Height = (int)MyMap.ActualHeight,
                LayerOption = LayerOption.Visible,
                SpatialReference = MyMap.SpatialReference,
                Tolerance = 2
            };

            IdentifyTask identifyTask = new IdentifyTask(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                "Demographics/ESRI_Census_USA/MapServer"));
            progress.IsActive = true;

            try
            {
                var result = await identifyTask.ExecuteAsync(identifyParams);

                GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.Add(new Graphic() { Geometry = mp });

                var _dataItems = new List<DataItem>();
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    foreach (var r in result.Results)
                    {
                        Graphic feature = r.Feature;
                        string title = r.Value.ToString() + " (" + r.LayerName + ")";
                        _dataItems.Add(new DataItem()
                        {
                            Title = title,
                            Data = feature.Attributes
                        });
                    }
                }
                TitleComboBox.ItemsSource = _dataItems;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                progress.IsActive = false;
            }
        }
        // Performs the identify operation and returns the results as DataItems
        private async Task <List <DataItem> > doIdentifyAsync(MapPoint point)
        {
            // Initialize paraemters for the identify operation
            IdentifyParameter identifyParams = new IdentifyParameter(point, m_mapView.Extent, 2,
                                                                     (int)m_mapView.ActualHeight, (int)m_mapView.ActualWidth)
            {
                SpatialReference = m_mapView.SpatialReference,
                ReturnGeometry   = true
            };

            // Initialize the identify task with the service to identify features from
            IdentifyTask identifyTask = new IdentifyTask(new Uri(
                                                             "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));
            var dataItems = new List <DataItem>();

            try
            {
                // Do the identify operation
                var result = await identifyTask.ExecuteAsync(identifyParams);

                // Create DataItems that encapsulate each result
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    foreach (var r in result.Results)
                    {
                        dataItems.Add(new DataItem()
                        {
                            Title      = string.Format("{0} ({1})", r.Value, r.LayerName),
                            Attributes = r.Feature.Attributes,
                            Geometry   = r.Feature.Geometry
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            // Return the results as DataItems
            return(dataItems);
        }
Пример #7
0
        private async void mapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility     = Visibility.Visible;
                resultsGrid.DataContext = null;

                GraphicsLayer graphicsLayer = mapView.Map.Layers["GraphicsLayer"] as GraphicsLayer;
                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.Add(new Graphic(e.Location));

                IdentifyParameter identifyParams = new IdentifyParameter(e.Location, mapView.Extent, 2, (int)mapView.ActualHeight, (int)mapView.ActualWidth)
                {
                    LayerOption      = LayerOption.Visible,
                    SpatialReference = mapView.SpatialReference,
                };

                IdentifyTask identifyTask = new IdentifyTask(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));

                var result = await identifyTask.ExecuteAsync(identifyParams);

                resultsGrid.DataContext = result.Results;
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    titleComboBox.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        // Performs the identify operation and returns the results as DataItems
        private async Task<List<DataItem>> doIdentifyAsync(MapPoint point)
        {
            // Initialize paraemters for the identify operation
            IdentifyParameter identifyParams = new IdentifyParameter(point, m_mapView.Extent, 2, 
                (int)m_mapView.ActualHeight, (int)m_mapView.ActualWidth)
            {
                SpatialReference = m_mapView.SpatialReference,
                ReturnGeometry = true
            };

            // Initialize the identify task with the service to identify features from
            IdentifyTask identifyTask = new IdentifyTask(new Uri(
                "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));
            var dataItems = new List<DataItem>();

            try
            {
                // Do the identify operation
                var result = await identifyTask.ExecuteAsync(identifyParams);

                // Create DataItems that encapsulate each result
                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    foreach (var r in result.Results)
                    {
                        dataItems.Add(new DataItem()
                        {
                            Title = string.Format("{0} ({1})", r.Value, r.LayerName),
                            Attributes = r.Feature.Attributes,
                            Geometry = r.Feature.Geometry
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            // Return the results as DataItems
            return dataItems;
        }
Пример #9
0
        private static async Task <KeyValuePair <Layer, IEnumerable <IdentifyFeature> > > IdentifyLayer(MapViewController controller, Layer layer, Point tapPoint, MapPoint mapPoint)
        {
            if (layer is ArcGISDynamicMapServiceLayer)
            {
                var dynamicLayer = ((ArcGISDynamicMapServiceLayer)layer);

                if (!dynamicLayer.ServiceInfo.Capabilities.Contains("Query"))
                {
                    return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
                }

                var identifyTask = new IdentifyTask(new Uri(dynamicLayer.ServiceUri, UriKind.Absolute));

                var resolution = controller.UnitsPerPixel;
                var center     = controller.Extent.GetCenter();
                var extent     = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
                                              center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameter(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                                                              c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
                {
                    LayerOption        = LayerOption.Visible,
                    LayerTimeOptions   = dynamicLayer.LayerTimeOptions,
                    LayerIDs           = dynamicLayer.VisibleLayers,
                    DynamicLayerInfos  = dynamicLayer.DynamicLayerInfos,
                    GeodatabaseVersion = dynamicLayer.GeodatabaseVersion,
                    TimeExtent         = controller.TimeExtent,
                };
                var identifyItems    = (await identifyTask.ExecuteAsync(identifyParameter)).Results;
                var identifyFeatures = new List <IdentifyFeature>();
                foreach (var identifyItem in identifyItems)
                {
                    var fields = await GetFieldInfo(dynamicLayer, identifyItem);

                    var identifyFeature = ReplaceAlaisWithFieldName(identifyItem, fields);
                    identifyFeatures.Add(identifyFeature);
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, identifyFeatures));
            }
            if (layer is ArcGISTiledMapServiceLayer)
            {
                var tiledlayer = ((ArcGISTiledMapServiceLayer)layer);
                if (!tiledlayer.ServiceInfo.Capabilities.Contains("Query"))
                {
                    return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
                }

                var identifyTask = new IdentifyTask(new Uri(tiledlayer.ServiceUri, UriKind.Absolute));
                var resolution   = controller.UnitsPerPixel;
                var center       = controller.Extent.GetCenter();
                var extent       = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
                                                center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameter(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                                                              c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
                {
                    LayerOption = LayerOption.Visible,
                    TimeExtent  = controller.TimeExtent,
                };

                var identifyItems = (await identifyTask.ExecuteAsync(identifyParameter)).Results;

                var identifyFeatures = new List <IdentifyFeature>();
                foreach (var identifyItem in identifyItems)
                {
                    var fields = await GetFieldInfo(tiledlayer, identifyItem);

                    var identifyFeature = ReplaceAlaisWithFieldName(identifyItem, fields);
                    identifyFeatures.Add(identifyFeature);
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, identifyFeatures));
            }
            if (layer is FeatureLayer)
            {
                var featureLayer = ((FeatureLayer)layer);
                var featureIds   = await controller.FeatureLayerHitTestAsync(featureLayer, tapPoint, 1000);

                var features = await featureLayer.FeatureTable.QueryAsync(featureIds);

                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, features.Select(f => new IdentifyFeature(new IdentifyItem(
                                                                                                                                    -1,
                                                                                                                                    featureLayer.DisplayName,
                                                                                                                                    f.Schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name,
                                                                                                                                    f.Attributes[f.Schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name].ToString(),
                                                                                                                                    f
                                                                                                                                    ), f.Schema.Fields))));
            }
            if (layer is GraphicsLayer)
            {
                var graphicsLayer = ((GraphicsLayer)layer);
                var graphics      = await controller.GraphicsLayerHitTestAsync(graphicsLayer, tapPoint, 1000);

                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, graphics.Select(f => new IdentifyFeature(new IdentifyItem(
                                                                                                                                    -1,
                                                                                                                                    layer.DisplayName,
                                                                                                                                    "",
                                                                                                                                    "",
                                                                                                                                    f
                                                                                                                                    )))));
            }

            // Not supported or not implemented yet
            return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
        }