@ SuppressWarnings ( "deprecation" ) @ TargetApi ( Build . VERSION_CODES . HONEYCOMB_MR2 ) public static int getMinimumCacheSize ( Context c , int tileSize , double overdrawFactor , float screenRatio ) { WindowManager wm = ( WindowManager ) c . getSystemService ( Context . WINDOW_SERVICE ) ; Display display = wm . getDefaultDisplay ( ) ; int height ; int width ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . HONEYCOMB_MR2 ) { Point p = new Point ( ) ; display . getSize ( p ) ; height = p . y ; width = p . x ; } else { // deprecated since Android 13 height = display . getHeight ( ) ; width = display . getWidth ( ) ; } // height * overdrawFactor / tileSize calculates the number of tiles that would cover // the view port, adding 1 is required since we can have part tiles on either side, // adding 2 adds another row/column as spare and ensures that we will generally have // a larger number of tiles in the cache than a TileLayer will render for a view. // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part // of a screen (the result can be too low if a MapView is very narrow). // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the // middle of a view. Dimension dimension = FrameBufferController . calculateFrameBufferDimension ( new Dimension ( width , height ) , overdrawFactor ) ; return ( int ) Math . max ( 4 , screenRatio * ( 2 + ( dimension . height / tileSize ) ) * ( 2 + ( dimension . width / tileSize ) ) ) ; }
Compute the minimum cache size for a view . When the cache is created we do not actually know the size of the mapview so the screenRatio is an approximation of the required size . For the view size we use the frame buffer calculated dimension .