Beispiel #1
0
        private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry         = clickPoint,
                MapExtent        = MyMap.Extent,
                Width            = (int)MyMap.ActualWidth,
                Height           = (int)MyMap.ActualHeight,
                LayerOption      = LayerOption.visible,
                SpatialReference = MyMap.SpatialReference
            };



            //IdentifyTask identifyTask = new IdentifyTask("http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Average_Household_Size/MapServer/");
            IdentifyTask identifyTask = new IdentifyTask(arcgisLayer.Url);


            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed           += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = clickPoint,
                Symbol   = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);
        }
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                _trafficOverlay.Visibility  = Visibility.Collapsed;
                _trafficOverlay.DataContext = null;

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

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

                var result = await identifyTask.ExecuteAsync(identifyParams);

                if (result != null && result.Results != null && result.Results.Count > 0)
                {
                    _trafficOverlay.DataContext = result.Results.First();
                    _trafficOverlay.Visibility  = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
		private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
		{
			try
			{
				_trafficOverlay.Visibility = Visibility.Collapsed;
				_trafficOverlay.DataContext = null;

				var identifyTask = new IdentifyTask(new Uri(_trafficLayer.ServiceUri));
				// Get current viewpoints extent from the MapView
				var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
				var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

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

				var result = await identifyTask.ExecuteAsync(identifyParams);

				if (result != null && result.Results != null && result.Results.Count > 0)
				{
					_trafficOverlay.DataContext = result.Results.First();
					_trafficOverlay.Visibility = Visibility.Visible;
				}
			}
			catch (Exception ex)
			{
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
		}
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                incidentOverlay.Visibility = Visibility.Collapsed;
                incidentOverlay.DataContext = null;

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

                IdentifyParameters identifyParams = new IdentifyParameters(e.Location, MyMapView.Extent, 5, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
                {
                    LayerIDs = new int[] { 2, 3, 4 },
                    LayerOption = LayerOption.Top,
                    SpatialReference = MyMapView.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");
            }
        }
Beispiel #5
0
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.Geometry as MapPoint;

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                SpatialReference = MyMap.SpatialReference,
                Geometry         = clickPoint,
                MapExtent        = MyMap.Extent,
                Width            = (int)MyMap.ActualWidth,
                Height           = (int)MyMap.ActualHeight,
                LayerOption      = LayerOption.visible
            };

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

            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed           += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = clickPoint,
                Symbol   = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);
        }
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                incidentOverlay.Visibility  = Visibility.Collapsed;
                incidentOverlay.DataContext = null;

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

                // Get current viewpoints extent from the MapView
                var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;

                IdentifyParameters identifyParams = new IdentifyParameters(e.Location, viewpointExtent, 5, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
                {
                    LayerIDs         = new int[] { 2, 3, 4 },
                    LayerOption      = LayerOption.Top,
                    SpatialReference = MyMapView.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 MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;
                resultsGrid.DataContext = null;

				GraphicsOverlay graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
				graphicsOverlay.Graphics.Clear();
				graphicsOverlay.Graphics.Add(new Graphic(e.Location));

                IdentifyParameters identifyParams = new IdentifyParameters(e.Location, MyMapView.Extent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
                {
                    LayerOption = LayerOption.Visible,
                    SpatialReference = MyMapView.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;
            }
        }
Beispiel #8
0
        private async Task RunIdentify(MapPoint mp)
        {
            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;
            IdentifyParameters identifyParams = new IdentifyParameters(mp, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
            {
                LayerOption      = LayerOption.Visible,
                SpatialReference = MyMapView.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 = MyMapView.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;
            }
        }
Beispiel #9
0
        private async Task RunIdentify(MapPoint mp)
        {
            IdentifyParameters identifyParams = new IdentifyParameters(mp, mapView1.Extent, 2, (int)mapView1.ActualHeight, (int)mapView1.ActualWidth)
            {
                LayerOption      = LayerOption.Visible,
                SpatialReference = mapView1.SpatialReference,
            };

            IdentifyTask identifyTask = new IdentifyTask(new Uri("http://54.187.22.10:6080/arcgis/rest/services/" +
                                                                 "Resultados_presidenciales/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;
            }
        }
        /// <summary>
        /// Identifies feature to highlight.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            // Ignore tap events while in edit mode so we do not interfere with edit geometry.
            var inEditMode = EditButton.IsEnabled;

            if (inEditMode)
            {
                return;
            }

            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;

            var layer     = MyMapView.Map.Layers["RecreationalArea"] as ArcGISDynamicMapServiceLayer;
            var task      = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint  = MyMapView.ScreenToLocation(e.Position);
            var parameter = new IdentifyParameters(mapPoint, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;

            overlay.Graphics.Clear();

            SetGeometryEditor();

            string message = null;

            try
            {
                // Performs an identify and adds feature result as selected into overlay.
                var result = await task.ExecuteAsync(parameter);

                if (result == null || result.Results == null || result.Results.Count < 1)
                {
                    return;
                }
                var graphic = (Graphic)result.Results[0].Feature;
                graphic.IsSelected = true;
                overlay.Graphics.Add(graphic);

                // Prepares geometry editor.
                var featureID = Convert.ToInt64(graphic.Attributes["Objectid"], CultureInfo.InvariantCulture);
                SetGeometryEditor(featureID);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                await new MessageDialog(message).ShowAsync();
            }
        }
        /// <summary>
        /// Identifies graphic to highlight and query its related records.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            var layer    = MyMapView.Map.Layers["ServiceRequests"] as ArcGISDynamicMapServiceLayer;
            var task     = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint = MyMapView.ScreenToLocation(e.Position);

            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;

            var parameter = new IdentifyParameters(mapPoint, viewpointExtent, 5, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;

            overlay.Graphics.Clear();

            SetRelatedRecordEditor();

            string message = null;

            try
            {
                // Performs an identify and adds graphic result into overlay.
                var result = await task.ExecuteAsync(parameter);

                if (result == null || result.Results == null || result.Results.Count < 1)
                {
                    return;
                }
                var graphic = (Graphic)result.Results[0].Feature;
                overlay.Graphics.Add(graphic);

                // Prepares related records editor.
                var    featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
                string requestID = null;
                if (graphic.Attributes["Service Request ID"] != null)
                {
                    requestID = Convert.ToString(graphic.Attributes["Service Request ID"], CultureInfo.InvariantCulture);
                }
                SetRelatedRecordEditor(featureID, requestID);

                await QueryRelatedRecordsAsync();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(message);
            }
        }
		private async Task RunIdentify(MapPoint mp)
		{
			// Get current viewpoints extent from the MapView
			var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
			var viewpointExtent = currentViewpoint.TargetGeometry.Extent;
			IdentifyParameters identifyParams = new IdentifyParameters(mp, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
			{
				LayerOption = LayerOption.Visible,
				SpatialReference = MyMapView.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 = MyMapView.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;
			}
		}
Beispiel #13
0
        /// <summary>
        /// Identifies feature to highlight.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            var layer    = MyMapView.Map.Layers["PoolPermit"] as ArcGISDynamicMapServiceLayer;
            var task     = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint = MyMapView.ScreenToLocation(e.Position);

            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;
            var parameter        = new IdentifyParameters(mapPoint, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;

            overlay.Graphics.Clear();

            SetAttributeEditor();

            string message = null;

            try
            {
                // Performs an identify and adds feature result as selected into overlay.
                var result = await task.ExecuteAsync(parameter);

                if (result == null || result.Results == null || result.Results.Count < 1)
                {
                    return;
                }
                var graphic = (Graphic)result.Results[0].Feature;
                graphic.IsSelected = true;
                overlay.Graphics.Add(graphic);

                // Prepares attribute editor.
                var featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
                var hasPool   = Convert.ToString(graphic.Attributes["Has_Pool"], CultureInfo.InvariantCulture);
                if (choices == null)
                {
                    choices = await GetChoicesAsync();
                }
                SetAttributeEditor(featureID, hasPool);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                await new MessageDialog(message).ShowAsync();
            }
        }
Beispiel #14
0
        /// <summary>
        /// Identifies feature to highlight.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            // Ignore tap events while in edit mode so we do not interfere with edit geometry.
            if (MyMapView.Editor.IsActive)
            {
                return;
            }

            var layer     = MyMapView.Map.Layers["WildFire"] as ArcGISDynamicMapServiceLayer;
            var task      = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint  = MyMapView.ScreenToLocation(e.Position);
            var parameter = new IdentifyParameters(mapPoint, MyMapView.Extent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;

            overlay.Graphics.Clear();

            SetGeometryEditor();

            string message = null;

            try
            {
                // Performs an identify and adds feature result as selected into overlay.
                var result = await task.ExecuteAsync(parameter);

                if (result == null || result.Results == null || result.Results.Count < 1)
                {
                    return;
                }
                var graphic = (Graphic)result.Results[0].Feature;
                graphic.IsSelected = true;
                overlay.Graphics.Add(graphic);

                // Prepares geometry editor.
                var featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
                SetGeometryEditor(featureID);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(message);
            }
        }
		/// <summary>
		/// Identifies feature to highlight.
		/// </summary>
		private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
		{
			// Ignore tap events while in edit mode so we do not interfere with edit geometry.
			var inEditMode = EditButton.IsEnabled;
			if (inEditMode)
				return;

			// Get current viewpoints extent from the MapView
			var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
			var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

			var layer = MyMapView.Map.Layers["RecreationalArea"] as ArcGISDynamicMapServiceLayer;
			var task = new IdentifyTask(new Uri(layer.ServiceUri));
			var mapPoint = MyMapView.ScreenToLocation(e.Position);
			var parameter = new IdentifyParameters(mapPoint, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

			// Clears map of any highlights.
			var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
			overlay.Graphics.Clear();

			SetGeometryEditor();

			string message = null;
			try
			{
				// Performs an identify and adds feature result as selected into overlay.
				var result = await task.ExecuteAsync(parameter);
				if (result == null || result.Results == null || result.Results.Count < 1)
					return;
				var graphic = (Graphic)result.Results[0].Feature;
				graphic.IsSelected = true;
				overlay.Graphics.Add(graphic);

				// Prepares geometry editor.
				var featureID = Convert.ToInt64(graphic.Attributes["Objectid"], CultureInfo.InvariantCulture);
				SetGeometryEditor(featureID);
			}
			catch (Exception ex)
			{
				message = ex.Message;
			}
			if (!string.IsNullOrWhiteSpace(message))
				await new MessageDialog(message).ShowAsync();
		}
        /// <summary>
        /// Identifies graphic to highlight and query its related records.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            var layer = MyMapView.Map.Layers["ServiceRequests"] as ArcGISDynamicMapServiceLayer;
            var task = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint = MyMapView.ScreenToLocation(e.Position);

            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

            var parameter = new IdentifyParameters(mapPoint, viewpointExtent, 5, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
            overlay.Graphics.Clear();

            SetRelatedRecordEditor();

            string message = null;
            try
            {
                // Performs an identify and adds graphic result into overlay.
                var result = await task.ExecuteAsync(parameter);
                if (result == null || result.Results == null || result.Results.Count < 1)
                    return;
                var graphic = (Graphic)result.Results[0].Feature;
                overlay.Graphics.Add(graphic);

                // Prepares related records editor.
                var featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
                string requestID = null;
                if(graphic.Attributes["Service Request ID"] != null)
                     requestID = Convert.ToString(graphic.Attributes["Service Request ID"], CultureInfo.InvariantCulture);
                SetRelatedRecordEditor(featureID, requestID);

                await QueryRelatedRecordsAsync();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
                MessageBox.Show(message);
        }
Beispiel #17
0
        public Task <IdentifyResult> DoIdentify(string serviceId, string layers, MapPoint pt)
        {
            LayerObject lo = null;

            foreach (var t in ConfigUtil.DynamicLayer)
            {
                if (serviceId != t.Id)
                {
                    continue;
                }
                lo = t;
            }
            if (lo == null)
            {
                return(null);
            }

            //创建查询IdentifyTask
            IdentifyTask task = new IdentifyTask(lo.Uri);


            if (lo.Token != null)
            {
                task.Token = lo.Token;
            }

            //设置查询参数
            var queryPara = new IdentifyParameters(pt, Map.MapView.Extent, 7
                                                   , (int)Map.MapView.ActualHeight, (int)Map.MapView.ActualWidth)
            {
                LayerOption = LayerOption.Visible
            };

            var layerArr = layers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var ids = (from layer in layerArr select lo.GetLayerId(layer) into layerId where layerId != null select(int) layerId).ToList();

            queryPara.LayerIDs = ids;

            queryPara.SpatialReference = Map.MapView.SpatialReference;
            return(task.ExecuteAsync(queryPara));
        }
		/// <summary>
		/// Identifies feature to highlight.
		/// </summary>
		private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
		{
			var layer = MyMapView.Map.Layers["PoolPermit"] as ArcGISDynamicMapServiceLayer;
			var task = new IdentifyTask(new Uri(layer.ServiceUri));
			var mapPoint = MyMapView.ScreenToLocation(e.Position);
            
            // Get current viewpoints extent from the MapView
            var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
            var viewpointExtent = currentViewpoint.TargetGeometry.Extent;
			var parameter = new IdentifyParameters(mapPoint, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

			// Clears map of any highlights.
			var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
			overlay.Graphics.Clear();

			SetAttributeEditor();

			string message = null;
			try
			{
				// Performs an identify and adds feature result as selected into overlay.
				var result = await task.ExecuteAsync(parameter);
				if (result == null || result.Results == null || result.Results.Count < 1)
					return;
				var graphic = (Graphic)result.Results[0].Feature;
				graphic.IsSelected = true;
				overlay.Graphics.Add(graphic);

				// Prepares attribute editor.
				var featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
				var hasPool = Convert.ToString(graphic.Attributes["Has_Pool"], CultureInfo.InvariantCulture);
				if (choices == null)
					choices = await GetChoicesAsync();
				SetAttributeEditor(featureID, hasPool);
			}
			catch (Exception ex)
			{
				message = ex.Message;
			}
			if (!string.IsNullOrWhiteSpace(message))
				await new MessageDialog(message).ShowAsync();
		}
Beispiel #19
0
        // Identify features at the click point
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility     = Visibility.Visible;
                resultsGrid.DataContext = null;

                GraphicsOverlay graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
                graphicsOverlay.Graphics.Clear();
                graphicsOverlay.Graphics.Add(new Graphic(e.Location));

                // Get current viewpoints extent from the MapView
                var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;

                IdentifyParameters identifyParams = new IdentifyParameters(e.Location, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
                {
                    LayerOption      = LayerOption.Visible,
                    SpatialReference = MyMapView.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;
            }
        }
Beispiel #20
0
        private void DoIdentification(MapPoint point)
        {
            IdentifyParameters identifyParams = new IdentifyParameters();

            identifyParams.LayerOption      = (LayerOption)Enum.Parse(typeof(LayerOption), widgetConfig.IdentifyOption, true);
            identifyParams.Tolerance        = widgetConfig.Tolerance;
            identifyParams.MapExtent        = this.MapControl.Extent;
            identifyParams.Height           = (int)this.MapControl.ActualHeight;
            identifyParams.Width            = (int)this.MapControl.ActualWidth;
            identifyParams.SpatialReference = new SpatialReference(this.MapSRWKID);
            identifyParams.ReturnGeometry   = true;
            identifyParams.Geometry         = point;

            this.IsBusy = true;
            this.ClearGraphics(0);

            for (int i = 0; i < widgetConfig.IdentifyLayers.Length; i++)
            {
                LivingMapLayer livingMapConfig = GetLivingMapConfig(widgetConfig.IdentifyLayers[i].Title);

                if (livingMapConfig != null && !string.IsNullOrEmpty(livingMapConfig.RESTURL))
                {
                    identifyParams.LayerIds.Clear();

                    int[] doLayers = GetIdentifiableLayers(livingMapConfig.ID, widgetConfig.IdentifyLayers[i].LayerIDs);
                    foreach (int kk in doLayers)
                    {
                        identifyParams.LayerIds.Add(kk);
                    }

                    IdentifyTask identifyTask = new IdentifyTask(livingMapConfig.RESTURL);
                    identifyTask.ExecuteCompleted += new EventHandler <IdentifyEventArgs>(IdentifyTask_ExecuteCompleted);
                    identifyTask.Failed           += new EventHandler <TaskFailedEventArgs>(IdentifyTask_Failed);
                    identifyTask.Token             = (livingMapConfig.Token == null) ? "" : livingMapConfig.Token;
                    identifyTask.ProxyURL          = livingMapConfig.ProxyURL;
                    identifyTask.ExecuteAsync(identifyParams, livingMapConfig.Title);
                }
            }
        }
        /// <summary>
        /// Identifies feature to highlight.
        /// </summary>
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            // Ignore tap events while in edit mode so we do not interfere with edit geometry.
            if (MyMapView.Editor.IsActive)
                return;

            var layer = MyMapView.Map.Layers["WildFire"] as ArcGISDynamicMapServiceLayer;
            var task = new IdentifyTask(new Uri(layer.ServiceUri));
            var mapPoint = MyMapView.ScreenToLocation(e.Position);
            var parameter = new IdentifyParameters(mapPoint, MyMapView.Extent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth);

            // Clears map of any highlights.
            var overlay = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
            overlay.Graphics.Clear();

            SetGeometryEditor();

            string message = null;
            try
            {
                // Performs an identify and adds feature result as selected into overlay.
                var result = await task.ExecuteAsync(parameter);
                if (result == null || result.Results == null || result.Results.Count < 1)
                    return;
                var graphic = (Graphic)result.Results[0].Feature;
                graphic.IsSelected = true;
                overlay.Graphics.Add(graphic);

                // Prepares geometry editor.
                var featureID = Convert.ToInt64(graphic.Attributes["OBJECTID"], CultureInfo.InvariantCulture);
                SetGeometryEditor(featureID);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (!string.IsNullOrWhiteSpace(message))
                MessageBox.Show(message);
        }
		private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
		{
			try
			{
				progress.Visibility = Visibility.Visible;
				resultsGrid.DataContext = null;

				GraphicsOverlay graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
				graphicsOverlay.Graphics.Clear();
				graphicsOverlay.Graphics.Add(new Graphic(e.Location));

				// Get current viewpoints extent from the MapView
				var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
				var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

				IdentifyParameters identifyParams = new IdentifyParameters(e.Location, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
				{
					LayerOption = LayerOption.Visible,
					SpatialReference = MyMapView.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 _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
			finally
			{
				progress.Visibility = Visibility.Collapsed;
			}
		}
        private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility     = Visibility.Visible;
                resultsGrid.DataContext = null;

                GraphicsOverlay graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
                graphicsOverlay.Graphics.Clear();
                graphicsOverlay.Graphics.Add(new Graphic(e.Location));

                IdentifyParameters identifyParams = new IdentifyParameters(e.Location, MyMapView.Extent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
                {
                    LayerOption      = LayerOption.Visible,
                    SpatialReference = MyMapView.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 _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        private void MyMap_MapGesture(object sender, Map.MapGestureEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;

            if (_displayViewshedInfo && resultLayer != null && e.Gesture == GestureType.Tap)
            {
                ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                {
                    Geometry         = mapPoint,
                    MapExtent        = MyMap.Extent,
                    Width            = (int)MyMap.ActualWidth,
                    Height           = (int)MyMap.ActualHeight,
                    LayerOption      = LayerOption.visible,
                    SpatialReference = MyMap.SpatialReference
                };

                IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
                identifyTask.ExecuteCompleted += (s, ie) =>
                {
                    if (ie.IdentifyResults.Count > 0)
                    {
                        foreach (var identifyresult in ie.IdentifyResults)
                        {
                            if (identifyresult.LayerId == 1)
                            {
                                Graphic g = identifyresult.Feature;
                                MyInfoWindow.Anchor  = e.MapPoint;
                                MyInfoWindow.Content = g.Attributes;
                                MyInfoWindow.IsOpen  = true;
                                break;
                            }
                        }
                    }
                };
                identifyTask.ExecuteAsync(identifyParams);
            }
        }
        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 IdentifyParameters(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>();

                try
                {
                    var dict = new Dictionary<int, IReadOnlyList<FieldInfo>>();
                    foreach (var identifyItem in identifyItems)
                    {
                        IReadOnlyList<FieldInfo> fields;
                        if(dict.ContainsKey(identifyItem.LayerID))
                            fields = dict[identifyItem.LayerID];
                        else
                        {
                            fields = await GetFieldInfo(dynamicLayer, identifyItem);                            
                            dict[identifyItem.LayerID] = fields;
                        }                        
                        var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);                        
                        identifyFeatures.Add(identifyFeature);
                    }

                }
                catch (Exception ex)
                {
                    
                    throw;
                }
                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 IdentifyParameters(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>();
                var dict = new Dictionary<int, IReadOnlyList<FieldInfo>>();
                foreach (var identifyItem in identifyItems)
                {
                    IReadOnlyList<FieldInfo> fields;
                    if (dict.ContainsKey(identifyItem.LayerID))
                        fields = dict[identifyItem.LayerID];
                    else
                    {
                        fields = await GetFieldInfo(tiledlayer, identifyItem);
                        dict[identifyItem.LayerID] = fields;
                    }
                    var identifyFeature = ReplaceAliasWithFieldName(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);
                IEnumerable<Feature> features = new List<Feature>();
                if (featureIds != null && featureIds.Any())
                    features = await featureLayer.FeatureTable.QueryAsync(featureIds);

                var schema = featureLayer.FeatureTable.Schema;
                IList<IdentifyFeature> displayFeatures = new List<IdentifyFeature>();
                foreach (var f in features)
                {
                    var objectIDFieldName = schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name;
                    var objectIDFieldValue = f.Attributes[objectIDFieldName].ToString();
                    IdentifyItem identifyItem = new IdentifyItem(-1, featureLayer.DisplayName, objectIDFieldName, objectIDFieldValue, f);
                    IdentifyFeature identifyFeature = new IdentifyFeature(identifyItem, schema.Fields);
                    displayFeatures.Add(identifyFeature);
                }
                return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, displayFeatures);
            }
            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);
        }
Beispiel #26
0
        private void myMap_MouseClick(object sender, Map.MouseEventArgs args)
        {
            if (activateIdentify == true)
            {

                GraphicsLayer graphicsLayer = myMap.Layers["identifyIconGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();
                ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
                {
                    Geometry = args.MapPoint,
                    Symbol = LayoutRoot.Resources["identifyLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
                };
                // Add the identify graphic
                graphicsLayer.Graphics.Add(graphic);

                IdentifyTask identifyTask = new IdentifyTask("http://unibeast/ArcGIS/rest/services/InternetVector/MapServer");
                identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                identifyTask.Failed += IdentifyTask_Failed;

                IdentifyParameters identifyParameters = new IdentifyParameters();
                // Search all layers
                identifyParameters.LayerOption = LayerOption.all;

                // Initialize extent of map width and height for identify parameters
                identifyParameters.MapExtent = myMap.Extent;
                identifyParameters.Width = (int)myMap.ActualWidth;
                identifyParameters.Height = (int)myMap.ActualHeight;

                // Identify the point clicked on the map
                identifyParameters.Geometry = args.MapPoint;

                // Execute the identify task
                identifyTask.ExecuteAsync(identifyParameters);
            }
        }
        // Perform Identify when the map is clicked.
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args)
        {
            // Show an icon at the Identify location.
            GraphicsLayer graphicsLayer = MyMap.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = args.MapPoint,
                Symbol = LayoutRoot.Resources["IdentifyLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);

            // Identify task initialization.
            IdentifyTask identifyTask = new IdentifyTask("http://maverick.arcgis.com/ArcGIS/rest/services/World_WGS84/MapServer/");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;

            // Initialize Identify parameters. Specify search of all layers.
            IdentifyParameters identifyParameters = new IdentifyParameters();
            //identifyParameters.LayerOption = LayerOption.all;
            identifyParameters.LayerIds.AddRange(new int[] { 0, 1 });

            // Pass the current Map properties to Identify parameters.
            identifyParameters.MapExtent = MyMap.Extent;
            identifyParameters.Width = (int)MyMap.ActualWidth;
            identifyParameters.Height = (int)MyMap.ActualHeight;

            // Identify features at the click point.
            identifyParameters.Geometry = args.MapPoint;

            identifyTask.ExecuteAsync(identifyParameters);
        }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;
              if (_displayViewshedInfo && resultLayer != null)
              {

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
              Geometry = mapPoint,
              MapExtent = MyMap.Extent,
              Width = (int)MyMap.ActualWidth,
              Height = (int)MyMap.ActualHeight,
              LayerOption = LayerOption.visible,
              SpatialReference = MyMap.SpatialReference
            };

            IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
            identifyTask.ExecuteCompleted += (s, ie) =>
            {
              if (ie.IdentifyResults.Count > 0)
              {
            foreach (var identifyresult in ie.IdentifyResults)
            {
              if (identifyresult.LayerId == 1)
              {
                Graphic g = identifyresult.Feature;
                MyInfoWindow.Anchor = e.MapPoint;
                MyInfoWindow.Content = g.Attributes;
                MyInfoWindow.IsOpen = true;
                break;
              }
            }
              }
            };
            identifyTask.ExecuteAsync(identifyParams);
              }
              else
              {
            _geoprocessorTask.CancelAsync();

            graphicsLayer.ClearGraphics();

            mapPoint.SpatialReference = new SpatialReference(102100);

            Graphic graphic = new Graphic()
            {
              Symbol = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
              Geometry = mapPoint
            };
            graphicsLayer.Graphics.Add(graphic);

            MyMap.Cursor = System.Windows.Input.Cursors.Wait;

            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPFeatureRecordSetLayer("Input_Features", mapPoint));
            parameters.Add(new GPString("Height", HeightTextBox.Text));
            parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));

            _geoprocessorTask.OutputSpatialReference = new SpatialReference(102100);
            _geoprocessorTask.SubmitJobAsync(parameters);
              }
        }
        private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry = clickPoint,
                MapExtent = MyMap.Extent,
                Width = (int)MyMap.ActualWidth,
                Height = (int)MyMap.ActualHeight,
                LayerOption = LayerOption.visible,
                SpatialReference = MyMap.SpatialReference
            };

            IdentifyTask identifyTask = new IdentifyTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                "Demographics/ESRI_Census_USA/MapServer");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = clickPoint,
                Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);
        }
        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]);
                }
            }
        }
Beispiel #31
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 IdentifyParameters(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>();

                try
                {
                    var dict = new Dictionary <int, IReadOnlyList <FieldInfo> >();
                    foreach (var identifyItem in identifyItems)
                    {
                        IReadOnlyList <FieldInfo> fields;
                        if (dict.ContainsKey(identifyItem.LayerID))
                        {
                            fields = dict[identifyItem.LayerID];
                        }
                        else
                        {
                            fields = await GetFieldInfo(dynamicLayer, identifyItem);

                            dict[identifyItem.LayerID] = fields;
                        }
                        var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);
                        identifyFeatures.Add(identifyFeature);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                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 IdentifyParameters(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>();
                var dict             = new Dictionary <int, IReadOnlyList <FieldInfo> >();
                foreach (var identifyItem in identifyItems)
                {
                    IReadOnlyList <FieldInfo> fields;
                    if (dict.ContainsKey(identifyItem.LayerID))
                    {
                        fields = dict[identifyItem.LayerID];
                    }
                    else
                    {
                        fields = await GetFieldInfo(tiledlayer, identifyItem);

                        dict[identifyItem.LayerID] = fields;
                    }
                    var identifyFeature = ReplaceAliasWithFieldName(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);

                IEnumerable <Feature> features = new List <Feature>();
                if (featureIds != null && featureIds.Any())
                {
                    features = await featureLayer.FeatureTable.QueryAsync(featureIds);
                }

                var schema = featureLayer.FeatureTable.Schema;
                IList <IdentifyFeature> displayFeatures = new List <IdentifyFeature>();
                foreach (var f in features)
                {
                    var             objectIDFieldName  = schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name;
                    var             objectIDFieldValue = f.Attributes[objectIDFieldName].ToString();
                    IdentifyItem    identifyItem       = new IdentifyItem(-1, featureLayer.DisplayName, objectIDFieldName, objectIDFieldValue, f);
                    IdentifyFeature identifyFeature    = new IdentifyFeature(identifyItem, schema.Fields);
                    displayFeatures.Add(identifyFeature);
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, displayFeatures));
            }
            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));
        }
        public void IdentifyPoint(Map ParcelMap, ref Configuration config, ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint)
        {
            if (config.IdentifyURL == "")
            return;

              if (config.IdentifyLayerCount == 0)
            return;

              if (config.UseQueryIdentify)
              {
            _dataItems = new List<DataItem>();

            GeometryService geometryServicePointSnap = new GeometryService(config.GeometryServerUrl);
            if (geometryServicePointSnap == null)
              return;

            QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0);

            geometryServicePointSnap.BufferCompleted += GeometryService_IdentifyPointBufferCompleted;
            geometryServicePointSnap.Failed += GeometryService_Failed;
            geometryServicePointSnap.CancelAsync();

            SimpleMarkerSymbol defaultSymbolMarker = new SimpleMarkerSymbol()
            {
              Color = System.Windows.Media.Brushes.Black, Size = 8,
              Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
            };

            Graphic clickGraphic = new Graphic();
            clickGraphic.Symbol = defaultSymbolMarker as ESRI.ArcGIS.Client.Symbols.Symbol;
            clickGraphic.Geometry = clickPoint;

            // Input spatial reference for buffer operation defined by first feature of input geometry array
            clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference;

            // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
            ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters()
            {
              BufferSpatialReference = ParcelMap.SpatialReference,
              OutSpatialReference = ParcelMap.SpatialReference,
              Unit = LinearUnit.Meter,
            };
            bufferParams.Distances.Add(config.SnapTolerance * config.SpatialReferenceUnitsPerMeter);
            bufferParams.Features.Add(clickGraphic);
            geometryServicePointSnap.BufferAsync(bufferParams, queryItem);
              }
              else
              {
            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
              Geometry = clickPoint,
              MapExtent = ParcelMap.Extent,
              Width = (int)ParcelMap.ActualWidth,
              Height = (int)ParcelMap.ActualHeight,
              LayerOption = LayerOption.visible,
              SpatialReference = ParcelMap.SpatialReference
            };

            // For performance, we allow certain layers to be only identified.
            if (config.IdentifyLayerIDs != null)
              foreach (int id in config.IdentifyLayerIDs)
            identifyParams.LayerIds.Add(id);

            IdentifyTask identifyTask = new IdentifyTask(config.IdentifyURL);
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;

            QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0);
            identifyTask.ExecuteAsync(identifyParams, queryItem);
              }
        }
Beispiel #33
0
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;

            if (_displayViewshedInfo && resultLayer != null)
            {
                ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                {
                    Geometry         = mapPoint,
                    MapExtent        = MyMap.Extent,
                    Width            = (int)MyMap.ActualWidth,
                    Height           = (int)MyMap.ActualHeight,
                    LayerOption      = LayerOption.visible,
                    SpatialReference = MyMap.SpatialReference
                };

                IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
                identifyTask.ExecuteCompleted += (s, ie) =>
                {
                    if (ie.IdentifyResults.Count > 0)
                    {
                        foreach (var identifyresult in ie.IdentifyResults)
                        {
                            if (identifyresult.LayerId == 1)
                            {
                                Graphic g = identifyresult.Feature;
                                MyInfoWindow.Anchor  = e.MapPoint;
                                MyInfoWindow.Content = g.Attributes;
                                MyInfoWindow.IsOpen  = true;
                                break;
                            }
                        }
                    }
                };
                identifyTask.ExecuteAsync(identifyParams);
            }
            else
            {
                _geoprocessorTask.CancelAsync();

                graphicsLayer.Graphics.Clear();

                mapPoint.SpatialReference = new SpatialReference(102100);

                Graphic graphic = new Graphic()
                {
                    Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                    Geometry = mapPoint
                };
                graphicsLayer.Graphics.Add(graphic);

                MyMap.Cursor = System.Windows.Input.Cursors.Wait;

                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("Input_Features", mapPoint));
                parameters.Add(new GPString("Height", HeightTextBox.Text));
                parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));


                _geoprocessorTask.OutputSpatialReference = new SpatialReference(102100);
                _geoprocessorTask.SubmitJobAsync(parameters);
            }
        }
        public void IdentifyPoint(Map ParcelMap, ref Configuration config, ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint)
        {
            if (config.IdentifyURL == "")
            {
                return;
            }

            if (config.IdentifyLayerCount == 0)
            {
                return;
            }

            if (config.UseQueryIdentify)
            {
                _dataItems = new List <DataItem>();

                GeometryService geometryServicePointSnap = new GeometryService(config.GeometryServerUrl);
                if (geometryServicePointSnap == null)
                {
                    return;
                }

                QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0);

                geometryServicePointSnap.BufferCompleted += GeometryService_IdentifyPointBufferCompleted;
                geometryServicePointSnap.Failed          += GeometryService_Failed;
                geometryServicePointSnap.CancelAsync();

                SimpleMarkerSymbol defaultSymbolMarker = new SimpleMarkerSymbol()
                {
                    Color = System.Windows.Media.Brushes.Black, Size = 8,
                    Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
                };

                Graphic clickGraphic = new Graphic();
                clickGraphic.Symbol   = defaultSymbolMarker as ESRI.ArcGIS.Client.Symbols.Symbol;
                clickGraphic.Geometry = clickPoint;

                // Input spatial reference for buffer operation defined by first feature of input geometry array
                clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference;

                // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
                ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters()
                {
                    BufferSpatialReference = ParcelMap.SpatialReference,
                    OutSpatialReference    = ParcelMap.SpatialReference,
                    Unit = LinearUnit.Meter,
                };
                bufferParams.Distances.Add(config.SnapTolerance * config.SpatialReferenceUnitsPerMeter);
                bufferParams.Features.Add(clickGraphic);
                geometryServicePointSnap.BufferAsync(bufferParams, queryItem);
            }
            else
            {
                ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                {
                    Geometry         = clickPoint,
                    MapExtent        = ParcelMap.Extent,
                    Width            = (int)ParcelMap.ActualWidth,
                    Height           = (int)ParcelMap.ActualHeight,
                    LayerOption      = LayerOption.visible,
                    SpatialReference = ParcelMap.SpatialReference
                };

                // For performance, we allow certain layers to be only identified.
                if (config.IdentifyLayerIDs != null)
                {
                    foreach (int id in config.IdentifyLayerIDs)
                    {
                        identifyParams.LayerIds.Add(id);
                    }
                }

                IdentifyTask identifyTask = new IdentifyTask(config.IdentifyURL);
                identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                identifyTask.Failed           += IdentifyTask_Failed;

                QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0);
                identifyTask.ExecuteAsync(identifyParams, queryItem);
            }
        }
        private void MyMap_MapGesture(object sender, Map.MapGestureEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;
              if (_displayViewshedInfo && resultLayer != null && e.Gesture == GestureType.Tap)
              {

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
              Geometry = mapPoint,
              MapExtent = MyMap.Extent,
              Width = (int)MyMap.ActualWidth,
              Height = (int)MyMap.ActualHeight,
              LayerOption = LayerOption.visible,
              SpatialReference = MyMap.SpatialReference
            };

            IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
            identifyTask.ExecuteCompleted += (s, ie) =>
            {
              if (ie.IdentifyResults.Count > 0)
              {
            foreach (var identifyresult in ie.IdentifyResults)
            {
              if (identifyresult.LayerId == 1)
              {
                Graphic g = identifyresult.Feature;
                MyInfoWindow.Anchor = e.MapPoint;
                MyInfoWindow.Content = g.Attributes;
                MyInfoWindow.IsOpen = true;
                break;
              }
            }
              }
            };
            identifyTask.ExecuteAsync(identifyParams);
              }
        }
