예제 #1
0
        public void WorldToTileShouldReturnCorrectTileRange()
        {
            // arrange
            var expectedRange = new TileRange(1, 2);
            var schema        = new GlobalSphericalMercator(YAxis.TMS);
            var extent        = new Extent(-15028130, -10018753, -10018755, -5009378);

            // act
            var range = TileTransform.WorldToTile(extent, 3, schema);

            // assert
            Assert.AreEqual(range, expectedRange);
        }
        private void LoadMap()
        {
            ClearCache();

            var schema    = new TmsGlobalGeodeticTileSchema();
            var tileRange = TileTransform.WorldToTile(extent, zoomLevel.ToString(), schema);
            var tiles     = schema.GetTileInfos(extent, zoomLevel.ToString()).ToList();

            RequestTiles(schema, tileRange, tiles);

            //if (useSatellite)
            //{
            //    var schema2 = new BruTile.Predefined.GlobalSphericalMercator(YAxis.TMS);
            //    var tiles2 = schema2.GetTileInfos(extent, zoomLevel.ToString()).ToList();

            //    foreach (var t in tiles2)
            //    {
            //        var url = textureUrl.Replace("{x}", t.Index.Col.ToString()).Replace("{y}", t.Index.Row.ToString()).Replace("{z}", int.Parse(t.Index.Level).ToString()); //WMTS
            //        downloadQueue.Enqueue(new DownloadRequest(url, TileServiceType.WMS, new Vector3(t.Index.Col, t.Index.Row, int.Parse(t.Index.Level))));
            //    }
            //}
        }
예제 #3
0
        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)
                    });
                }
            }
        }
예제 #4
0
        public void TileTransformWithDifferentTileWidthAndHeight()
        {
            // arrange
            var tileWidth  = 10;
            var tileHeight = 5; // Note, tile tileHeight is half the tileWidth

            var expectedColCount = 10;
            var expectedRowCount = 20; // Because tileHeight is half the tileHeight there is a double number of rows

            var schema = new TileSchema {
                Extent = new Extent(0, 0, 100, 100), OriginX = 0, OriginY = 0
            };

            schema.Resolutions.Add(0, new Resolution(0, 1, tileWidth, tileHeight, 0, 0, 10, 10, 1));
            var requestedExtent = new Extent(0, 0, 100, 100);

            // act
            var range = TileTransform.WorldToTile(requestedExtent, 0, schema);

            // assert
            Assert.AreEqual(expectedColCount, range.ColCount, "ColCount");
            Assert.AreEqual(expectedRowCount, range.RowCount, "RowCount");
        }
예제 #5
0
        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))));
            }
        }