/// <summary> /// Generates a URI at which to get the data for a tile. /// </summary> /// <param name="info">Information about a tile.</param> /// <returns>The URI at which to get the data for the specified tile.</returns> public Uri GetUri(TileInfo info) { var url = new StringBuilder(_baseUrl.AbsoluteUri); url.Append("&SERVICE=WMS"); if (!string.IsNullOrEmpty(_version)) { url.AppendFormat("&VERSION={0}", _version); } url.Append("&REQUEST=GetMap"); url.AppendFormat("&BBOX={0}", TileTransform.TileToWorld(new TileRange(info.Index.Row, info.Index.Col), info.Index.Level, _schema)); url.AppendFormat("&FORMAT={0}", _schema.Format); url.AppendFormat("&WIDTH={0}", _schema.Width); url.AppendFormat("&HEIGHT={0}", _schema.Height); var crsFormat = !string.IsNullOrEmpty(_version) && string.CompareOrdinal(_version, "1.3.0") >= 0 ? "&CRS={0}" : "&SRS={0}"; url.AppendFormat(crsFormat, _schema.Srs); url.AppendFormat("&LAYERS={0}", ToCommaSeparatedValues(_layers)); if (_styles != null && _styles.Count > 0) { url.AppendFormat("&STYLES={0}", ToCommaSeparatedValues(_styles)); } AppendCustomParameters(url); return(new Uri(url.ToString())); }
private void RequestTiles(TmsGlobalGeodeticTileSchema schema, TileRange tileRange, List <TileInfo> tiles) { //immediately draw placeholder tile and fire request for texture and height. Depending on which one returns first, update place holder. foreach (var t in tiles) { //draw placeholder tile var tile = DrawPlaceHolder(tileRange, t); tileDb.Add(new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)), tile); //get tile texture data string surfaceUrl = ""; switch (surface.Service) { case DataService.WMS: var subtileExtent = TileTransform.TileToWorld(new TileRange(t.Index.Col, t.Index.Row), t.Index.Level.ToString(), schema); surfaceUrl = surface.Url.Replace("{xMin}", subtileExtent.MinX.ToString()).Replace("{yMin}", subtileExtent.MinY.ToString()).Replace("{xMax}", subtileExtent.MaxX.ToString()).Replace("{yMax}", subtileExtent.MaxY.ToString()).Replace(",", "."); break; case DataService.TMS: surfaceUrl = surface.Url.Replace("{x}", t.Index.Col.ToString()).Replace("{y}", t.Index.Row.ToString()).Replace("{z}", int.Parse(t.Index.Level).ToString()); break; } downloadQueue.Enqueue(new DownloadRequest(surfaceUrl, DataType.Surface, new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)))); //get tile height data ( var terrainUrl = terrain.Url.Replace("{x}", t.Index.Col.ToString()).Replace("{y}", t.Index.Row.ToString()).Replace("{z}", int.Parse(t.Index.Level).ToString()); downloadQueue.Enqueue(new DownloadRequest(terrainUrl, DataType.Terrain, new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)))); } }
public void TileFetcherShouldBehaveProperlyWithNoisyResponses() { // Arrange var schema = new GlobalSphericalMercator(); var tileSource = new TileSource(new SometimesFailingTileProvider(), schema); var memoryCache = new MemoryCache <Feature>(14, 17); var tileFetcher = new TileFetcher(tileSource, memoryCache); var random = new Random(31747074); var tiles = new List <Feature>(); // Act for (int i = 0; i < 100; i++) { var randomLevel = "5"; var randomCol = random.Next(schema.GetMatrixWidth(randomLevel)); var randomRow = random.Next(schema.GetMatrixHeight(randomLevel)); var tileRange = new TileRange(randomCol - 2, randomRow - 2, 5, 5); var unitsPerPixel = schema.Resolutions[randomLevel].UnitsPerPixel; var extent = TileTransform.TileToWorld(tileRange, randomLevel, schema); tileFetcher.ViewChanged(TileTransform.TileToWorld(tileRange, randomLevel, schema).ToBoundingBox(), unitsPerPixel); var tileInfos = schema.GetTileInfos(extent, randomLevel); foreach (var tileInfo in tileInfos) { tiles.Add(memoryCache.Find(tileInfo.Index)); } } // Assert Assert.True(tiles.Count > 0); Assert.True(memoryCache.TileCount == 0); }
public void TileToWorldShouldReturnCorrectExtent() { // arrange var range = new TileRange(1, 2); var schema = new SphericalMercatorWorldSchema(); var expectedExtent = new Extent(-15028131.257989, -10018754.173189, -10018754.173189, -5009377.088389); // act var extent = TileTransform.TileToWorld(range, 3, schema); // assert Assert.AreEqual(extent.MinX, expectedExtent.MinX, 0.0001); Assert.AreEqual(extent.MinY, expectedExtent.MinY, 0.0001); Assert.AreEqual(extent.MaxX, expectedExtent.MaxX, 0.0001); Assert.AreEqual(extent.MaxY, expectedExtent.MaxY, 0.0001); }
private static List <RasterFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource) { var features = new List <RasterFeature>(); foreach (var tileIndex in tileIndexes) { var tileInfo = new TileInfo { Index = tileIndex, Extent = TileTransform.TileToWorld( new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema) }; var raster = new MRaster(tileSource.GetTile(tileInfo), tileInfo.Extent.ToMRect()); features.Add(new RasterFeature(raster)); } return(features); }
public void TileToWorldShouldReturnCorrectExtent() { // arrange var range = new TileRange(1, 2); var schema = new GlobalSphericalMercator(YAxis.TMS); var expectedExtent = new Extent(-15028131.257989, -10018754.173189, -10018754.173189, -5009377.088389); const double toleratedDelta = 0.01; // act var extent = TileTransform.TileToWorld(range, 3, schema); // assert Assert.AreEqual(extent.MinX, expectedExtent.MinX, toleratedDelta); Assert.AreEqual(extent.MinY, expectedExtent.MinY, toleratedDelta); Assert.AreEqual(extent.MaxX, expectedExtent.MaxX, toleratedDelta); Assert.AreEqual(extent.MaxY, expectedExtent.MaxY, toleratedDelta); }
public IEnumerable <TileInfo> GetTileInfos(Extent extent, string levelId) { // todo: move this method elsewhere. var range = TileTransform.WorldToTile(extent, levelId, this); // todo: use a method to get tilerange for full schema and intersect with requested tilerange. var startX = Math.Max(range.FirstCol, GetMatrixFirstCol(levelId)); var stopX = Math.Min(range.FirstCol + range.ColCount, GetMatrixFirstCol(levelId) + GetMatrixWidth(levelId)); var startY = Math.Max(range.FirstRow, GetMatrixFirstRow(levelId)); var stopY = Math.Min(range.FirstRow + range.RowCount, GetMatrixFirstRow(levelId) + GetMatrixHeight(levelId)); for (var x = startX; x < stopX; x++) { for (var y = startY; y < stopY; y++) { yield return(new TileInfo { Extent = TileTransform.TileToWorld(new TileRange(x, y), levelId, this), Index = new TileIndex(x, y, levelId) }); } } }
private static List <IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource) { var features = new List <IFeature>(); foreach (var tileIndex in tileIndexes) { var tileInfo = new TileInfo { Index = tileIndex, Extent = TileTransform.TileToWorld( new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema) }; var feature = new Feature { Geometry = new Raster(new MemoryStream( tileSource.GetTile(tileInfo)), tileInfo.Extent.ToBoundingBox()) }; features.Add(feature); } return(features); }
public void CreateTiles() { ClearTiles(); sw.Start(); var schema = new TmsGlobalGeodeticTileSchema(); var tileRange = TileTransform.WorldToTile(extent, zoomLevel.ToString(), schema); var tilesOrigin = schema.GetTileInfos(extent, 13.ToString()).ToList(); //refactor when done experimenting scale var tiles = schema.GetTileInfos(extent, zoomLevel.ToString()).ToList(); yOffset = (float)Math.Abs(tiles[0].Extent.MinY - tilesOrigin[0].Extent.MinY); xOffset = (float)Math.Abs(tiles[0].Extent.MinX - tilesOrigin[0].Extent.MinX); UnityEngine.Debug.Log(xOffset); var folder = new GameObject("map"); //immediately draw placeholder tile and fire request for texture and height. Depending on which one returns first, update place holder. foreach (var t in tiles) { //draw placeholder tile GameObject tile = DrawPlaceHolder(tileRange, t); tile.transform.parent = folder.transform; tileDb.Add(new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)), tile); //get tile texture data Extent subtileExtent = TileTransform.TileToWorld(new TileRange(t.Index.Col, t.Index.Row), t.Index.Level.ToString(), schema); var wmsUrl = textureUrl.Replace("{xMin}", subtileExtent.MinX.ToString()).Replace("{yMin}", subtileExtent.MinY.ToString()).Replace("{xMax}", subtileExtent.MaxX.ToString()).Replace("{yMax}", subtileExtent.MaxY.ToString()).Replace(",", "."); downloadQueue.Enqueue(new downloadRequest(wmsUrl, TileService.WMS, new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)))); //get tile height data ( var qmUrl = terrainUrl.Replace("{x}", t.Index.Col.ToString()).Replace("{y}", t.Index.Row.ToString()).Replace("{z}", int.Parse(t.Index.Level).ToString()); downloadQueue.Enqueue(new downloadRequest(qmUrl, TileService.QM, new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level)))); } }