Пример #1
0
    public override Task <ElevationTile> GetElevationTileData(TileId tileId, CancellationToken cancellationToken = default)
    {
        if (!_tiles.Contains(tileId))
        {
            return(ElevationTile.FromNull());
        }

        // Read the elevation data from the corresponding file in streaming assets. Files are named by the TileId's quadkey.
        var elevationTileData = File.ReadAllBytes(Path.Combine(ElevationDataDirectory, tileId.ToKey() + ".et"));

        // The ElevationTile data has this layout:
        // * 0 - magic id (0x12345678)
        // * 4 - min elevation in meters (float)
        // * 8 - tile elevation range in meters (float)
        // * 12 - normalized elevation values (ushorts - 257*257 entries).
        var minElevationInMeters   = BitConverter.ToSingle(elevationTileData, 4);
        var elevationRangeInMeters = BitConverter.ToSingle(elevationTileData, 8);
        var elevationTile          =
            ElevationTile.FromNormalizedData(
                tileId,
                257,
                257,
                minElevationInMeters,
                elevationRangeInMeters,
                elevationTileData,
                12 /* offset */);

        // No async code was required so wrap in Task.
        return(Task.FromResult(elevationTile));
    }