private void Initialize() { // Define the route stop locations (points) MapPoint fromPoint = new MapPoint(-117.15494348793044, 32.706506537686927, SpatialReferences.Wgs84); MapPoint toPoint = new MapPoint(-117.14905088669816, 32.735308180609138, SpatialReferences.Wgs84); // Create Stop objects with the points and add them to a list of stops Stop stop1 = new Stop(fromPoint); Stop stop2 = new Stop(toPoint); _routeStops = new List <Stop> { stop1, stop2 }; // Picture marker symbols: from = car, to = checkered flag PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(_carIconUri) { Height = 40, Width = 40 }; PictureMarkerSymbol flagSymbol = new PictureMarkerSymbol(_checkedFlagIconUri) { Height = 40, Width = 40, // Offset the icon so that it is anchored at the bottom of the flagpole OffsetX = 20, OffsetY = 20 }; // Create graphics for the stops Graphic fromGraphic = new Graphic(fromPoint, carSymbol) { // Make sure the icons are shown over the route line ZIndex = 1 }; Graphic toGraphic = new Graphic(toPoint, flagSymbol) { ZIndex = 1 }; // Create the graphics overlay and add the stop graphics _routeGraphicsOverlay = new GraphicsOverlay(); _routeGraphicsOverlay.Graphics.Add(fromGraphic); _routeGraphicsOverlay.Graphics.Add(toGraphic); // Get an Envelope that covers the area of the stops (and a little more) Envelope routeStopsExtent = new Envelope(fromPoint, toPoint); EnvelopeBuilder envBuilder = new EnvelopeBuilder(routeStopsExtent); envBuilder.Expand(1.5); // Create a new viewpoint apply it to the map view when the spatial reference changes Viewpoint sanDiegoViewpoint = new Viewpoint(envBuilder.ToGeometry()); _myMapView.SpatialReferenceChanged += (s, e) => _myMapView.SetViewpoint(sanDiegoViewpoint); // Add a new Map and the graphics overlay to the map view _myMapView.Map = new Map(Basemap.CreateStreets()); _myMapView.GraphicsOverlays.Add(_routeGraphicsOverlay); }
private void Initialize() { // Create a spatial reference that's suitable for creating planar buffers in north central Texas (State Plane). SpatialReference statePlaneNorthCentralTexas = new SpatialReference(32038); // Define a polygon that represents the valid area of use for the spatial reference. // This information is available at https://developers.arcgis.com/net/latest/wpf/guide/pdf/projected_coordinate_systems_rt100_3_0.pdf List <MapPoint> spatialReferenceExtentCoords = new List <MapPoint> { new MapPoint(-103.070, 31.720, SpatialReferences.Wgs84), new MapPoint(-103.070, 34.580, SpatialReferences.Wgs84), new MapPoint(-94.000, 34.580, SpatialReferences.Wgs84), new MapPoint(-94.00, 31.720, SpatialReferences.Wgs84) }; _spatialReferenceArea = new Polygon(spatialReferenceExtentCoords); _spatialReferenceArea = GeometryEngine.Project(_spatialReferenceArea, statePlaneNorthCentralTexas) as Polygon; // Create a map that uses the North Central Texas state plane spatial reference. Map bufferMap = new Map(statePlaneNorthCentralTexas); // Add some base layers (counties, cities, and highways). Uri usaLayerSource = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"); ArcGISMapImageLayer usaLayer = new ArcGISMapImageLayer(usaLayerSource); bufferMap.Basemap.BaseLayers.Add(usaLayer); // Use a new EnvelopeBuilder to expand the spatial reference extent 120%. EnvelopeBuilder envBuilder = new EnvelopeBuilder(_spatialReferenceArea.Extent); envBuilder.Expand(1.2); // Set the map's initial extent to the expanded envelope. Envelope startingEnvelope = envBuilder.ToGeometry(); bufferMap.InitialViewpoint = new Viewpoint(startingEnvelope); // Assign the map to the MapView. _myMapView.Map = bufferMap; // Create a graphics overlay to show the buffer polygon graphics. GraphicsOverlay bufferGraphicsOverlay = new GraphicsOverlay { // Give the overlay an ID so it can be found later. Id = "buffers" }; // Create a graphic to show the spatial reference's valid extent (envelope) with a dashed red line. SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Red, 5); Graphic spatialReferenceExtentGraphic = new Graphic(_spatialReferenceArea, lineSymbol); // Add the graphic to a new overlay. GraphicsOverlay spatialReferenceGraphicsOverlay = new GraphicsOverlay(); spatialReferenceGraphicsOverlay.Graphics.Add(spatialReferenceExtentGraphic); // Add the graphics overlays to the MapView. _myMapView.GraphicsOverlays.Add(bufferGraphicsOverlay); _myMapView.GraphicsOverlays.Add(spatialReferenceGraphicsOverlay); }
private void Initialize() { // Define the route stop locations (points) MapPoint fromPoint = new MapPoint(-117.15494348793044, 32.706506537686927, SpatialReferences.Wgs84); MapPoint toPoint = new MapPoint(-117.14905088669816, 32.735308180609138, SpatialReferences.Wgs84); // Create Stop objects with the points and add them to a list of stops Stop stop1 = new Stop(fromPoint); Stop stop2 = new Stop(toPoint); _routeStops = new List <Stop> { stop1, stop2 }; // Picture marker symbols: from = car, to = checkered flag PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(_carIconUri); PictureMarkerSymbol flagSymbol = new PictureMarkerSymbol(_checkedFlagIconUri); // Add a slight offset (pixels) to the picture symbols. carSymbol.OffsetX = -carSymbol.Width / 2; carSymbol.OffsetY = -carSymbol.Height / 2; flagSymbol.OffsetX = -flagSymbol.Width / 2; flagSymbol.OffsetY = -flagSymbol.Height / 2; // Set the height and width. flagSymbol.Height = 60; flagSymbol.Width = 60; carSymbol.Height = 60; carSymbol.Width = 60; // Create graphics for the stops Graphic fromGraphic = new Graphic(fromPoint, carSymbol) { ZIndex = 1 }; Graphic toGraphic = new Graphic(toPoint, flagSymbol) { ZIndex = 1 }; // Create the graphics overlay and add the stop graphics _routeGraphicsOverlay = new GraphicsOverlay(); _routeGraphicsOverlay.Graphics.Add(fromGraphic); _routeGraphicsOverlay.Graphics.Add(toGraphic); // Get an Envelope that covers the area of the stops (and a little more) Envelope routeStopsExtent = new Envelope(fromPoint, toPoint); EnvelopeBuilder envBuilder = new EnvelopeBuilder(routeStopsExtent); envBuilder.Expand(1.5); // Create a new viewpoint apply it to the map view when the spatial reference changes Viewpoint sanDiegoViewpoint = new Viewpoint(envBuilder.ToGeometry()); MyMapView.SpatialReferenceChanged += (s, e) => MyMapView.SetViewpoint(sanDiegoViewpoint); // Add a new Map and the graphics overlay to the map view MyMapView.Map = new Map(BasemapStyle.ArcGISStreets); MyMapView.GraphicsOverlays.Add(_routeGraphicsOverlay); }
private async void Initialize() { // Get all the ColorRamp names from the PresetColorRampType Enumeration and put them // in an array of strings, then set the ComboBox.ItemSource to the array, and finally // select the first item in the ComboBox string[] myPresetColorRampTypes = Enum.GetNames(typeof(PresetColorRampType)); ColorRamps.ItemsSource = myPresetColorRampTypes; ColorRamps.SelectedIndex = 0; // Get all the SlopeType names from the SlopeType Enumeration and put them // in an array of strings, then set the ComboBox.ItemSource to the array, and finally // select the first item in the ComboBox string[] mySlopeTypes = Enum.GetNames(typeof(SlopeType)); SlopeTypes.ItemsSource = mySlopeTypes; SlopeTypes.SelectedIndex = 0; // Set the altitude slider min/max and initial value Altitude_Slider.Minimum = 0; Altitude_Slider.Maximum = 90; Altitude_Slider.Value = 45; // Set the azimuth slider min/max and initial value Azimuth_Slider.Minimum = 0; Azimuth_Slider.Maximum = 360; Azimuth_Slider.Value = 180; // Load the raster file using a path on disk Raster myRasterImagery = new Raster(GetRasterPath_Imagery()); // Create the raster layer from the raster RasterLayer myRasterLayerImagery = new RasterLayer(myRasterImagery); // Create a new map using the raster layer as the base map Map myMap = new Map(new Basemap(myRasterLayerImagery)); // Wait for the layer to load - this enabled being able to obtain the extent information // of the raster layer await myRasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer EnvelopeBuilder myEnvelopBuilder = new EnvelopeBuilder(myRasterLayerImagery.FullExtent); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map myEnvelopBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent myMap.InitialViewpoint = new Viewpoint(myEnvelopBuilder.ToGeometry().Extent); // Add map to the map view MyMapView.Map = myMap; // Wait for the map to load await myMap.LoadAsync(); // Enable the 'Update Renderer' button now that the map has loaded UpdateRenderer.IsEnabled = true; }
private void UpdateMapExtent() { // Return if mapview is null. if (myMapView == null) { return; } // Get the new viewpoint. Viewpoint myViewPoint = myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); // Return if viewpoint is null. if (myViewPoint == null) { return; } // Get the updated extent for the new viewpoint. Envelope extent = myViewPoint.TargetGeometry as Envelope; // Return if extent is null. if (extent == null) { return; } // Create an envelope that is a bit smaller than the extent. EnvelopeBuilder envelopeBldr = new EnvelopeBuilder(extent); envelopeBldr.Expand(0.80); // Get the (only) graphics overlay in the map view. GraphicsOverlay extentOverlay = myMapView.GraphicsOverlays.FirstOrDefault(); // Return if the extent overlay is null. if (extentOverlay == null) { return; } // Get the extent graphic. Graphic extentGraphic = extentOverlay.Graphics.FirstOrDefault(); // Create the extent graphic and add it to the overlay if it doesn't exist. if (extentGraphic == null) { extentGraphic = new Graphic(envelopeBldr.ToGeometry()); extentOverlay.Graphics.Add(extentGraphic); } else { // Otherwise, update the graphic's geometry. extentGraphic.Geometry = envelopeBldr.ToGeometry(); } }
private async void Initialize() { try { // Set the altitude slider min/max and initial value (minimum is always 0 - do // not set _Altitude_Slider.Min = 0) _Slider_Altitude.Max = 90; _Slider_Altitude.Progress = 45; // Set the azimuth slider min/max and initial value (minimum is always 0 - do // not set _AZimuth_Slider.Min = 0) _Slider_Azimuth.Max = 360; _Slider_Azimuth.Progress = 180; // Load the raster file using a path on disk Raster myRasterImagery = new Raster(await GetRasterPath_Imagery()); // Create the raster layer from the raster RasterLayer myRasterLayerImagery = new RasterLayer(myRasterImagery); // Create a new map using the raster layer as the base map Map myMap = new Map(new Basemap(myRasterLayerImagery)); // Wait for the layer to load - this enabled being able to obtain the extent information // of the raster layer await myRasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer EnvelopeBuilder myEnvelopBuilder = new EnvelopeBuilder(myRasterLayerImagery.FullExtent); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable // area of the map myEnvelopBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent myMap.InitialViewpoint = new Viewpoint(myEnvelopBuilder.ToGeometry().Extent); // Add map to the map view _myMapView.Map = myMap; // Wait for the map to load await myMap.LoadAsync(); // Enable the 'Update Renderer' button now that the map has loaded _Button_UpdateRenderer.Enabled = true; } catch (Exception ex) { Console.WriteLine(ex); } }
private async void Initialize() { // Set the altitude slider min/max and initial value. _altitudeSlider.MinValue = 0; _altitudeSlider.MaxValue = 90; _altitudeSlider.Value = 45; // Set the azimuth slider min/max and initial value. _azimuthSlider.MinValue = 0; _azimuthSlider.MaxValue = 360; _azimuthSlider.Value = 180; // Load the raster file using a path on disk. Raster rasterImagery = new Raster(DataManager.GetDataFolder("7c4c679ab06a4df19dc497f577f111bd", "raster-file", "Shasta.tif")); // Create the raster layer from the raster. RasterLayer rasterLayerImagery = new RasterLayer(rasterImagery); // Create a new map using the raster layer as the base map. Map map = new Map(new Basemap(rasterLayerImagery)); try { // Wait for the layer to load - this enabled being able to obtain the raster layer's extent. await rasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer. EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(rasterLayerImagery.FullExtent); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map. envelopeBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent. map.InitialViewpoint = new Viewpoint(envelopeBuilder.ToGeometry().Extent); // Add map to the map view. _myMapView.Map = map; // Wait for the map to load. await map.LoadAsync(); // Enable the 'Update Renderer' button now that the map has loaded. _updateRendererButton.Enabled = true; } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void Initialize() { // Update the preset color ramp type options and select the first one. ColorRamps.ItemsSource = Enum.GetNames(typeof(PresetColorRampType)); ColorRamps.SelectedIndex = 0; // Update the slope options and select the first one. SlopeTypes.ItemsSource = Enum.GetNames(typeof(SlopeType)); SlopeTypes.SelectedIndex = 0; // Load the raster file using a path on disk. Raster myRasterImagery = new Raster(GetRasterPath_Imagery()); // Create the raster layer from the raster. RasterLayer myRasterLayerImagery = new RasterLayer(myRasterImagery); // Create a new map using the raster layer as the base map. Map myMap = new Map(new Basemap(myRasterLayerImagery)); try { // Wait for the layer to load - this enabled being able to obtain the extent information // of the raster layer. await myRasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer. EnvelopeBuilder myEnvelopBuilder = new EnvelopeBuilder(myRasterLayerImagery.FullExtent); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map. myEnvelopBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent. myMap.InitialViewpoint = new Viewpoint(myEnvelopBuilder.ToGeometry().Extent); // Add map to the map view. MyMapView.Map = myMap; // Wait for the map to load. await myMap.LoadAsync(); // Enable the 'Update Renderer' button now that the map has loaded. UpdateRenderer.IsEnabled = true; } catch (Exception e) { MessageBox.Show(e.ToString(), "Error"); } }
private void ViewpointChanged1(object sender, EventArgs e) { try { Viewpoint UIMapViewpoint = HeatVulnerability1.HeatVuln.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var UIMapViewGeometry = UIMapViewpoint.TargetGeometry.Extent; EnvelopeBuilder newEnvelope = new EnvelopeBuilder(UIMapViewGeometry); // The video walls map extent is 1.4x the UI's extent newEnvelope.Expand(1.4); HeatVulnerability2.HeatVuln.SetViewpoint(new Viewpoint(newEnvelope.Extent)); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private async void Initialize() { // Set the altitude slider min/max and initial value _Altitude_Slider.MinValue = 0; _Altitude_Slider.MaxValue = 90; _Altitude_Slider.Value = 45; // Set the azimuth slider min/max and initial value _Azimuth_Slider.MinValue = 0; _Azimuth_Slider.MaxValue = 360; _Azimuth_Slider.Value = 180; // Load the raster file using a path on disk Raster myRasterImagery = new Raster(GetRasterPath_Imagery()); // Create the raster layer from the raster RasterLayer myRasterLayerImagery = new RasterLayer(myRasterImagery); // Create a new map using the raster layer as the base map Map myMap = new Map(new Basemap(myRasterLayerImagery)); // Wait for the layer to load - this enabled being able to obtain the extent information // of the raster layer await myRasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer EnvelopeBuilder myEnvelopBuilder = new EnvelopeBuilder(myRasterLayerImagery.FullExtent); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map myEnvelopBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent myMap.InitialViewpoint = new Viewpoint(myEnvelopBuilder.ToGeometry().Extent); // Add map to the map view _myMapView.Map = myMap; // Wait for the map to load await myMap.LoadAsync(); // Enable the 'Update Renderer' button now that the map has loaded _UpdateRenderer.Enabled = true; }
private Geometry GetExtentOfGraphicsOverlay(GraphicsOverlay inputGraphicsOverlay, double expansionFactor, SpatialReference spatialReferenceType) { // Get all of the graphics contained in the graphics overlay. GraphicCollection inputGraphicCollection = inputGraphicsOverlay.Graphics; // Create a new envelope builder using the same spatial reference as the graphics. EnvelopeBuilder unionEnvelopeBuilder = new EnvelopeBuilder(spatialReferenceType); // Loop through each graphic in the graphic collection. foreach (Graphic oneGraphic in inputGraphicCollection) { // Union the extent of each graphic in the envelope builder. unionEnvelopeBuilder.UnionOf(oneGraphic.Geometry.Extent); } // Expand the envelope builder by the expansion factor. unionEnvelopeBuilder.Expand(expansionFactor); // Return the unioned extent plus the expansion factor. return(unionEnvelopeBuilder.Extent); }
private void SetExtent() { // Get all of the graphics contained in the graphics overlay GraphicCollection myGraphicCollection = _overlay.Graphics; // Create a new envelope builder using the same spatial reference as the graphics EnvelopeBuilder myEnvelopeBuilder = new EnvelopeBuilder(SpatialReferences.Wgs84); // Loop through each graphic in the graphic collection foreach (Graphic oneGraphic in myGraphicCollection) { // Union the extent of each graphic in the envelope builder myEnvelopeBuilder.UnionOf(oneGraphic.Geometry.Extent); } // Expand the envelope builder by 30% myEnvelopeBuilder.Expand(1.3); // Adjust the viewable area of the map to encompass all of the graphics in the // graphics overlay plus an extra 30% margin for better viewing _myMapView.SetViewpointAsync(new Viewpoint(myEnvelopeBuilder.Extent)); }
private async void Initialize() { // Load the raster file using a path on disk. Raster rasterImagery = new Raster(DataManager.GetDataFolder("7c4c679ab06a4df19dc497f577f111bd", "raster-file", "Shasta.tif")); // Create the raster layer from the raster. RasterLayer rasterLayerImagery = new RasterLayer(rasterImagery); // Create a new map using the raster layer as the base map. Map map = new Map(new Basemap(rasterLayerImagery)); try { // Wait for the layer to load - this enabled being able to obtain the raster layer's extent. await rasterLayerImagery.LoadAsync(); // Create a new EnvelopeBuilder from the full extent of the raster layer. EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(rasterLayerImagery.FullExtent); // Configure the settings view. _settingsVC = new BlendSettingsController(map); // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map. envelopeBuilder.Expand(0.75); // Set the viewpoint of the map to the EnvelopeBuilder's extent. map.InitialViewpoint = new Viewpoint(envelopeBuilder.ToGeometry().Extent); // Add map to the map view. _myMapView.Map = map; // Wait for the map to load. await map.LoadAsync(); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private void Initialize() { // Define the route stop locations (points) MapPoint fromPoint = new MapPoint(-112.068962, 33.638390, SpatialReferences.Wgs84); MapPoint toPoint = new MapPoint(-112.1028099, 33.7334937, SpatialReferences.Wgs84); // Create Stop objects with the points and add them to a list of stops Stop stop1 = new Stop(new MapPoint(-112.068962, 33.638390, SpatialReferences.Wgs84)); Stop stop2 = new Stop(new MapPoint(-111.994930, 33.618900, SpatialReferences.Wgs84)); Stop stop3 = new Stop(new MapPoint(-112.0021089, 33.6858299, SpatialReferences.Wgs84)); Stop stop4 = new Stop(new MapPoint(-111.9734644, 33.6348065, SpatialReferences.Wgs84)); Stop stop5 = new Stop(new MapPoint(-112.1028099, 33.7334937, SpatialReferences.Wgs84)); _routeStops = new List <Stop> { stop1, stop2, stop3, stop4, stop5 }; //// Create Stop objects with the points and add them to a list of stops //Stop stop1 = new Stop(fromPoint); //Stop stop2 = new Stop(toPoint); //_routeStops = new List<Stop> { stop1, stop2 }; // Picture marker symbols: from = car, to = checkered flag PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(_carIconUri); PictureMarkerSymbol flagSymbol = new PictureMarkerSymbol(_checkedFlagIconUri); // Add a slight offset (pixels) to the picture symbols. carSymbol.OffsetX = -carSymbol.Width / 2; carSymbol.OffsetY = -carSymbol.Height / 2; flagSymbol.OffsetX = -flagSymbol.Width / 2; flagSymbol.OffsetY = -flagSymbol.Height / 2; // Set the height and width. flagSymbol.Height = 60; flagSymbol.Width = 60; carSymbol.Height = 60; carSymbol.Width = 60; // Create graphics for the stops Graphic fromGraphic = new Graphic(fromPoint, carSymbol) { ZIndex = 1 }; Graphic toGraphic = new Graphic(toPoint, flagSymbol) { ZIndex = 1 }; // Create the graphics overlay and add the stop graphics _routeGraphicsOverlay = new GraphicsOverlay(); _routeGraphicsOverlay.Graphics.Add(fromGraphic); _routeGraphicsOverlay.Graphics.Add(toGraphic); // Get an Envelope that covers the area of the stops (and a little more) Envelope routeStopsExtent = new Envelope(fromPoint, toPoint); EnvelopeBuilder envBuilder = new EnvelopeBuilder(routeStopsExtent); envBuilder.Expand(1.5); // Create a new viewpoint apply it to the map view when the spatial reference changes Viewpoint sanDiegoViewpoint = new Viewpoint(envBuilder.ToGeometry()); MyMapView.SpatialReferenceChanged += (s, e) => MyMapView.SetViewpoint(sanDiegoViewpoint); // Add a new Map and the graphics overlay to the map view MyMapView.Map = new Map(Basemap.CreateImageryWithLabelsVector()); MyMapView.GraphicsOverlays.Add(_routeGraphicsOverlay); }
/// <summary> /// Generates route from the geocoded locations /// </summary> private async Task GetRouteAsync() { if (FromPlace == null || ToPlace == null) { return; } IsBusy = true; if (Router == null) { try { await CreateRouteTask(); } catch (Exception ex) { ErrorMessage = "Unable to load routing service. The routing functionality may not work."; StackTrace = ex.ToString(); IsBusy = false; return; } } // set the route parameters var routeParams = await Router.CreateDefaultParametersAsync(); routeParams.ReturnDirections = true; routeParams.ReturnRoutes = true; // add route stops as parameters try { routeParams.SetStops(new List <Stop>() { new Stop(FromPlace.RouteLocation), new Stop(ToPlace.RouteLocation) }); Route = await Router.SolveRouteAsync(routeParams); // Set the AOI to an area slightly larger than the route's extent var aoiBuilder = new EnvelopeBuilder(Route.Routes.FirstOrDefault()?.RouteGeometry.Extent); aoiBuilder.Expand(1.2); AreaOfInterest = new Viewpoint(aoiBuilder.ToGeometry()); // Set turn by turn directions DirectionManeuvers = Route.Routes.FirstOrDefault()?.DirectionManeuvers; } catch (ArcGISWebException e) { // This is returned when user hits the Cancel button in iOS or the back arrow in Android // It does not get caught in the SignInRenderer and needs to be handled here if (e.Message.Contains("Token Required")) { FromPlace = null; ToPlace = null; IsBusy = false; return; } ErrorMessage = "A web exception occured. Are you connected to the internet?"; StackTrace = e.ToString(); } catch (Exception ex) { //TODO: Remove workaround when iOS bug is fixed #if __IOS__ exceptionCounter++; if (ex.Message == "403 (Forbidden)" && exceptionCounter <= 3) { await GetRouteAsync(); return; } #endif ErrorMessage = "Something went wrong and the routing operation failed."; StackTrace = ex.ToString(); } exceptionCounter = 0; IsBusy = false; }
private async void Initialize() { // Set paths that are relative to execution path string currentDir = Directory.GetCurrentDirectory(); int idx = currentDir.IndexOf("bin") - 1; appRootDir = currentDir.Substring(0, idx); appDataDir = appRootDir + @"\Data"; appTempDir = appRootDir + @"\temp"; // Set up files testImage = appDataDir + @"\sampleFile.tiff"; gpPackage = appDataDir + @"\CreateMapTilePackage.gpkx"; mapPackage = appDataDir + @"\emptyMapPackage.mpkx"; Debug.WriteLine(">> App Root Directory = " + appRootDir); Debug.WriteLine(">> App Data Directory = " + appDataDir); Debug.WriteLine(">> App Temp Directory = " + appTempDir); ////////////// start Q Basket set up ////////////////// // Create raster layer from a raster file (Geotiff) Debug.WriteLine("Loading raster layer from " + testImage); RasterLayer inRasterLayer = new RasterLayer(testImage); // Load Raster into Raster Layer try { await inRasterLayer.LoadAsync(); if (inRasterLayer.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded) { Debug.WriteLine("Error - Input Raster Layer not loaded "); } } catch (Exception ex) { string msg = "Unable to load the raster\n"; msg += "Raster file = " + testImage; msg += "Load status = " + inRasterLayer.LoadStatus.ToString(); msg += "\n\nMessage: " + ex.Message; MessageBox.Show(msg, "inRasterLayer.LoadAsync failed"); } // Create a new EnvelopeBuilder from the full extent of the raster layer. // Add a small zoom to make sure entire map is viewable EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(inRasterLayer.FullExtent); envelopeBuilder.Expand(0.75); // Create a basemap from the raster layer Basemap baseMap = new Basemap(inRasterLayer); // Create a new map using the new basemap Map newMap = new Map(baseMap); // Set the viewpoint of the map to the proper extent. newMap.InitialViewpoint = new Viewpoint(envelopeBuilder.ToGeometry().Extent); // Create a map and add it to the view MyMapView.Map = newMap; // Load new map to display basemap try { // Add map to the map view. MyMapView.Map = newMap; // Wait for the map to load. await newMap.LoadAsync(); } catch (Exception ex) { string msg = "Unable to load the Map\n"; msg += "\n\nMessage: " + ex.Message; MessageBox.Show(msg, "newMap.LoadAsync failed"); } // Wait for rendering to finish before taking the screenshot for the thumbnail await WaitForRenderCompleteAsync(MyMapView); ////////////// end Q Basket set up ////////////////// // Start the Local Server try { // LocalServer must not be running when setting the data path. if (LocalServer.Instance.Status == LocalServerStatus.Started) { await LocalServer.Instance.StopAsync(); } // Set the local data path - must be done before starting. // Avoid Windows path length limitations (260). // CreateDirectory won't overwrite if it already exists. Directory.CreateDirectory(appTempDir); LocalServer.Instance.AppDataPath = appTempDir; // Start the local server instance await LocalServer.Instance.StartAsync(); MessageBox.Show("Local Server started"); Debug.WriteLine(">> Local Server started"); // Get the URL for the localServer // localhost port is variable localServerURL = LocalServer.Instance.Url.AbsoluteUri; Debug.WriteLine("\n>> Local server url - " + localServerURL); Debug.WriteLine(">> Local server App Data Path - " + LocalServer.Instance.AppDataPath); } catch (Exception ex) { string msg = "Please ensure the local server is installed \nand configured correctly"; msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "Local Server failed to start"); Debug.WriteLine(msg); App.Current.Shutdown(); } // LOCAL MAP SERVICE INIT // Create and start the local map service try { _localMapService = new LocalMapService(mapPackage); } catch (Exception ex) { string msg = "Cannot create the local map service"; msg += "Map Package = " + mapPackage; msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "Local Map Server failed to start"); Debug.WriteLine(msg); App.Current.Shutdown(); } // RASTER WORKSPACE CREATION // Create the Raster workspace; this workspace name was chosen arbitrarily // Does workspace need to be the same directory as rasters? // setting to temp directory rasterWorkspace = new RasterWorkspace("raster_wkspc", appTempDir); Debug.WriteLine(">> raster workspace folder = " + rasterWorkspace.FolderPath); Debug.WriteLine(">> raster workspace id = " + rasterWorkspace.Id); // Create the layer source that represents the Raster on disk RasterSublayerSource source = new RasterSublayerSource(rasterWorkspace.Id, testImage); // Create a sublayer instance from the table source _rasterSublayer = new ArcGISMapImageSublayer(0, source); // Add the dynamic workspace to the map service _localMapService.SetDynamicWorkspaces(new List <DynamicWorkspace>() { rasterWorkspace }); // Register map service status chagne event handle _localMapService.StatusChanged += _localMapService_StatusChanged; // Start the map service try { await _localMapService.StartAsync(); } catch (Exception ex) { string msg = "Cannot start the local map service"; msg += "Map Package = " + mapPackage; msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "Local Map Server failed to start"); Debug.WriteLine(msg); App.Current.Shutdown(); } // Get the url to the local map service localMapServiceURL = _localMapService.Url.AbsoluteUri; MessageBox.Show("Local Map Service URL = " + localMapServiceURL); Debug.WriteLine("Local Map Service URL = " + localMapServiceURL); // LOCAL GEOPROCESSING SERVICE INIT // Create the geoprocessing service _localGPservice = new LocalGeoprocessingService(gpPackage, gpServiceType); // Ass GP service status chagned event handler _localGPservice.StatusChanged += GpServiceOnStatusChanged; // Try to start the service try { // Start the service await _localGPservice.StartAsync(); if (_localGPservice.Status == LocalServerStatus.Failed) { string msg = ("Geoprocessing service failed to start.\n"); MessageBox.Show(msg, "gpService.StartAsync failed"); App.Current.Shutdown(); } else if (_localGPservice.Status == LocalServerStatus.Started) { localGPserviceUrl = _localGPservice.Url.AbsoluteUri + "/CreateMapTilePackage"; string msg = ("Geoprocessing service started.\n"); msg += "\n>> GP Service URL: " + localGPserviceUrl; msg += ">> GP Service Max Records: " + _localGPservice.MaxRecords; msg += ">> GP Service Package Path: " + _localGPservice.PackagePath; msg += ">> GP Service Type: " + _localGPservice.ServiceType; MessageBox.Show(msg, "gpService.StartAsync started"); Debug.WriteLine("\n>> GP Service URL: " + localGPserviceUrl); Debug.WriteLine(">> GP Service Max Records: " + _localGPservice.MaxRecords); Debug.WriteLine(">> GP Service Package Path: " + _localGPservice.PackagePath); Debug.WriteLine(">> GP Service Type: " + _localGPservice.ServiceType); } } catch (Exception ex) { string msg = ("Geoprocessing service failed to start.\n"); msg += "\nGeoprocessing package - " + gpPackage + "\n"; msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "gpService.StartAsync failed"); return; } // GEOPROCESSING TASK INIT // Create the geoprocessing task from the service try { string url = _localGPservice.Url + "/CreateMapTilePackage"; _gpTask = await GeoprocessingTask.CreateAsync(new Uri(url)); } catch (Exception ex) { string msg = ("Geoprocessing task failed to start.\n"); msg += "\nlocalGPserviceUrl- " + localGPserviceUrl + "\n"; msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "GeoprocessingTask.CreateAsync failed"); return; } MessageBox.Show("GeoprocessingTask.CreateAsync created"); // GEOPROCESSING JOB // Create the geoprocessing parameters GeoprocessingParameters gpParams = new GeoprocessingParameters(gpExecutionType); // Add the interval parameter to the geoprocessing parameters //GeoprocessingString Input_Map = new GeoprocessingString("MyMapView.Map"); GeoprocessingString Input_Map = new GeoprocessingString("localMapServiceURL"); GeoprocessingDouble Max_LOD = new GeoprocessingDouble(10); GeoprocessingString Output_Package = new GeoprocessingString("C://Karen/Data/TilePackages/test.tpkx"); gpParams.Inputs.Add("Input_Map", Input_Map); gpParams.Inputs.Add("Max_LOD", Max_LOD); gpParams.Inputs.Add("Output_Package", Output_Package); // Create the job try { _gpJob = _gpTask.CreateJob(gpParams); } catch (Exception ex) { string msg = ("Geoprocessing job cannot be created.\n"); msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "_gpTask.CreateJob failed"); return; } MessageBox.Show("GeoprocessingTask.CreateJob created"); MyLoadingIndicator.Visibility = Visibility.Visible; // Update the UI when job progress changes _gpJob.ProgressChanged += (sender, args) => { Dispatcher.Invoke(() => { MyLoadingIndicator.Value = _gpJob.Progress; }); }; // Be notified when the task completes (or other change happens) _gpJob.JobChanged += GpJobOnJobChanged; // Start the job try { _gpJob.Start(); } catch (Exception ex) { string msg = ("Geoprocessing start job failed to start.\n"); msg += String.Format("\nMessage: {0}", ex.Message); MessageBox.Show(msg, "_gpjob.Start failed"); return; } MessageBox.Show("GeoprocessingTask job started"); }
// Initialize creates the Map objects, assigns rasters, and creates bookmarks private async void Initialize() { // add imagery basemap to both scenes Scene BeforeMap = new Scene(Basemap.CreateImageryWithLabels()); Scene AfterMap = new Scene(Basemap.CreateImageryWithLabels()); // wait for scenes to load await BeforeMap.LoadAsync(); await AfterMap.LoadAsync(); // Assigns Scene objects to View NaturalDisasterBefore.Scene = BeforeMap; NaturalDisasterAfter.Scene = AfterMap; // List containing paths to each "before" raster string[] beforeimages; String fpath = Path.Combine(Directory.GetCurrentDirectory(), "BeforeImages\\"); beforeimages = Directory.GetFiles(fpath, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray(); // List containing paths to each "after" raster string[] afterimages; String fpath2 = Path.Combine(Directory.GetCurrentDirectory(), "AfterImages\\"); afterimages = Directory.GetFiles(fpath2, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray(); // Iterate through "before" raster list and add each one to the BeforeMap foreach (var item in beforeimages) { // specify filepath to raster location string filepath = Path.Combine(Directory.GetCurrentDirectory(), "BeforeImages\\" + item); // Load the raster file Raster myRasterFile = new Raster(filepath); // Create the layer RasterLayer myRasterLayer = new RasterLayer(myRasterFile); // Add the layer and bookmark to the map BeforeMap.OperationalLayers.Add(myRasterLayer); // Wait for the layer to load await myRasterLayer.LoadAsync(); //Creates an envelope for the current Raster var rasterGeometry = myRasterLayer.FullExtent; EnvelopeBuilder newEnvelope = new EnvelopeBuilder(rasterGeometry); newEnvelope.Expand(1.5); // Creates an envelope for comparison to bookmark location EnvelopeBuilder textEnvelope = new EnvelopeBuilder(rasterGeometry); textEnvelope.Expand(2.5); var xMax = newEnvelope.XMax; var yMax = newEnvelope.YMax; var xMin = newEnvelope.XMin; var yMin = newEnvelope.YMin; var spatialreference = newEnvelope.SpatialReference; // Converts newEnvelope to a geometry object that can be read as a Viewpoint Envelope rasterEnvelope = new Envelope(xMin, yMin, xMax, yMax, spatialreference); // Create Bookmark location and name for current raster // Raster needs spatial reference to load try { if (rasterEnvelope.SpatialReference != null) { Viewpoint viewpoint = new Viewpoint(rasterEnvelope); Bookmark bookmark = new Bookmark { Name = Path.GetFileNameWithoutExtension(item), Viewpoint = viewpoint }; NaturalDisasterBefore.Scene.Bookmarks.Add(bookmark); BookmarkChooser.Items.Add(bookmark); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } // Iterate through "after" raster list and add each one to the AfterMap // Same as the one for the BeforeMap foreach (var item in afterimages) { // specify filepath to raster location string filepath = Path.Combine(Directory.GetCurrentDirectory(), "AfterImages\\" + item); // Load the raster file Raster myRasterFile = new Raster(filepath); // Create the layer RasterLayer myRasterLayer = new RasterLayer(myRasterFile); // Add the layer and bookmark to the map AfterMap.OperationalLayers.Add(myRasterLayer); // Wait for the layer to load await myRasterLayer.LoadAsync(); } }