public async void MyMapView_OnMouseMove(object sender, MouseEventArgs e) { if (_isHitTesting) { return; } try { _isHitTesting = true; var screenPoint = e.GetPosition(MyMapView); var graphic = await _graphicsLayer.HitTestAsync(MyMapView, screenPoint); if (graphic != null) { Graphic = graphic; IsVisible = true; } else { IsVisible = false; } } catch { IsVisible = false; } finally { _isHitTesting = false; } }
private async void MapView_MouseMove(object sender, MouseEventArgs e) { if (_isHitTesting) { return; } try { _isHitTesting = true; Point screenPoint = e.GetPosition(MyMapView); Graphic graphic = await _graphicsLayer.HitTestAsync(MyMapView, screenPoint); if (graphic != null) { mapTip.DataContext = graphic; mapTip.Visibility = Visibility.Visible; } else { mapTip.Visibility = Visibility.Collapsed; } } catch { mapTip.Visibility = Visibility.Collapsed; } finally { _isHitTesting = false; } }
public override async void MapViewTapped(MapView mapView, MapViewInputEventArgs e, bool drawing) { if (drawing) { DeleteGraphic(DRAFT); } ClearHilight(); var graphic = await GraphicsLayer.HitTestAsync(mapView, e.Position); if (graphic != null) { if (_layerInfo.MarkerType == EventMarkerType.Proportional) { (graphic.Symbol as SimpleMarkerSymbol).Color = DefaultSettings.GetColor(GeoStatus.Hilight); } else { graphic.Symbol = _layerInfo.GetSymbol(GeoStatus.Hilight); } OnPointTapped(graphic.Geometry as MapPoint); } else { if (drawing) { AddGraphic(e.Location, DRAFT, 1, GeoStatus.Hilight); } OnPointTapped((MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84)); } }
// HitTest the graphics and position the map tip private async void MyMapView_PointerMoved(object sender, PointerRoutedEventArgs e) { if (!_isMapReady) { return; } try { _isMapReady = false; Point screenPoint = e.GetCurrentPoint(MyMapView).Position; var graphic = await _graphicsLayer.HitTestAsync(MyMapView, screenPoint); if (graphic != null) { _mapTip.DataContext = graphic; _mapTip.Visibility = Visibility.Visible; } else { _mapTip.Visibility = Visibility.Collapsed; } } catch { _mapTip.Visibility = Visibility.Collapsed; } finally { _isMapReady = true; } }
private async Task SelectParcelForOffset() { try { ResetButton.IsEnabled = false; offsetGraphicsLayer.Graphics.Clear(); var pointGeom = await mapView.Editor.RequestPointAsync(); pointGeom.SpatialReference = mapView.SpatialReference; var screenPnt = mapView.LocationToScreen(pointGeom); selectedParcelGraphic = await parcelGraphicsLayer.HitTestAsync(mapView, screenPnt); DoOffset(); } catch (Exception) { } finally { ResetButton.IsEnabled = true; } }
private async void HandleMapViewTapped(object sender, MapViewInputEventArgs e) { if (layer == null || MapEditor.IsActive) { return; } var graphic = await layer.HitTestAsync(PmssMapView, e.Position); if (graphic != null) { if (graphic == CurrentGraphic) { CurrentGraphic.IsSelected = false; CurrentGraphic = null; } else { if (CurrentGraphic != null) { CurrentGraphic.IsSelected = false; } CurrentGraphic = graphic; CurrentGraphic.IsSelected = true; } } }
public override async void MapViewTapped(MapView mapView, MapViewInputEventArgs e, bool drawing) { if (!drawing) { var graphic = await GraphicsLayer.HitTestAsync(mapView, e.Position); if (graphic != null) { OnItemTapped(int.Parse($"{graphic.Attributes[CURR_GEO]}")); } return; } MapPoint newPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84); if (_drawPointList.Count == 0) { AddGraphic(newPoint, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Point, GeoStatus.Hilight)); } else { Polyline line = new Polyline(new MapPoint[] { _drawPointList.Last(), newPoint }); AddGraphic(line, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Hilight)); } _drawPointList.Add(newPoint); }
// Accept user click point and select the underlying target polygon private async Task SelectTargetGeometryAsync() { txtInstruct.Text = "Click to select a target geometry"; _coordinateLayer.Graphics.Clear(); _targetLayer.Graphics.Clear(); Graphic graphic = null; while (graphic == null) { var point = await mapView.Editor.RequestPointAsync(); graphic = await _graphicsLayer.HitTestAsync(mapView, mapView.LocationToScreen(point)); if (graphic == null) { continue; } _targetLayer.Graphics.Add(graphic); var poly = graphic.Geometry as Polygon; foreach (var coord in poly.Rings.First()) { _targetLayer.Graphics.Add(new Graphic(new MapPoint(coord, poly.SpatialReference), _vertexSymbol)); } } }
// HitTest the graphics and position the map tip private async void mapView_PointerMoved(object sender, PointerRoutedEventArgs e) { if (_isHitTesting) { return; } try { _isHitTesting = true; Point screenPoint = e.GetCurrentPoint(mapView).Position; var graphic = await _graphicsLayer.HitTestAsync(mapView, screenPoint); if (graphic != null) { maptipTransform.X = screenPoint.X + 4; maptipTransform.Y = screenPoint.Y - mapTip.ActualHeight; mapTip.DataContext = graphic; mapTip.Visibility = Visibility.Visible; } else { mapTip.Visibility = Visibility.Collapsed; } } catch { mapTip.Visibility = Visibility.Collapsed; } finally { _isHitTesting = false; } }
// 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)); }
public Task <IEnumerable <Graphic> > GraphicsLayerHitTestAsync(GraphicsLayer graphicsLayer, Point point, int maxHits = 10) { if (graphicsLayer == null) { return(Task.FromResult(System.Linq.Enumerable.Empty <Graphic>())); } var map = MapView; return(graphicsLayer.HitTestAsync(map, point, maxHits)); }
private async void MouseDoubleClick(object parameter) { Point tagPoint = Mouse.GetPosition(tagView as FrameworkElement); GraphicsLayer layer = scene.Layers["PointLayer"] as GraphicsLayer; if (layer == null) { return; } var ga = await layer.HitTestAsync(tagView, tagPoint); if (ga != null) { TagGraphic = ga; } }
private async void mapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { var hitGraphic = await _candidateGraphicsLayer.HitTestAsync(mapView1, e.Position); if (hitGraphic != null) { if (mapView1tip.Visibility == Windows.UI.Xaml.Visibility.Collapsed) { _mapTipGraphic = hitGraphic; RenderMapTip(); } else { mapView1tip.Visibility = Windows.UI.Xaml.Visibility.Collapsed; mapView1tip.DataContext = null; _mapTipGraphic = null; } } }
public async void QueryEvent() { //if (mapOperationType != MapOperationType.QueryEvent) //{ mapOperationType = MapOperationType.QueryEvent; var mapRect = await mainMapView.Editor.RequestShapeAsync(DrawShape.Envelope) as Envelope; personsLayers.ClearSelection(); eventsLayer.ClearSelection(); var winRect = new Rect(mainMapView.LocationToScreen(new MapPoint(mapRect.XMin, mapRect.YMax, mainMapView.SpatialReference)), mainMapView.LocationToScreen(new MapPoint(mapRect.XMax, mapRect.YMin, mainMapView.SpatialReference))); var graphics = await eventsLayer.HitTestAsync(mainMapView, winRect, 1000); ShowSelectEventsByGraphic(graphics); mapOperationType = MapOperationType.None; // } // else // { // mapOperationType = MapOperationType.None; // } }
// Hit Test the graphics layer by single point private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e) { try { var graphics = await _graphicsLayer.HitTestAsync(MyMapView, e.Position, MAX_GRAPHICS); string results = "Hit: "; if (graphics == null || graphics.Count() == 0) { results += "None"; } else { results += string.Join(", ", graphics.Select(g => g.Attributes["ID"].ToString()).ToArray()); } txtResults.Text = results; } catch (Exception ex) { var _x = new MessageDialog("HitTest Error: " + ex.Message, "Graphics Layer Hit Testing").ShowAsync(); } }
private async Task SelectParcelForOffset() { ResetButton.IsEnabled = false; try { offsetGraphicsLayer.Graphics.Clear(); var pointGeom = await mapView1.Editor.RequestPointAsync(); var screenPnt = mapView1.LocationToScreen(pointGeom); selectedParcelGraphic = await parcelGraphicsLayer.HitTestAsync(mapView1, screenPnt); DoOffset(); } catch (Exception) { } ResetButton.IsEnabled = true; }
private async void mapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { var hitGraphic = await _locationGraphicsLayer.HitTestAsync(mapView1, e.Position); if (hitGraphic != null) { if (maptip.Visibility == Windows.UI.Xaml.Visibility.Collapsed) { MapTipGraphic = hitGraphic; RenderMapTip(); } else { maptip.Visibility = Windows.UI.Xaml.Visibility.Collapsed; maptip.DataContext = null; MapTipGraphic = null; } } else { maptip.Visibility = Windows.UI.Xaml.Visibility.Collapsed; var mp = mapView1.ScreenToLocation(e.Position); Graphic g = new Graphic() { Geometry = mp }; var layer = mapView1.Map.Layers.OfType <GraphicsLayer>().First(); layer.Graphics.Add(g); var token = ""; var locatorTask = new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), token); try { var result = await locatorTask.ReverseGeocodeAsync(mp, 30, mapView1.SpatialReference, CancellationToken.None); Graphic graphic = new Graphic() { Geometry = mp }; string latlon = String.Format("{0}, {1}", result.Location.X, result.Location.Y); string address1 = result.AddressFields["Address"].ToString(); string address2 = String.Format("{0}, {1} {2}", result.AddressFields["City"], result.AddressFields["Region"], result.AddressFields["Postal"]); graphic.Attributes.Add("LatLon", latlon); graphic.Attributes.Add("Address1", address1); graphic.Attributes.Add("Address2", address2); _locationGraphicsLayer.Graphics.Add(graphic); MapTipGraphic = graphic; RenderMapTip(); } catch (Exception) { } } }