public OfflineSideloadOfflineMapPage()
        {
            InitializeComponent();

            map.MapStyle  = MapStyle.OUTDOORS;
            map.Center    = new LatLng(21.2, 105.5019);
            map.ZoomLevel = 13;

            map.DidFinishLoadingStyleCommand = new Command <MapStyle>(HandleStyleLoaded);

            offlineService = DependencyService.Get <IOfflineStorageService>();

            MessagingCenter.Subscribe <MyTransferDelegate, HttpTransfer>(this, "UPLOAD_DONE", (sender, e) => {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    txtMerge.Text = "Downloaded. Merging...";

                    var localPath = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "mapbox-cache.db");
                    var result    = await offlineService.Sideload(localPath);

                    txtMerge.IsEnabled = true;
                    txtMerge.Text      = "Download and Merge";
                    DisplayAlert("Download", "Downloading and Merging were successfully", "Ok");
                });
            });

            MessagingCenter.Subscribe <MyTransferDelegate, Exception>(this, "UPLOAD_FAILED", (sender, e) => {
                Device.BeginInvokeOnMainThread(() => {
                    txtMerge.IsEnabled = true;
                    txtMerge.Text      = "Try again";

                    DisplayAlert("Download", $"Downloading is failed: \n{e.Message}", "Ok");
                });
            });
        }
Beispiel #2
0
        public OfflineSimpleOfflineMapPage()
        {
            InitializeComponent();

            map.MapStyle  = MapStyle.OUTDOORS;
            map.Center    = new LatLng(37.73359, -119.58410);
            map.ZoomLevel = 10;

            map.DidFinishLoadingStyleCommand = new Command <MapStyle>(HandleStyleLoaded);


            offlineService = DependencyService.Get <IOfflineStorageService>();
        }
Beispiel #3
0
        public MainPageViewModel()
        {
            DidFinishRenderingCommand = new Command((obj) =>
            {
                if (_IsScaleBarShown == false && CenterLocation != null)
                {
                    _IsScaleBarShown = ToggleScaleBarFunc?.Invoke(true) ?? false;
                    System.Diagnostics.Debug.WriteLine("Did toggle scale bar");
                    //UpdateViewPortAction?.Invoke(new Position(CenterLocation.Lat + 0.001, CenterLocation.Long + 0.001), 16, null, false, () => {
                    //	System.Diagnostics.Debug.WriteLine("Did update center location");
                    //});
                }
                if (forcedRegion != null)
                {
                    UpdateViewPortAction?.Invoke(
                        new Position()
                    {
                        Lat  = forcedRegion.Bounds.SouthWest.Lat / 2 + forcedRegion.Bounds.NorthEast.Lat / 2,
                        Long = forcedRegion.Bounds.SouthWest.Long / 2 + forcedRegion.Bounds.NorthEast.Long / 2
                    },
                        forcedRegion.MaximumZoomLevel / 2 + forcedRegion.MinimumZoomLevel / 2,
                        null,
                        true,
                        null
                        );
                    forcedRegion = null;
                }
            }, (arg) => true);


            offlineService = DependencyService.Get <IOfflineStorageService>();
            offlineService.OfflinePackProgressChanged += (sender, e) =>
            {
                var   progress   = e.OfflinePack.Progress;
                float percentage = 0;
                if (progress.CountOfResourcesExpected > 0)
                {
                    percentage = (float)progress.CountOfResourcesCompleted / progress.CountOfResourcesExpected;
                }
                System.Diagnostics.Debug.WriteLine($"Downloaded resources: {progress.CountOfResourcesCompleted} ({percentage * 100} %)");
                System.Diagnostics.Debug.WriteLine($"Downloaded tiles: {progress.CountOfTilesCompleted}");
                if (progress.CountOfResourcesExpected == progress.CountOfResourcesCompleted)
                {
                    System.Diagnostics.Debug.WriteLine("Download completed");
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        UserDialogs.Instance.HideLoading();
                    });
                }
            };
        }