private OfflineRegionDto Transform(OfflineRegion region) { var definition = region.Definition as OfflineTilePyramidRegionDefinition; var regionDto = new OfflineRegionDto() { Id = region.ID, Bounds = new LatLngBoundsDto() { Ne = new Coordinate { Latitude = definition.Bounds.NorthEast.Latitude, Longitude = definition.Bounds.NorthEast.Longitude }, Sw = new Coordinate { Latitude = definition.Bounds.SouthWest.Latitude, Longitude = definition.Bounds.SouthWest.Longitude } }, Style = definition.StyleURL, MinimumZoomLevel = definition.MinZoom, MaximumZoomLevel = definition.MaxZoom }; return(regionDto); }
/* * If the device has network connectivity, the Maps SDK for Android or iOS will make periodic network requests to revalidate cached tiles * and other resources if the Cache-Control or Expires HTTP response headers have expired. * If an updated resource is available, it will replace the older version in the offline database. * When the SDK automatically updates offline map tiles, the offline region is not re-download from scratch. * The offline tile update process is the same process as with regular map tiles: * The map tile's only downloaded if there's a new version of that tile. */ public async void DownloadOfflineRegion(OfflineRegionDto regionDto) { var regions = await GetMapBoxOfflineRegions(); var region = regions.FirstOrDefault(d => d.ID == regionDto.Id); if (region == null) { return; } region.SetDownloadState(OfflineRegion.StateActive); region.SetObserver(new OfflineRegionDownloadObserver(Application.Context) { OnStatusChangedCallback = status => { regionDto.DownloadStatus = new DownloadStatus { CountOfResourcesExpected = (ulong)status.RequiredResourceCount, CountOfResourcesCompleted = (ulong)status.CompletedResourceCount, CountOfTilesCompleted = (ulong)status.CompletedTileCount, CountOfTileBytesCompleted = (ulong)status.CompletedTileSize, CountOfBytesCompleted = (ulong)status.CompletedResourceSize, MaximumResourcesExpected = (ulong)status.RequiredResourceCount }; if (status.IsComplete) { regionDto.DownloadState = DownloadState.Completed; } else if (status.DownloadState == OfflineRegion.StateActive) { regionDto.DownloadState = DownloadState.Active; } else { regionDto.DownloadState = DownloadState.Inactive; } OfflineDownloadProgress?.Invoke(this, new DownloadStatusEventArgs(regionDto)); }, OnErrorCallback = error => { OfflineDownloadError?.Invoke(this, new EventArgs <string>($"{error.Reason} - {error.Message}")); region.SetDownloadState(OfflineRegion.StateInactive); }, OnMapBoxTileCountLimitExceededCallback = l => { Toast.MakeText(Application.Context, "Limit exceeded", ToastLength.Long).Show(); } }); }
public async Task <bool> IsRegionDownloadCompleted(OfflineRegionDto regionDto) { var regions = await GetMapBoxOfflineRegions(); var requiredRegion = regions.SingleOrDefault(x => x.ID == regionDto.Id); if (requiredRegion != null) { return(await GetStatusRegionDto(requiredRegion) == DownloadState.Completed); } return(false); }
public void Pause(OfflineRegionDto region) { throw new NotImplementedException(); }