// Continuosly accept polygons from the user and calculate label points private async Task CalculateLabelPointsAsync() { try { await MyMapView.LayersLoadedAsync(); while (MyMapView.Extent != null) { if (MyMapView.Editor.IsActive) MyMapView.Editor.Cancel.Execute(null); //Get the input polygon geometry from the user var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, ((SimpleRenderer)_labelOverlay.Renderer).Symbol); if (poly != null) { //Add the polygon drawn by the user _labelOverlay.Graphics.Add(new Graphic(poly)); //Get the label point for the input geometry var labelPoint = GeometryEngine.LabelPoint(poly); if (labelPoint != null) { _labelOverlay.Graphics.Add(new Graphic(labelPoint, _pictureMarkerSymbol)); } } } } catch (TaskCanceledException) { } catch (Exception ex) { var _x = new MessageDialog("Label Point Error: " + ex.Message, "Sample Error").ShowAsync(); } }
private async Task DoLabelPoints() { ResetButton.IsEnabled = false; try { if (mapView1.Editor.IsActive) { mapView1.Editor.Cancel.Execute(null); } //Get the input polygon geometry from the user inputGeom = await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon); if (inputGeom != null) { //Add the polygon drawn by the user var g = new Graphic { Geometry = inputGeom, }; myGraphicsLayer.Graphics.Add(g); //Get the label point for the input geometry var labelPointGeom = GeometryEngine.LabelPoint(inputGeom); if (labelPointGeom != null) { myGraphicsLayer.Graphics.Add(new Graphic { Geometry = labelPointGeom, Symbol = pictureMarkerSymbol }); } } await DoLabelPoints(); } catch (Exception) { } ResetButton.IsEnabled = true; }
private async Task DoLabelPoints() { try { if (mapView1.Editor.IsActive) { mapView1.Editor.Cancel.Execute(null); } //Get the input polygon geometry from the user inputGeom = await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon); if (inputGeom != null) { //Add the polygon drawn by the user var g = new Graphic { Geometry = inputGeom, }; myGraphicsLayer.Graphics.Add(g); //Get the label point for the input geometry var labelPointGeom = GeometryEngine.LabelPoint(inputGeom); if (labelPointGeom != null) { myGraphicsLayer.Graphics.Add(new Graphic { Geometry = labelPointGeom, Symbol = pictureMarkerSymbol }); ResetButton.IsEnabled = true; } } await DoLabelPoints(); } catch (TaskCanceledException) { } catch (Exception ex) { var _x = new MessageDialog("Ha ocurrido un error: " + ex.Message, "Error").ShowAsync(); } }
/// <summary> /// When view is tapped, clear the map of selection, close keyboard and bottom sheet /// </summary> /// <param name="sender">Sender element.</param> /// <param name="e">Eevent args.</param> private async void MapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Wait for double tap to fire await Task.Delay(500); // If view has been double tapped, set tapped to handled and flag back to false // If view has been tapped just once clear the map of selection, close keyboard and bottom sheet if (this.isViewDoubleTapped == true) { e.Handled = true; this.isViewDoubleTapped = false; } else { // If route card is visible, do not dismiss route if (this.RouteCard.Alpha == 1) { // Create a new Alert Controller UIAlertController actionSheetAlert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); // Add Actions actionSheetAlert.AddAction(UIAlertAction.Create("Clear Route", UIAlertActionStyle.Destructive, (action) => this.ClearRoute())); actionSheetAlert.AddAction(UIAlertAction.Create("Keep Route", UIAlertActionStyle.Default, null)); // Required for iPad - You must specify a source for the Action Sheet since it is // displayed as a popover UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = this.View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Display the alert this.PresentViewController(actionSheetAlert, true, null); } else { // get the tap location in screen unit var tapScreenPoint = e.Position; var layer = this.MapView.Map.OperationalLayers[AppSettings.CurrentSettings.RoomsLayerIndex]; var pixelTolerance = 10; var returnPopupsOnly = false; var maxResults = 1; try { // Identify a layer using MapView, passing in the layer, the tap point, tolerance, types to return, and max result IdentifyLayerResult idResults = await this.MapView.IdentifyLayerAsync(layer, tapScreenPoint, pixelTolerance, returnPopupsOnly, maxResults); // create a picture marker symbol var uiImagePin = UIImage.FromBundle("MapPin"); var mapPin = this.ImageToByteArray(uiImagePin); var roomMarker = new PictureMarkerSymbol(new RuntimeImage(mapPin)); roomMarker.OffsetY = uiImagePin.Size.Height * 0.65; // Create graphic var mapPinGraphic = new Graphic(GeometryEngine.LabelPoint(idResults.GeoElements.First().Geometry as Polygon), roomMarker); // Add pin to mapview var graphicsOverlay = this.MapView.GraphicsOverlays["PinsGraphicsOverlay"]; graphicsOverlay.Graphics.Clear(); graphicsOverlay.Graphics.Add(mapPinGraphic); // Get room attribute from the settings. First attribute should be set as the searcheable one var roomAttribute = AppSettings.CurrentSettings.ContactCardDisplayFields[0]; var employeeNameAttribute = AppSettings.CurrentSettings.ContactCardDisplayFields[1]; var roomNumber = idResults.GeoElements.First().Attributes[roomAttribute]; var employeeName = idResults.GeoElements.First().Attributes[employeeNameAttribute]; if (roomNumber != null) { var employeeNameLabel = employeeName ?? string.Empty; this.ShowBottomCard(roomNumber.ToString(), employeeNameLabel.ToString(), false); } else { this.MapView.GraphicsOverlays["PinsGraphicsOverlay"].Graphics.Clear(); this.HideContactCard(); } } catch { this.MapView.GraphicsOverlays["PinsGraphicsOverlay"].Graphics.Clear(); this.HideContactCard(); } if (this.LocationSearchBar.IsFirstResponder == true) { this.LocationSearchBar.ResignFirstResponder(); } } } }