Beispiel #36
0
        }         // public void log(String txt)

        /// <summary>
        /// Fires when the drawing action is complete.
        /// Issues an identify operation using the drawn geometry.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawComplete(object sender, DrawEventArgs e)
        {
            log("VIdentify.DrawComplete");
            var map        = MapApplication.Current.Map;
            var clickPoint = e.Geometry as MapPoint;

            var identifyParams = new IdentifyParameters()
            {
                Geometry         = clickPoint.Clone(),
                MapExtent        = map.Extent.Clone(),
                LayerOption      = LayerOption.visible,
                Tolerance        = 2,          // default = 2
                SpatialReference = map.SpatialReference.Clone(),
                Height           = (int)map.ActualHeight,
                Width            = (int)map.ActualWidth,
                ReturnGeometry   = false
            };

            // get layer url

            /*
             * для линейных слоев иногда ничего не находит
             * Возможно потому, что надо выбирать толеранец поболе?
             * http://rngis.algis.com/ArcGIS/rest/services/mesh/MapServer/identify?geometryType=esriGeometryPoint&geometry=%7b%22x%22%3a8678329.72666139%2c%22y%22%3a6793256.24367089%2c%22spatialReference%22%3a%7b%22wkid%22%3a102100%7d%7d&returnGeometry=true&sr=102100&imageDisplay=0%2c0%2c96&layers=visible&tolerance=2&mapExtent=-7380211.5%2c2988666.0221519%2c12657297%2c12246502.2278481&f=json&
             */
            var lyr = new VLayer(MapApplication.Current.SelectedLayer);

            srvUrl = lyr.getAGSMapServiceUrl();
            if (srvUrl == "")
            {
                log(string.Format("VIdentify.DrawComplete, layer has wrong type [{0}]", lyr.lyrType));
                identifyDialog.DataDisplayTitleBottom.Text =
                    string.Format("Ошибка, выделенный слой [тип {0}] не поддерживает операцию Identify, ", lyr.lyrType);
                return;
            }
            identifyTask.Url      = srvUrl;
            identifyTask.ProxyURL = lyr.proxy;
            //identifyTask.Token = "";
            log(string.Format("VIdentify.DrawComplete, ask [{0}]", srvUrl));

            // clear result window
            DataItems.Clear();
            // say "wait for server..."
            identifyDialog.DataDisplayTitleBottom.Text = "Ждем ответа от сервера...";

            if (identifyTask.IsBusy)
            {
                identifyTask.CancelAsync();
            }
            identifyTask.ExecuteAsync(identifyParams);

            var graphicsLayer = map.Layers["IdentifyResultsLayer"]
                                as GraphicsLayer;

            if (graphicsLayer == null)
            {
                graphicsLayer = createResultsLayer();
                map.Layers.Add(graphicsLayer);
                MapApplication.Current.SelectedLayer = lyr.lyr;
            }
            else
            {
                graphicsLayer.ClearGraphics();
            }

            Graphic graphic = new Graphic()
            {
                Geometry = clickPoint
            };

            graphicsLayer.Graphics.Add(graphic);
        }         // private void DrawComplete(object sender, DrawEventArgs e)