// Accept user click point and select the underlying target polygon private async Task SelectTargetGeometryAsync() { txtInstruct.Text = "Click to select a target geometry"; _coordinateOverlay.Graphics.Clear(); _targetOverlay.Graphics.Clear(); Graphic graphic = null; while (graphic == null) { var point = await MyMapView.Editor.RequestPointAsync(); graphic = await _graphicsOverlay.HitTestAsync(MyMapView, MyMapView.LocationToScreen(point)); if (graphic == null) { continue; } _targetOverlay.Graphics.Add(graphic); var poly = graphic.Geometry as Polygon; foreach (var coord in poly.Parts.First().GetPoints()) { _targetOverlay.Graphics.Add(new Graphic(coord, _vertexSymbol)); } } }
private async Task SelectParcelForOffsetAsync() { ResetButton.IsEnabled = false; try { _offsetOverlay.Graphics.Clear(); var pointGeom = await MyMapView.Editor.RequestPointAsync(); var screenPnt = MyMapView.LocationToScreen(pointGeom); _selectedParcelGraphic = await _parcelOverlay.HitTestAsync(MyMapView, screenPnt); DoOffset(); } catch (TaskCanceledException) { } catch (Exception ex) { var _x = new MessageDialog(ex.Message).ShowAsync(); } ResetButton.IsEnabled = true; }
private void RenderMapTip() { MapPoint anchor = MapTipGraphic.Geometry as MapPoint; if (MyMapView.SpatialReference != null) { if (MapTipGraphic != null) { maptip.DataContext = MapTipGraphic.Attributes; } //Convert anchor point to the spatial reference of the map var mp = GeometryEngine.Project(anchor, MyMapView.SpatialReference) as MapPoint; //Convert anchor point to screen MapPoint var screen = MyMapView.LocationToScreen(mp); if (screen.X >= 0 && screen.Y >= 0 && screen.X < MyMapView.ActualWidth && screen.Y < MyMapView.ActualHeight) { //Update location of map MapTipTranslate.X = screen.X; MapTipTranslate.Y = screen.Y - maptip.ActualHeight; maptip.Visibility = Windows.UI.Xaml.Visibility.Visible; } else //Anchor is outside the display so close map tip { maptip.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } } }
private async Task SelectParcelForOffsetAsync() { try { ResetButton.IsEnabled = false; _offsetOverlay.Graphics.Clear(); var pointGeom = await MyMapView.Editor.RequestPointAsync(); var screenPnt = MyMapView.LocationToScreen(pointGeom); _selectedParcelGraphic = await _parcelOverlay.HitTestAsync(MyMapView, screenPnt); DoOffset(); } catch (TaskCanceledException) { } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } finally { ResetButton.IsEnabled = true; } }
private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e) { try { // Define the selection tolerance (half the marker symbol size so that any click on the symbol will select the feature) double tolerance = 14; // Convert the tolerance to map units double mapTolerance = tolerance * MyMapView.UnitsPerPixel; // Define the envelope around the tap location for selecting features var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance, e.Location.Y + mapTolerance, MyMapView.Map.SpatialReference); // Define the query parameters for selecting features var queryParams = new QueryParameters(); // Set the geometry to selection envelope for selection by geometry queryParams.Geometry = selectionEnvelope; // Select the features based on query parameters defined above _queryResult = await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New); bool hasResult = false; foreach (var r in _queryResult) { hasResult = true; Feature f = r as Feature; string attribute = ""; foreach (var a in f.Attributes) { attribute = attribute + a.ToString() + "\n"; } MapPoint p = f.Geometry as MapPoint; Point sp = MyMapView.LocationToScreen(p); TextBlock popupText = new TextBlock(); popupText.Background = Brushes.LightBlue; popupText.Foreground = Brushes.Blue; popupText.Text = attribute; myPopup.Child = popupText; myPopup.Width = 200; myPopup.Height = 100; var b = MyMapView.Margin; myPopup.Margin = new Thickness(sp.X, sp.Y, MyMapView.ActualWidth - 200 - sp.X, MyMapView.ActualHeight - 100 - sp.Y); } if (!hasResult) { myPopup.Width = myPopup.Height = 0; } } catch (Exception ex) { MessageBox.Show("Sample error", ex.ToString()); } }
// Retrieve a user click point and return hit tested graphics private async Task <IEnumerable <Graphic> > FindIntersectingGraphicsAsync() { var mapRect = await MyMapView.Editor.RequestShapeAsync(DrawShape.Envelope) as Envelope; Rect winRect = new Rect( MyMapView.LocationToScreen(new MapPoint(mapRect.XMin, mapRect.YMax, MyMapView.SpatialReference)), MyMapView.LocationToScreen(new MapPoint(mapRect.XMax, mapRect.YMin, MyMapView.SpatialReference))); return(await _graphicsLayer.HitTestAsync(MyMapView, winRect, MAX_GRAPHICS)); }
private async Task FindIntersectingGraphicsAsync(DrawShape drawMode) { var messageSubLayers = _messageLayer.ChildLayers.Cast <MessageSubLayer>(); IEnumerable <Graphic> results = Enumerable.Empty <Graphic>(); int maxHits = 1; if (drawMode == DrawShape.Point) { var mapPoint = await MyMapView.Editor.RequestPointAsync(); var screenPoint = MyMapView.LocationToScreen(mapPoint); foreach (var l in messageSubLayers) { results = results.Concat(await l.HitTestAsync(MyMapView, screenPoint, maxHits)); } } else { maxHits = 100; var geometry = await MyMapView.Editor.RequestShapeAsync(drawMode); var mapEnvelope = (geometry as Envelope).Extent; var upperLeft = MyMapView.LocationToScreen (new MapPoint(mapEnvelope.XMin, mapEnvelope.YMax, geometry.SpatialReference)); var lowerRight = MyMapView.LocationToScreen (new MapPoint(mapEnvelope.XMax, mapEnvelope.YMin, geometry.SpatialReference)); var rect = new Rect(upperLeft, lowerRight); foreach (var l in messageSubLayers) { results = results.Concat(await l.HitTestAsync(MyMapView, rect, maxHits)); } } if (results.Count() == 0) { return; } foreach (var graphic in results) { MilitaryMessage message = _messageLayer.GetMessage(graphic.Attributes["_id"].ToString()) as MilitaryMessage; message.MessageAction = MilitaryMessageAction.Select; if (_messageLayer.ProcessMessage(message)) { selectedMessages.Add(message); } else { MessageBox.Show("Failed"); } } }
private async Task <Graphic> GetGraphicAsync() { // Wait for the user to click a location on the map var mapPoint = (MapPoint)await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false); // Convert the map point to a screen point var screenCoordinate = MyMapView.LocationToScreen(mapPoint); // Identify graphics in the graphics overlay using the point var results = await MyMapView.IdentifyGraphicsOverlaysAsync(screenCoordinate, 2, false); // If results were found, get the first graphic Graphic graphic = null; IdentifyGraphicsOverlayResult idResult = results.FirstOrDefault(); if (idResult != null && idResult.Graphics.Count > 0) { graphic = idResult.Graphics.FirstOrDefault(); } // Return the graphic (or null if none were found) return(graphic); }
private async Task SelectParcelForOffset() { ResetButton.IsEnabled = false; try { offsetGraphicsLayer.Graphics.Clear(); var pointGeom = await MyMapView.Editor.RequestPointAsync(); var screenPnt = MyMapView.LocationToScreen(pointGeom); selectedParcelGraphic = await parcelGraphicsLayer.HitTestAsync(MyMapView, screenPnt); DoOffset(); } catch (Exception) { } ResetButton.IsEnabled = true; }
// Performs a HitTest on the rendered Messages and selects the results private async Task FindIntersectingGraphicsAsync(DrawShape drawMode) { // Get sub layers of the MessageLayer var messageSubLayers = _messageLayer.ChildLayers.Cast <MessageSubLayer>(); // Create an empty result set IEnumerable <Graphic> results = Enumerable.Empty <Graphic>(); // Set the max hits to 1 int maxHits = 1; // Handle the individual Message selection mode if (drawMode == DrawShape.Point) { // Ask the user for the point of interest MapPoint mapPoint = null; try { mapPoint = await MyMapView.Editor.RequestPointAsync(); } catch (TaskCanceledException) { } // Check the geometry if (Geometry.IsNullOrEmpty(mapPoint)) { return; } // Get the location in screen coordinates var screenPoint = MyMapView.LocationToScreen(mapPoint); // Iterate the Message sub layers and await the HitTestAsync method on each layer foreach (var l in messageSubLayers) { results = results.Concat(await l.HitTestAsync(MyMapView, screenPoint, maxHits)); } } // Handle the multiple Message selection mode else { // Increase the max hits value maxHits = 100; // Ask the user for the area of interest Envelope envelope = null; try { envelope = await MyMapView.Editor.RequestShapeAsync(drawMode) as Envelope; } catch (TaskCanceledException) { } // Check the geometry if (Geometry.IsNullOrEmpty(envelope)) { return; } // Get the screen location of the upper left var upperLeft = MyMapView.LocationToScreen (new MapPoint(envelope.XMin, envelope.YMax, envelope.SpatialReference)); // Get the screen location of the lower right var lowerRight = MyMapView.LocationToScreen (new MapPoint(envelope.XMax, envelope.YMin, envelope.SpatialReference)); // Create a Rect from the two corners var rect = new Rect(upperLeft, lowerRight); // Iterate the Message sub layers and await the HitTestAsync method on each layer foreach (var l in messageSubLayers) { results = results.Concat(await l.HitTestAsync(MyMapView, rect, maxHits)); } } if (results.Count() == 0) { return; } // Iterate the results and modify the Action value to Select then reprocess each Message foreach (var graphic in results) { // Retrieve the Message representation from the MessageLayer for each Graphic returned MilitaryMessage message = _messageLayer.GetMessage(graphic.Attributes["_id"].ToString()) as MilitaryMessage; // Modify the Action to Select message.MessageAction = MilitaryMessageAction.Select; // Reprocess the Message and add to the list if (_messageLayer.ProcessMessage(message)) { selectedMessages.Add(message); } } }