Example #1
0
        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);
            }
        }
Example #2
0
        private async void ApplyUpdates()
        {
            try
            {
                // Create default sync parameters.
                OfflineMapSyncParameters parameters = await _offlineMapSyncTask.CreateDefaultOfflineMapSyncParametersAsync();

                // Set the parameters to download all updates for the mobile map packages.
                parameters.PreplannedScheduledUpdatesOption = PreplannedScheduledUpdatesOption.DownloadAllUpdates;

                // Set the map package to rollback to the old state should the sync job fail.
                parameters.RollbackOnFailure = true;

                // Create a sync job using the parameters.
                OfflineMapSyncJob offlineMapSyncJob = _offlineMapSyncTask.SyncOfflineMap(parameters);

                // Get the results of the job.
                offlineMapSyncJob.Start();
                OfflineMapSyncResult result = await offlineMapSyncJob.GetResultAsync();

                // Check if the job succeeded.
                if (offlineMapSyncJob.Status == JobStatus.Succeeded)
                {
                    // Check if the map package needs to be re-opened.
                    if (result.IsMobileMapPackageReopenRequired)
                    {
                        // Re-open the mobile map package.
                        _mobileMapPackage.Close();
                        await _mobileMapPackage.LoadAsync();

                        // Check that the mobile map package was loaded.
                        if (_mobileMapPackage.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded && _mobileMapPackage.Maps.Any())
                        {
                            // Set the mapview to the map from the package.
                            Map offlineMap = _mobileMapPackage.Maps[0];
                            MyMapView.Map = offlineMap;

                            // Create an offline map sync task for the map.
                            _offlineMapSyncTask = await OfflineMapSyncTask.CreateAsync(offlineMap);
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert("Error", "Failed to load the mobile map package.", "OK");
                        }
                    }

                    // Verify that the map is up to date and change the UI to reflect the update availability status.
                    CheckForScheduledUpdates();
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Error syncing the offline map.", "OK");
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }
        private async void ApplyUpdatesClicked(object sender, EventArgs e)
        {
            try
            {
                // Create default sync parameters.
                OfflineMapSyncParameters parameters = await _offlineMapSyncTask.CreateDefaultOfflineMapSyncParametersAsync();

                // Set the parameters to download all updates for the mobile map packages.
                parameters.PreplannedScheduledUpdatesOption = PreplannedScheduledUpdatesOption.DownloadAllUpdates;

                // Create a sync job using the parameters.
                OfflineMapSyncJob offlineMapSyncJob = _offlineMapSyncTask.SyncOfflineMap(parameters);

                // Get the results of the job.
                offlineMapSyncJob.Start();
                OfflineMapSyncResult result = await offlineMapSyncJob.GetResultAsync();

                // Check if the job succeeded.
                if (offlineMapSyncJob.Status == JobStatus.Succeeded)
                {
                    // Check if the map package needs to be re-opened.
                    if (result.IsMobileMapPackageReopenRequired)
                    {
                        // Re-open the mobile map package.
                        _mobileMapPackage.Close();
                        _mobileMapPackage = new MobileMapPackage(_mapPackagePath);
                        await _mobileMapPackage.LoadAsync();

                        // Check that the mobile map package was loaded.
                        if (_mobileMapPackage.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded && _mobileMapPackage.Maps.Any())
                        {
                            // Set the mapview to the map from the package.
                            Map offlineMap = _mobileMapPackage.Maps[0];
                            _myMapView.Map = offlineMap;

                            // Create an offline map sync task for the map.
                            _offlineMapSyncTask = await OfflineMapSyncTask.CreateAsync(offlineMap);
                        }
                        else
                        {
                            new UIAlertView("Error", "Failed to load the mobile map package.", (IUIAlertViewDelegate)null, "OK", null).Show();
                        }
                    }

                    // Verify that the map is up to date and change the UI to reflect the update availability status.
                    CheckForScheduledUpdates();
                }
                else
                {
                    new UIAlertView("Error", "Error syncing the offline map.", (IUIAlertViewDelegate)null, "OK", null).Show();
                }
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Example #4
0
        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);
        }
Example #5
0
        private async void Initialize()
        {
            try
            {
                // Path to the mobile map package.
                string mobileMapPackagePath = DataManager.GetDataFolder("174150279af74a2ba6f8b87a567f480b", "LothianRiversAnno.mmpk");

                // Create a mobile map package.
                MobileMapPackage mobileMapPackage = new MobileMapPackage(mobileMapPackagePath);

                // Load the mobile map package.
                await mobileMapPackage.LoadAsync();

                // Check if the map package is expired.
                if (mobileMapPackage.Expiration?.IsExpired == true)
                {
                    // Get the expiration of the mobile map package.
                    Expiration expiration = mobileMapPackage.Expiration;

                    // Get the expiration message.
                    string expirationMessage = expiration.Message;

                    // Get the expiration date.
                    string expirationDate = expiration.DateTime.ToString("F");

                    // Set the expiration message.
                    _expirationLabel.Text = $"{expirationMessage}\nExpiration date: {expirationDate}";

                    // Check if the map is accessible after expiration.
                    if (expiration.Type == ExpirationType.AllowExpiredAccess && mobileMapPackage.Maps.Count > 0)
                    {
                        // Set the mapview to the map from the mobile map package.
                        _myMapView.Map = mobileMapPackage.Maps[0];
                    }
                    else if (expiration.Type == ExpirationType.PreventExpiredAccess)
                    {
                        new AlertDialog.Builder(this).SetMessage("The author of this mobile map package has disallowed access after the expiration date.").SetTitle("Error").Show();
                    }
                }
                else if (mobileMapPackage.Maps.Any())
                {
                    // Set the mapview to the map from the mobile map package.
                    _myMapView.Map = mobileMapPackage.Maps[0];
                }
                else
                {
                    new AlertDialog.Builder(this).SetMessage("Failed to load the mobile map package.").SetTitle("Error").Show();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #6
0
        /// <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);
        }
Example #7
0
        private async void Initialize()
        {
            try
            {
                // Load the mobile map package.
                _mobileMapPackage = new MobileMapPackage(DataManager.GetDataFolder("b87307dcfb26411eb2e92e1627cb615b", "GasDeviceAnno.mmpk"));
                await _mobileMapPackage.LoadAsync();

                // Set the mapview to display the map from the package.
                _myMapView.Map = _mobileMapPackage.Maps.First();

                // Get the annotation layer from the MapView operational layers.
                AnnotationLayer annotationLayer = (AnnotationLayer)_myMapView.Map.OperationalLayers.Where(layer => layer is AnnotationLayer).First();

                // Load the annotation layer.
                await annotationLayer.LoadAsync();

                // Get the annotation sub layers.
                _closedSublayer = (AnnotationSublayer)annotationLayer.SublayerContents[0];
                _openSublayer   = (AnnotationSublayer)annotationLayer.SublayerContents[1];

                // Set the label content.
                _openLabel.Text   = $"{_openSublayer.Name} (1:{_openSublayer.MaxScale} - 1:{_openSublayer.MinScale})";
                _closedLabel.Text = _closedSublayer.Name;

                // Enable the check boxes.
                _openSwitch.Enabled   = true;
                _closedSwitch.Enabled = true;

                // Add event handler for changing the text to indicate whether the "open" sublayer is visible at the current scale.
                _myMapView.ViewpointChanged += (s, e) =>
                {
                    // Check if the sublayer is visible at the current map scale.
                    if (_openSublayer.IsVisibleAtScale(_myMapView.MapScale))
                    {
                        _openLabel.TextColor = UIColor.Black;
                    }
                    else
                    {
                        _openLabel.TextColor = UIColor.Gray;
                    }

                    // Set the current map scale text.
                    _scaleLabel.Text = "Current map scale: 1:" + (int)_myMapView.MapScale;
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        private async void Initialize()
        {
            try
            {
                // Clear the exiting sample data.
                Directory.Delete(DataManager.GetDataFolder(_itemId, ""), true);
            }
            catch (IOException)
            {
                // Do nothing. Exception happens when sample hasn't been run before and data isn't already present.
            }

            try
            {
                // Token for cancelling the download if the sample is exited early.
                var tokenSource         = new CancellationTokenSource();
                CancellationToken token = tokenSource.Token;

                // Add an event to close the mobile map package when the sample closes.
                Unloaded += (s, e) =>
                {
                    _mobileMapPackage?.Close();
                    tokenSource.Cancel();
                };

                // Download the mobile map package using the sample viewer's data manager.
                await DataManager.DownloadDataItem(_itemId, token);

                // Get the folder path to the mobile map package.
                _mapPackagePath = DataManager.GetDataFolder(_itemId, "");

                // Load the mobile map package.
                _mobileMapPackage = new MobileMapPackage(_mapPackagePath);
                await _mobileMapPackage.LoadAsync();

                // Set the mapview to the map from the package.
                Map offlineMap = _mobileMapPackage.Maps[0];
                MyMapView.Map = offlineMap;

                // Create an offline map sync task for the map.
                _offlineMapSyncTask = await OfflineMapSyncTask.CreateAsync(offlineMap);

                // Check if there are scheduled updates to the preplanned map area.
                CheckForScheduledUpdates();
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, "Error").ShowAsync();
            }
        }
        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");
            }
        }
        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();
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            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 AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            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)
            {
                await new MessageDialog(e.ToString(), "Error").ShowAsync();
            }
        }
Example #13
0
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            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)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            try
            {
                // Open the package.
                MobileMapPackage package = await MobileMapPackage.OpenAsync(filepath);

                // Load the package.
                await package.LoadAsync();

                // Show the first map.
                MyMapView.Map = package.Maps.First();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = DataManager.GetDataFolder("e1f3a7254cb845b09450f54937c16061", "Yellowstone.mmpk");

            try
            {
                // Load directly or unpack then load as needed by the map package.
                if (await MobileMapPackage.IsDirectReadSupportedAsync(filepath))
                {
                    // Open the map package.
                    MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath);

                    // Display the first map in the package.
                    _myMapView.Map = myMapPackage.Maps.First();
                }
                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();

                    // Show the first map.
                    _myMapView.Map = package.Maps.First();
                }
            }
            catch (Exception e)
            {
                new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            try
            {
                // Load directly or unpack then load as needed by the map package.
                if (await MobileMapPackage.IsDirectReadSupportedAsync(filepath))
                {
                    // Open the map package.
                    MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath);

                    // Display the first map in the package.
                    MyMapView.Map = myMapPackage.Maps.First();
                }
                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();

                    // Show the first map.
                    MyMapView.Map = package.Maps.First();
                }
            }
            catch (Exception e)
            {
                await((Page)Parent).DisplayAlert("Error", e.ToString(), "OK");
            }
        }
        private async void Initialize()
        {
            try
            {
                // Clear the exiting sample data.
                Directory.Delete(DataManager.GetDataFolder(_itemId, ""), true);
            }
            catch (IOException)
            {
                // Do nothing. Exception happens when sample hasn't been run before and data isn't already present.
            }

            try
            {
                // Download the mobile map package using the sample viewer's data manager.
                await DataManager.DownloadDataItem(_itemId);

                // Get the folder path to the mobile map package.
                _mapPackagePath = DataManager.GetDataFolder(_itemId, "");

                // Load the mobile map package.
                _mobileMapPackage = new MobileMapPackage(_mapPackagePath);
                await _mobileMapPackage.LoadAsync();

                // Set the mapview to the map from the package.
                Map offlineMap = _mobileMapPackage.Maps[0];
                _myMapView.Map = offlineMap;

                // Create an offline map sync task for the map.
                _offlineMapSyncTask = await OfflineMapSyncTask.CreateAsync(offlineMap);

                // Check if there are scheduled updates to the preplanned map area.
                CheckForScheduledUpdates();
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
        private async void Initialize()
        {
            // Get the path to the mobile map package.
            string filepath = GetMmpkPath();

            try
            {
                // Load directly or unpack then load as needed by the map package.
                if (await MobileMapPackage.IsDirectReadSupportedAsync(filepath))
                {
                    // Open the map package.
                    MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(filepath);

                    // Display the first map in the package.
                    _myMapView.Map = myMapPackage.Maps.First();
                }
                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();

                    // Show the first map.
                    _myMapView.Map = package.Maps.First();
                }
            }
            catch (Exception e)
            {
                new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }
        private async void ActivateButton_Clicked(object sender, EventArgs e)
        {
            // Open the map package.
            MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(GetMmpkPath());

            await myMapPackage.LoadAsync();

            // Get our annotation layer
            var annoLayer = myMapPackage.Maps.First().AllLayers.First();

            myMapPackage.Maps.First().OperationalLayers.Clear();
            myMapPackage.Close();

            // Add it to our offline map area
            _offlineMapArea.OperationalLayers.Add(annoLayer);
            TheMap.Map = _offlineMapArea;

            Device.BeginInvokeOnMainThread(() =>
            {
                ActivateMapAreaButton.IsEnabled = false;
                UpdateFeatureButton.IsEnabled   = true;
            });
        }