Пример #1
0
        private async void btnTestFakeTerrain_Click_1(object sender, EventArgs e)
        {
            listBox1.Items.Add("Fetching DEM...");
            // class to get digital elevation models(DEM)
            FakeDEMSource demSrc = new FakeDEMSource();

            demSrc.Initalize(new MapHeader()
            {
                GridSize = Int32.Parse(txtTileSize.Text)
            });

            var elevData = await demSrc.GetDemLL(1, 1, 1, 1); //) mp.GetTerrainTileAsync(x,y,z);

            listBox1.Items.Add($"DEM length {elevData.Elev.Length}");

            listBox1.Items.Add("Making Mesh...");
            // This class constructs a cesium quantized mesh from the dem
            var vertices = new Mesh().MakeFakeMesh(ref elevData);

            listBox1.Items.Add("Making Tile...");
            // This class constructs a quantized mesh tile mesh from the original mesh
            var tile = new Tiler().MakeTile(vertices,
                                            new TerrainTileHeader()
            {
                MinimumHeight = elevData.MinimumHeight, MaximumHeight = elevData.MaximumHeight
            },
                                            MapUtil.GridSizeToTriangleCount(elevData.GridSize), elevData.GridSize);

            listBox1.Items.Add($"Tile Ready. Size:{tile.Length} . Saving to {txtPath.Text}");

            var ms = new MemoryStream(tile);

            using (FileStream fs = new FileStream(txtPath.Text, FileMode.Create))
                using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Compress, false))
                {
                    zipStream.Write(ms.ToArray(), 0, ms.ToArray().Length); // .Write(bytes, 0, bytes.Length);
                }
        }
Пример #2
0
        public async Task <IActionResult> GetFakeTile(int x, int y, int z, string formatExtension)
        {
            // todo for now default values. these will be passed in eventually
            var testDataPath = _configuration["TestDataPath"];

            Guid projectId;
            bool isValid = Guid.TryParse(_configuration["DefaultProjectUid"], out projectId);

            if (!isValid)
            {
                return(NotFound()); // todo
            }
            if (z < 1)
            {
                // these two tiles are standard
                // Use tiler to fetch the correct tile
                var basicTile = await new Tiler.Tiler().FetchTile(testDataPath, x, y, z);
                if (basicTile != null)
                {
                    HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                    //   HttpContext.Response.Headers.Add("Access-Control-Allow-Origin","*"); // already compressed on disk

                    HttpContext.Response.Headers.Add("Content-Length", basicTile.Length.ToString());
                    HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                    HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                    Console.WriteLine($"*** Tile x:{x},y:{y},z:{z} was found ***");
                    return(File(basicTile, _TerrainDataQM));
                }

                return(NotFound());
            }

            FakeDEMSource demSrc = new FakeDEMSource();

            demSrc.Initalize(new MapHeader()
            {
                GridSize = _GridSize
            });

            // todo x,y,z to lat lon
            var elevData = await demSrc.GetDemLL(1, 1, 1, 1); // just the same tile always for now

            // This class constructs a cesium quantized mesh from the dem
            var vertices = new Mesh.Mesh().MakeFakeMesh(ref elevData);

            // todo fill in header details
            var tempHeadr = new TerrainTileHeader()
            {
                MaximumHeight = elevData.MaximumHeight,
                MinimumHeight = elevData.MinimumHeight
            };

            // This class constructs a quantized mesh tile mesh from the original mesh
            var tile = new Tiler.Tiler().MakeTile(vertices, tempHeadr, MapUtil.GridSizeToTriangleCount(elevData.GridSize),
                                                  elevData.GridSize);

            if (tile != null)
            {
                var compressed = MapUtil.Compress(tile);
                HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                //   HttpContext.Response.Headers.Add("Access-Control-Allow-Origin","*"); // already compressed on disk

                HttpContext.Response.Headers.Add("Content-Length", compressed.Length.ToString());
                HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                return(File(compressed, _TerrainDataQM));
            }
            else
            {
                return(NotFound());
            }
        }