public GeoPackageTile getTile ( BoundingBox requestBoundingBox ) { GeoPackageTile tile = null ; // Transform to the projection of the tiles ProjectionTransform transformRequestToTiles = requestProjection . getTransformation ( tilesProjection ) ; BoundingBox tilesBoundingBox = requestBoundingBox . transform ( transformRequestToTiles ) ; List < TileMatrix > tileMatrices = getTileMatrices ( tilesBoundingBox ) ; for ( int i = 0 ; tile == null && i < tileMatrices . size ( ) ; i ++ ) { TileMatrix tileMatrix = tileMatrices . get ( i ) ; TileCursor tileResults = retrieveTileResults ( tilesBoundingBox , tileMatrix ) ; if ( tileResults != null ) { try { if ( tileResults . getCount ( ) > 0 ) { BoundingBox requestProjectedBoundingBox = requestBoundingBox . transform ( transformRequestToTiles ) ; // Determine the requested tile dimensions, or use the dimensions of a single tile matrix tile int requestedTileWidth = width != null ? width : ( int ) tileMatrix . getTileWidth ( ) ; int requestedTileHeight = height != null ? height : ( int ) tileMatrix . getTileHeight ( ) ; // Determine the size of the tile to initially draw int tileWidth = requestedTileWidth ; int tileHeight = requestedTileHeight ; if ( ! sameProjection ) { tileWidth = ( int ) Math . round ( ( requestProjectedBoundingBox . getMaxLongitude ( ) - requestProjectedBoundingBox . getMinLongitude ( ) ) / tileMatrix . getPixelXSize ( ) ) ; tileHeight = ( int ) Math . round ( ( requestProjectedBoundingBox . getMaxLatitude ( ) - requestProjectedBoundingBox . getMinLatitude ( ) ) / tileMatrix . getPixelYSize ( ) ) ; } // Draw the resulting bitmap with the matching tiles Bitmap tileBitmap = drawTile ( tileMatrix , tileResults , requestProjectedBoundingBox , tileWidth , tileHeight ) ; // Create the tile if ( tileBitmap != null ) { // Project the tile if needed if ( ! sameProjection ) { Bitmap reprojectTile = reprojectTile ( tileBitmap , requestedTileWidth , requestedTileHeight , requestBoundingBox , transformRequestToTiles , tilesBoundingBox ) ; tileBitmap . recycle ( ) ; tileBitmap = reprojectTile ; } try { byte [ ] tileData = BitmapConverter . toBytes ( tileBitmap , COMPRESS_FORMAT ) ; tileBitmap . recycle ( ) ; tile = new GeoPackageTile ( requestedTileWidth , requestedTileHeight , tileData ) ; } catch ( IOException e ) { Log . e ( TileCreator . class . getSimpleName ( ) , "Failed to create tile. min lat: " + requestBoundingBox . getMinLatitude ( ) + ", max lat: " + requestBoundingBox . getMaxLatitude ( ) + ", min lon: " + requestBoundingBox . getMinLongitude ( ) + ", max lon: " + requestBoundingBox . getMaxLongitude ( ) , e ) ; } } } } finally { tileResults . close ( ) ; } } } return tile ; }
Get the tile from the request bounding box in the request projection