private async void Initialize() { // Create and add the map. _mapView.Map = new Map(Basemap.CreateImagery()); // Configure location display. _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter; await _mapView.LocationDisplay.DataSource.StartAsync(); _mapView.LocationDisplay.IsEnabled = true; // Add a graphics overlay for the drawn pipes. _mapView.GraphicsOverlays.Add(_pipesOverlay); _pipesOverlay.Renderer = new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 2)); // Set the SketchEditor for the map. _mapView.SketchEditor = _sketchEditor; // Create an elevation source and Surface. _elevationSource = new ArcGISTiledElevationSource(new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")); await _elevationSource.LoadAsync(); _elevationSurface = new Surface(); _elevationSurface.ElevationSources.Add(_elevationSource); await _elevationSurface.LoadAsync(); // Enable the add button. _addButton.Enabled = true; }
private async void Initialize() { // Create and add the map. MyMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard); MyMapView.PropertyChanged += async(o, e) => { if (e.PropertyName == nameof(MyMapView.LocationDisplay) && MyMapView.LocationDisplay != null) { // Start the location display on the mapview. try { // Permission request only needed on Android. #if XAMARIN_ANDROID // See implementation in MainActivity.cs in the Android platform project. bool permissionGranted = await MainActivity.Instance.AskForLocationPermission(); if (!permissionGranted) { throw new Exception("Location permission not granted."); } #endif MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter; await MyMapView.LocationDisplay.DataSource.StartAsync(); MyMapView.LocationDisplay.IsEnabled = true; } catch (Exception ex) { Debug.WriteLine(ex); await Application.Current.MainPage.DisplayAlert("Couldn't start location", ex.Message, "OK"); } } }; // Add a graphics overlay for the drawn pipes. MyMapView.GraphicsOverlays.Add(_pipesOverlay); _pipesOverlay.Renderer = new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 2)); // Set the SketchEditor for the map. MyMapView.SketchEditor = _sketchEditor; try { // Create an elevation source and Surface. _elevationSource = new ArcGISTiledElevationSource(new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")); await _elevationSource.LoadAsync(); _elevationSurface = new Surface(); _elevationSurface.ElevationSources.Add(_elevationSource); await _elevationSurface.LoadAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); await Application.Current.MainPage.DisplayAlert("Error", "Failed to load elevation.", "OK"); } // Enable the add button. AddButton.IsEnabled = true; }