private bool GetNextTile(out ICanvasBitmapTile tile) { lock (_locker) { tile = null; while (_tilesToLoad.Any()) { int minKey = _tilesToLoad.Keys.Min(); List <ICanvasBitmapTile> tileForMinLevel = _tilesToLoad[minKey]; if (tileForMinLevel.Any()) { tile = tileForMinLevel.FirstOrDefault(t => !t.IsNotInCache); if (tile == null) { tile = tileForMinLevel.First(); } tileForMinLevel.Remove(tile); Interlocked.Decrement(ref _pendingTileCount); break; } _tilesToLoad.Remove(minKey); } } OnPropertyChanged(nameof(PendingTileCount)); return(tile != null); }
protected override async Task <InMemoryRandomAccessStream> LoadTileImage(ICanvasBitmapTile tile) { if (DesignMode.DesignModeEnabled) { return(await CreateEmptyImage()); } using (HttpRequestMessage tileRequest = BuildRequest(tile)) { using (HttpResponseMessage response = await _client.SendRequestAsync(tileRequest)) { if (!response.IsSuccessStatusCode) { MapEventSource.Log.TileLoaderDownloadFailed(tile.CacheKey, (int)response.StatusCode, tileRequest.RequestUri.ToString()); return(null); } if (response.StatusCode == HttpStatusCode.NoContent) { tile.State = TileState.TileDoesNotExist; return(null); } InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream(); await response.Content.WriteToStreamAsync(ras); ras.Seek(0); tile.State = TileState.Loaded; return(ras); } } }
protected override HttpRequestMessage BuildRequest(ICanvasBitmapTile tile) { HttpRequestMessage request = base.BuildRequest(tile); request.Headers.Add("Referer", LicenseKey); return(request); }
protected virtual HttpRequestMessage BuildRequest(ICanvasBitmapTile tile) { Uri url = _tiler.GetUrl(tile); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3)"); return(request); }
public Uri GetUrl(ICanvasBitmapTile tile) { int tileCount = 1 << tile.TileSet; int halfTileCount = tileCount / 2; int tileSize = 1 << (ZoomExponent - tile.TileSet); int x = SanitizeIndex((int)Math.Floor(tile.Bounds.X / tileSize) + halfTileCount, tileCount); int y = SanitizeIndex((int)Math.Floor(tile.Bounds.Y / tileSize) + halfTileCount, tileCount); string uriString = PatternMatcher.Replace(UrlPattern, m => MatchEvaluator(m, x, y, tile.TileSet)); return(new Uri(uriString)); }
public async Task <bool> TryLoadAsync(ICanvasBitmapTile tile) { IRandomAccessStream stream = await TryGetStream(tile); if ((stream == null) || (stream.Size == 0)) { return(false); } await tile.ReadFromAsync(stream); return(tile.HasImage); }
public void Enqueue(ICanvasBitmapTile tile) { if (!tile.HasImage) { lock (_locker) { List <ICanvasBitmapTile> tiles; if (!_tilesToLoad.TryGetValue(tile.TileSet, out tiles)) { tiles = new List <ICanvasBitmapTile>(); _tilesToLoad.Add(tile.TileSet, tiles); } tiles.Add(tile); Interlocked.Increment(ref _pendingTileCount); } StartDownloading(); OnPropertyChanged(nameof(PendingTileCount)); } }
public Uri GetUrl(ICanvasBitmapTile tile) { long tileWidthMeters = TileSizeMeter[tile.TileSet]; int x = (int)(tile.Bounds.X / tileWidthMeters); int y = (int)(tile.Bounds.Y / tileWidthMeters); int r = _random.Next(5, 9); string url; if (tile.TileSet >= 24) { url = string.Format("http://wmts{3}.geo.admin.ch/1.0.0/ch.swisstopo.swisstlm3d-karte-farbe/default/current/21781/{2}/{1}/{0}.png", x, y, tile.TileSet, r); } else { url = string.Format("http://wmts{3}.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/21781/{2}/{1}/{0}.jpeg", x, y, tile.TileSet, r); } return(new Uri(url)); }
public async Task AddAsyc(ICanvasBitmapTile tile, IRandomAccessStream tileData) { StorageFolder folder = await OpenFolder(tile).ConfigureAwait(false); string filename = string.Format(CultureInfo.InvariantCulture, "{0}.tile", tile.CacheKey); StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite).AsTask().ConfigureAwait(false)) { Buffer buffer = new Buffer(1024 * 1024); bool eof = false; while (!eof) { IBuffer readBuffer = await tileData.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial).AsTask().ConfigureAwait(false); await fileStream.WriteAsync(readBuffer).AsTask().ConfigureAwait(false); eof = readBuffer.Length < readBuffer.Capacity; } await fileStream.FlushAsync(); } }
protected virtual void DrawLoadingTile(CanvasDrawingSession drawingSession, ICanvasBitmapTile tile, Map parentMap) { drawingSession.FillRectangle(tile.Bounds, LoadingOverlayColor); }
protected virtual void DrawInexistentTile(CanvasDrawingSession drawingSession, ICanvasBitmapTile tile, Map parentMap) { }
protected abstract Task <InMemoryRandomAccessStream> LoadTileImage(ICanvasBitmapTile tile);