public async Task Initialize() { // Clear any existing items. Items.Clear(); // Get the data folder. string filepath = OfflineDataStorageHelper.GetDataFolder(); foreach (string subDirectory in Directory.GetDirectories(filepath)) { try { // Note: the downloaded map packages are stored as *unpacked* mobile map packages. var mmpk = await MobileMapPackage.OpenAsync(subDirectory); if (mmpk?.Item != null) { Items.Add(new PortalItemViewModel(mmpk.Item)); } } catch (Exception) { // Ignored - not a valid map package } } }
private async void AddSMPLocator_Click(object sender, RoutedEventArgs e) { // NOTE: You can download a sample of StreetMap Premium for testing purposes by visiting the downloads section of the ArcGIS Developer dashboard. string path = LocatorPathText.Text; if (!File.Exists(path)) { MessageBox.Show("Error", "Input Path Does Not Exist"); return; } try { MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(path); if (mmpk.LocatorTask is LocatorTask packagedLocator) { MySearchView.SearchViewModel.Sources.Add(new LocatorSearchSource(packagedLocator)); } } catch (Exception ex) { MessageBox.Show("Error", ex.Message); } }
/// <summary> /// Loads the Mobile Map Package and creates single instance of the AppViewModel /// </summary> /// <returns>Async task</returns> private async Task LoadMmpkAsync() { // Open mmpk if it exists // If no mmpk is found, alert the user and shut down the application var mmpkFullPath = Path.Combine(Settings.Default.DownloadPath, Settings.Default.MmpkFileName); if (File.Exists(mmpkFullPath)) { try { var mmpk = await MobileMapPackage.OpenAsync(mmpkFullPath); AppViewModel.Instance.Mmpk = mmpk; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "Error opening map", MessageBoxButton.OK, MessageBoxImage.Error); } } else { System.Windows.MessageBox.Show( "Map could not be downloaded and no locally stored map was found. Application will now exit. Please restart application to re-try the map download", "No Map Found", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } // Set data context for the main screen and load main screen this.DataContext = AppViewModel.Instance; AppViewModel.Instance.DisplayViewModel = new MainViewModel(); }
private async Task <MobileMapPackage> OpenMobileMapPackage(string path) { // Load directly or unpack then load as needed by the map package. if (await MobileMapPackage.IsDirectReadSupportedAsync(path)) { // Open the map package. MobileMapPackage package = await MobileMapPackage.OpenAsync(path); // Load the package. await package.LoadAsync(); // Return the opened package. return(package); } else { // Create a path for the unpacked package. string unpackedPath = path + "unpacked"; // Unpack the package. await MobileMapPackage.UnpackAsync(path, unpackedPath); // Open the package. MobileMapPackage package = await MobileMapPackage.OpenAsync(unpackedPath); // Load the package. await package.LoadAsync(); // Return the opened package. return(package); } }
private async Task CheckOfflineMapArea() { if (!Directory.Exists(OfflineMapAreaFolder)) { Directory.CreateDirectory(OfflineMapAreaFolder); } if (Directory.EnumerateFiles(OfflineMapAreaFolder).Any()) { try { var mmpk = await MobileMapPackage.OpenAsync(OfflineMapAreaFolder); DownloadMapAreaStatusLabel.Text = "Offline Map Area: Download complete."; DownloadMapAreaStatusLabel.TextColor = Color.Green; _offlineMapArea = mmpk.Maps.First(); Device.BeginInvokeOnMainThread(() => { OfflineMapAreaButton.IsEnabled = false; ActivateMapAreaButton.IsEnabled = true; }); } catch (Exception) { Directory.Delete(OfflineMapAreaFolder, true); } } }
private async void OpenMMPK1() { // Mobile map package to open directly from a package or an unpacked folder. MobileMapPackage mobileMapPackage; // Check whether the mobile map package supports direct read. bool isDirectReadSupported = await MobileMapPackage.IsDirectReadSupportedAsync(pathToOutputPackage); if (isDirectReadSupported) { // If it does, create the mobile map package directly from the .mmpk file. mobileMapPackage = await MobileMapPackage.OpenAsync(pathToOutputPackage); } else { // Otherwise, unpack the mobile map package file into a directory. await MobileMapPackage.UnpackAsync(pathToOutputPackage, pathToUnpackedPackage); // Create the mobile map package from the unpack directory. mobileMapPackage = await MobileMapPackage.OpenAsync(pathToUnpackedPackage); } // Make sure there is at least one map, then add the first map in the package to the map view. if (mobileMapPackage.Maps.Count > 0) { Map myMap = mobileMapPackage.Maps.First(); MyMapView.Map = myMap; } }
private async void ViewButton_Click(object sender, RoutedEventArgs e) { originPoint = null; //Change button to 2D or 3D when button is clicked ViewButton.Content = FindResource(ViewButton.Content == FindResource("3D") ? "2D" : "3D"); if (ViewButton.Content == FindResource("2D")) { threeD = true; if (myScene == null) { //Create a new scene myScene = new Scene(Basemap.CreateNationalGeographic()); sceneView.Scene = myScene; // create an elevation source var elevationSource = new ArcGISTiledElevationSource(new System.Uri(ELEVATION_IMAGE_SERVICE)); // create a surface and add the elevation surface var sceneSurface = new Surface(); sceneSurface.ElevationSources.Add(elevationSource); // apply the surface to the scene sceneView.Scene.BaseSurface = sceneSurface; //Exercise 3: Open mobie map package (.mmpk) and add its operational layers to the scene var mmpk = await MobileMapPackage.OpenAsync(MMPK_PATH); if (mmpk.Maps.Count >= 0) { myMap = mmpk.Maps[0]; LayerCollection layerCollection = myMap.OperationalLayers; for (int i = 0; i < layerCollection.Count(); i++) { var thelayer = layerCollection[i]; myMap.OperationalLayers.Clear(); myScene.OperationalLayers.Add(thelayer); sceneView.SetViewpoint(myMap.InitialViewpoint); //Rotate the camera Viewpoint viewpoint = sceneView.GetCurrentViewpoint(ViewpointType.CenterAndScale); Esri.ArcGISRuntime.Geometry.MapPoint targetPoint = (MapPoint)viewpoint.TargetGeometry; Camera camera = sceneView.Camera.RotateAround(targetPoint, 45.0, 65.0, 0.0); await sceneView.SetViewpointCameraAsync(camera); } sceneView.Scene = myScene; bufferAndQuerySceneGraphics.SceneProperties.SurfacePlacement = SurfacePlacement.Draped; sceneView.GraphicsOverlays.Add(bufferAndQuerySceneGraphics); sceneRouteGraphics.SceneProperties.SurfacePlacement = SurfacePlacement.Draped; sceneView.GraphicsOverlays.Add(sceneRouteGraphics); } } //Exercise 1 Once the scene has been created hide the mapView and show the sceneView mapView.Visibility = Visibility.Hidden; sceneView.Visibility = Visibility.Visible; } else { threeD = false; sceneView.Visibility = Visibility.Hidden; mapView.Visibility = Visibility.Visible; } }
private async void Initialize() { // The mobile map package will be downloaded from ArcGIS Online // The data manager (a component of the sample viewer, *NOT* the runtime // handles the offline data process // The desired MMPK is expected to be called Yellowstone.mmpk string filename = "Yellowstone.mmpk"; // The data manager provides a method to get the folder string folder = DataManager.GetDataFolder(); // Get the full path string filepath = Path.Combine(folder, "SampleData", "OpenMobileMap", filename); // Check if the file exists if (!File.Exists(filepath)) { // Download the map package file await DataManager.GetData("e1f3a7254cb845b09450f54937c16061", "OpenMobileMap"); } // Open the map package MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath); // Check that there is at least one map if (myMapPackage.Maps.Count > 0) { // Display the first map in the package _myMapView.Map = myMapPackage.Maps.First(); } }
public async void Initialize() { // ライセンスキーを登録して Lite ライセンスの認証を行う string licenseKey = "xxxx"; ArcGISRuntimeEnvironment.SetLicense(licenseKey); MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(@"..\..\..\..\SampleData\sample_maps.mmpk"); // マップ ビューの持つ Map プロパティにモバイル マップ パッケージが持つマップを割り当てる MyMapView.Map = myMapPackage.Maps.First(); // 背景に ArcGIS Online の衛星画像サービスを表示する MyMapView.Map.Basemap = Basemap.CreateImagery(); // マップのレイヤーを取得してレイヤーの透過率を設定 MyMapView.Map.OperationalLayers[0].Opacity = 0.5; // マップのスケール範囲を設定 MyMapView.Map.MinScale = 5000000; MyMapView.Map.MaxScale = 5000; // マップに追加されているレイヤーの一覧取得 TreeViewMultipleTemplatesSample(); // マップ ビューのタップイベント MyMapView.GeoViewTapped += MyMapView_GeoViewTapped; }
public async Task ConfigureStreetMapPremium() { // Open the mmpk file string path = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Canada_Quebec.mmpk"); try { // Load the package. MobileMapPackage streetMapPremiumPackage = await MobileMapPackage.OpenAsync(path); // Get the first Map. Map caliMap = streetMapPremiumPackage.Maps.First(); // Load the map; transportation networks aren't available until the map is loaded await caliMap.LoadAsync(); // Get the first network _transportationNetwork = caliMap.TransportationNetworks.First(); // Set the initial viewPoint caliMap.InitialViewpoint = new Viewpoint(_latitude, _longitude, _scale); // Update the map in use this.Map = caliMap; _mapView.Map = Map; MapView.LocationDisplay.IsEnabled = true; MapView.LocationDisplay.LocationChanged += OnLocationChanged; } catch (Exception e) { MessageBox.Show(e.Message, "Error opening package"); return; } }
private async void OnDeleteAllMapAreasClicked(object sender, RoutedEventArgs e) { // Show the map area deletion UI. DownloadNotificationText.Visibility = Visibility.Collapsed; ProgressBar.IsIndeterminate = true; BusyText.Text = "Deleting downloaded map areas..."; BusyIndicator.Visibility = Visibility.Visible; // If there is a map loaded, remove it. if (MyMapView.Map != null) { // Clear the layers. This will ensure that their resources are freed. MyMapView.Map.OperationalLayers.Clear(); MyMapView.Map = null; } // Ensure the map and related resources (for example, handles to geodatabases) are cleared. // This is important on Windows where open files can't be deleted. GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); try { // Find all downloaded offline areas from the sample folder. List <string> downloadedPackagePaths = Directory.GetDirectories(_offlineDataFolder).ToList(); foreach (string packagePath in downloadedPackagePaths) { MobileMapPackage downloadedAreaPackage = await MobileMapPackage.OpenAsync(packagePath); if (!downloadedAreaPackage.Maps.Any()) { // Delete temporary data folder from potential stray folders. Directory.Delete(_offlineDataFolder, true); } else { // Unregister all geodatabases and delete the package. await UnregisterAndRemoveMobileMapPackage(downloadedAreaPackage); } } } catch (Exception ex) { // Report error accessing a resource. MessageDialog message = new MessageDialog(ex.Message, "Deleting map areas failed"); await message.ShowAsync(); } finally { // Reset the UI. DownloadNotificationText.Visibility = Visibility.Visible; MyMapView.Visibility = Visibility.Collapsed; BusyIndicator.Visibility = Visibility.Collapsed; PreplannedAreasList.SelectedItem = null; } }
public async void Initialize() { MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(@"..\..\..\..\SampleData\sample_maps.mmpk"); // マップ ビューの持つ Map プロパティにモバイル マップ パッケージが持つマップを割り当てる MyMapView.Map = myMapPackage.Maps.First(); // マップのレイヤーを取得してレイヤーの透過率を設定 MyMapView.Map.OperationalLayers[0].Opacity = 0.5; }
private async void OfflineMapTaskButton_Click(object sender, RoutedEventArgs e) { string pathToOutputPackage = @"C:\My Documents\Readiness\Trainings\Runtime 100.1\Demos\OfflineMap"; // Create a mobile map package from the offline map MobileMapPackage offlineMapPackage = await MobileMapPackage.OpenAsync(pathToOutputPackage); // Get the map from the package and set it to the MapView var map = offlineMapPackage.Maps.First(); MyMapView.Map = map; }
private async Task <MobileMapPackage> OpenMobileMapPackage(string path) { // Open the map package. MobileMapPackage package = await MobileMapPackage.OpenAsync(path); // Load the package. await package.LoadAsync(); // Return the opened package. return(package); }
/// <summary> /// Adds a MMPK map source. /// </summary> /// <param name="fileName">the MMPK file</param> /// <returns>the opened MMPK</returns> public async Task <MobileMapPackage> AddMMPKAsync(string fileName) { List <Map> maps = new List <Map>(); MobileMapPackage mmpk = null; if (!this.HasLayerFileSource(fileName)) { LayerFileSource lfs = new LayerFileSource(); lfs.SourceFile = fileName; this.LayerFileSources.Add(lfs); mmpk = await MobileMapPackage.OpenAsync(fileName); await mmpk.LoadAsync(); foreach (Map aMap in mmpk.Maps) { maps.Add(aMap); var layerCollection = aMap.OperationalLayers.Reverse(); await aMap.LoadAsync(); Trace.WriteLine("Map = " + aMap.ToString()); foreach (var layer in layerCollection) { Layer lyr = layer.Clone(); lyr.IsVisible = layer.IsVisible; //if (layer.Opacity == 1) // layer.Opacity = .55; lyr.Opacity = layer.Opacity; await lyr.LoadAsync(); if (lyr is FeatureLayer) { TesterLayer testLayer = new TesterLayer(); FeatureLayer featLyr = lyr as FeatureLayer; GeodatabaseFeatureTable featureTable = featLyr.FeatureTable as GeodatabaseFeatureTable; testLayer.FeatureTable = featureTable; testLayer.FeatureLayer = featLyr; lfs.Children.Add(testLayer); ((FeatureLayer)lyr).LabelsEnabled = true; ((FeatureLayer)lyr).DefinitionExpression = ((FeatureLayer)layer).DefinitionExpression; } else if (lyr is GroupLayer) { SetupLayersUnderGroupLayer((GroupLayer)lyr, (GroupLayer)layer, lfs); } this.Map.OperationalLayers.Add(lyr); } } } return(mmpk); }
private async void OpenPackage_Click(object sender, RoutedEventArgs e) { // Create a mobile map package from an unpacked map package folder. MobileMapPackage offlineMapPackage = await MobileMapPackage.OpenAsync(pathToOutputPackage); // Set the title from the package metadata to the UI // Get the map from the package and set it to the MapView var map = offlineMapPackage.Maps.First(); MyMapView.Map = map; }
/// <summary> /// Loads the MMPK from the location on disk /// </summary> /// <returns>The MMPKA sync.</returns> private async Task <MobileMapPackage> LoadMMPKAsync() { try { var mmpk = await MobileMapPackage.OpenAsync(Path.Combine(DownloadViewModel.GetDataFolder(), AppSettings.CurrentSettings.PortalItemName)); return(mmpk); } catch { return(null); } }
private async void CreateMMPKLayer() { // Path to MMPK string sPath_mobile = parent.FullName + "\\MMPK\\NewZealand.mmpk"; // Open MMPK asynchrously and store in map objects MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(sPath_mobile); _map1 = mmpk.Maps[0]; _map2 = mmpk.Maps[1]; // Add maps to the MapView MyMapView.Map = _map1; MyMapView.Map = _map2; }
private async void Initialize() { // Get the path to the mobile map package string filepath = GetMmpkPath(); // Open the map package MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath); // Check that there is at least one map if (myMapPackage.Maps.Count > 0) { // Display the first map in the package _myMapView.Map = myMapPackage.Maps.First(); } }
private async void Initialize() { // Get the path to the mobile map package. string filepath = DataManager.GetDataFolder("e1f3a7254cb845b09450f54937c16061", "Yellowstone.mmpk"); // Open the map package. MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath); // Check that there is at least one map. if (myMapPackage.Maps.Count > 0) { // Display the first map in the package. _myMapView.Map = myMapPackage.Maps.First(); } }
private async void SetMap() { try { var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var path = Directory.EnumerateFiles(localFolder, "*.mmpk").FirstOrDefault(); if (path == null) { using (var fos = File.Create(Path.Combine(localFolder, "map.mmpk"))) using (var fis = this.GetType().Assembly.GetManifestResourceStream("MmpkTest.Yellowstone.mmpk")) { fis.CopyTo(fos); } path = Directory.EnumerateFiles(localFolder, "*.mmpk").FirstOrDefault(); } if (path != null && File.Exists(path)) { var mmpk = await MobileMapPackage.OpenAsync(path); TheMap.Map = mmpk.Maps.First(); Map = TheMap.Map; } else { var stack = new StackLayout() { Margin = 40 }; stack.Children.Add(new Label() { Text = "Mobile Map Package not found. Please place an mmpk (any file name that ends in .mmpk) and restart this app." }); this.Content = stack; } } catch (Exception e) { var stack = new StackLayout() { Margin = 40 }; stack.Children.Add(new Label() { Text = e.ToString() }); this.Content = stack; } }
private async void OpenMMPK() { var filepath = mapClass.Filepath; Basemap heatBase = Basemap.CreateImageryWithLabels(); try { // Load directly or unpack then load as needed by the map package. if (await MobileMapPackage.IsDirectReadSupportedAsync(filepath)) { // Open the map package. MobileMapPackage heatMap = await MobileMapPackage.OpenAsync(filepath); Map HeatVulnerabilityMap = heatMap.Maps.First(); // Check for map in .mmpk and give to corresponding views if (heatMap.Maps.Count > 0) { HeatVuln.Map = HeatVulnerabilityMap; HeatVuln.Map.Basemap = heatBase; HeatVuln.Map.OperationalLayers[0].IsVisible = false; // Avg Temp / Daily Heating HeatVuln.Map.OperationalLayers[1].IsVisible = false; // Impervous Surfaces HeatVuln.Map.OperationalLayers[2].IsVisible = false; // Tree Canopy HeatVuln.Map.OperationalLayers[3].IsVisible = true; // Heat Vulnerability HeatVuln.Map.OperationalLayers[4].IsVisible = false; // Richmond Poverty } } else { // Create a path for the unpacked package. string unpackedPath = filepath + "unpacked"; // Unpack the package. await MobileMapPackage.UnpackAsync(filepath, unpackedPath); // Open the package. MobileMapPackage package = await MobileMapPackage.OpenAsync(unpackedPath); // Load the package. await package.LoadAsync(); } } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString(), "Error"); } }
public async void Initialize() { MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(@"..\..\..\..\SampleData\sample_maps.mmpk"); // マップ ビューの持つ Map プロパティにモバイル マップ パッケージが持つマップを割り当てる MyMapView.Map = myMapPackage.Maps.First(); // 背景に ArcGIS Online の衛星画像サービスを表示する MyMapView.Map.Basemap = Basemap.CreateImagery(); // マップのレイヤーを取得してレイヤーの透過率を設定 MyMapView.Map.OperationalLayers[0].Opacity = 0.5; // マップのスケール範囲を設定 MyMapView.Map.MinScale = 5000000; MyMapView.Map.MaxScale = 5000; // マップ ビューのタップイベント MyMapView.GeoViewTapped += MyMapView_GeoViewTapped; }
private async void OnDeleteAllMapAreasClicked(object sender, EventArgs e) { // Show the deletion UI. View.AddSubview(_progressIndicator); _progressIndicator.UpdateMessageAndProgress("Deleting downloaded map areas", -1); // If there is a map loaded, remove it. if (_myMapView.Map != null) { _myMapView.Map = null; } try { // Find all downloaded offline areas from the sample folder. List <string> downloadedPackagePaths = Directory.GetDirectories(_offlineDataFolder).ToList(); foreach (string packagePath in downloadedPackagePaths) { MobileMapPackage downloadedAreaPackage = await MobileMapPackage.OpenAsync(packagePath); if (!downloadedAreaPackage.Maps.Any()) { // Delete temporary data folder from potential stray folders. Directory.Delete(_offlineDataFolder, true); } else { // Unregister all geodatabases and delete the package. await UnregisterAndRemoveMobileMapPackage(downloadedAreaPackage); } } } catch (Exception ex) { // Report the error. UIAlertController alertController = UIAlertController.Create("Deleting map areas failed.", ex.Message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); } finally { // Reset the UI. _progressIndicator.RemoveFromSuperview(); } }
public async void init() { try { MobileMapPackage offlineMapPackage = await MobileMapPackage.OpenAsync("C:/TEMPCD"); // Get the map from the package and set it to the MapView var map = offlineMapPackage.Maps.First(); Map = map; } catch (Exception e) { ArcGISPortal portal = await ArcGISPortal.CreateAsync(); // Get a web map item using its ID. PortalItem webmapItem = await PortalItem.CreateAsync(portal, "a72f2553da664a41b5f00583f7780206"); // Create a map from the web map item. _map = new Map(webmapItem); Map = _map; // Create an OfflineMapTask from the map ... OfflineMapTask takeMapOfflineTask = await OfflineMapTask.CreateAsync(_map); // ... or a web map portal item. // Create the default parameters for the task, pass in the area of interest. GenerateOfflineMapParameters parameters = await takeMapOfflineTask.CreateDefaultGenerateOfflineMapParametersAsync(new Envelope(375474, 120000, 422020, 152000, new SpatialReference(26985))); // Create the job with the parameters and output location. var _generateOfflineMapJob = takeMapOfflineTask.GenerateOfflineMap(parameters, "C:/TEMPCD"); // Handle the progress changed event for the job. // _generateOfflineMapJob.ProgressChanged += OfflineMapJob_ProgressChanged; // Await the job to generate geodatabases, export tile packages, and create the mobile map package. GenerateOfflineMapResult results = await _generateOfflineMapJob.GetResultAsync(); Map = results.OfflineMap; } }
private async void Initialize() { //Exercise 1: Create new Map with basemap and initial location myMap = new Map(Basemap.CreateNationalGeographic()); //Exercise 1: Assign the map to the MapView mapView.Map = myMap; //Exercise 3: Add mobile map package to the map var mmpk = await MobileMapPackage.OpenAsync(MMPK_PATH); if (mmpk.Maps.Count >= 0) { myMap = mmpk.Maps[0]; //Exercise 3: Mobile map package does not contain a basemap so must add one. myMap.Basemap = Basemap.CreateNationalGeographic(); mapView.Map = myMap; } }
internal static async Task <List <MapArea> > GetMapAreasAsync(string mapId) { ArcGISPortal arcGISOnline = await ArcGISPortal.CreateAsync(); var portalItem = await PortalItem.CreateAsync(arcGISOnline, mapId); var offlineTask = await OfflineMapTask.CreateAsync(portalItem); var mapAreas = await offlineTask.GetPreplannedMapAreasAsync(); var model = new List <MapArea>(); foreach (PreplannedMapArea mapArea in mapAreas) { await mapArea.LoadAsync(); PortalItem preplannedMapItem = mapArea.PortalItem; var thumbnail = await preplannedMapItem.Thumbnail.ToImageSourceAsync(); var path = MapAreaManager.GetOfflineMapPath(preplannedMapItem.ItemId); var offlineMapPackage = default(MobileMapPackage); try { offlineMapPackage = await MobileMapPackage.OpenAsync(path); } catch (FileNotFoundException) { /* this is expected when the map has not been downloaded yet */ } model.Add(new MapArea() { Id = preplannedMapItem.ItemId, Title = preplannedMapItem.Title, Thumbnail = thumbnail, Snippet = preplannedMapItem.Snippet, Payload = mapArea, OfflineTask = offlineTask, IsDownloaded = (offlineMapPackage != null), IsDownloading = false }); } return(model); }
private async void OpenMapArea_Click(object sender, RoutedEventArgs e) { string areaId = ((Button)sender)?.Tag?.ToString(); if (string.IsNullOrWhiteSpace(areaId)) { return; //TODO: Log this } var area = this.ViewModel.MapAreasRaw.FirstOrDefault(m => m.Id == areaId); var path = MapAreaManager.GetOfflineMapPath(areaId); MobileMapPackage offlineMapPackage = await MobileMapPackage.OpenAsync(path); var parameters = new MapParameters() { Map = offlineMapPackage.Maps.FirstOrDefault() }; this.Frame.Navigate(typeof(MapViewer), parameters); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); Item item = _mainVM.SelectedItem.Item; try { Map map; if (item is LocalItem localItem) { // This logic is quite brittle and only valid for MMPKs created as a result of // taking a map offline with this app. string mmpkPath = localItem.Path; var mmpk = await MobileMapPackage.OpenAsync(mmpkPath); // Get the first map. map = mmpk.Maps.First(); } else { map = new Map(_mainVM.SelectedItem.Item as PortalItem); } await map.LoadAsync(); if (map.LoadStatus != LoadStatus.Loaded) { throw new Exception("Map couldn't be loaded."); } ViewModel.Initialize(map, _mainVM.SelectedItem); } catch (Exception exception) { Debug.WriteLine(exception); this.Frame.GoBack(); await new MessageDialog("Couldn't load map.", "Error").ShowAsync(); } }
private async void Initialize() { // Get the path to the mobile map package. string filepath = DataManager.GetDataFolder("e1f3a7254cb845b09450f54937c16061", "Yellowstone.mmpk"); try { // Open the map package. MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath); // Load the package. await myMapPackage.LoadAsync(); // Display the first map in the package. _myMapView.Map = myMapPackage.Maps.First(); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }