/** * Load a tile from cache. * Returns null if there is no corresponding cache entry or it could not be loaded. */ private Tile getCachedTile(String key) { if (mCache.isClosed()) { return null; } try { DiskLruCache.Snapshot snapshot = mCache.get(key); if (snapshot == null) { // tile is not in cache return null; } final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA)); final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT)); final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH)); if (data != null) { LOGD(TAG, "Cache hit for tile " + key); return new Tile(width, height, data); } } catch (IOException e) { // ignore error } return null; }
private boolean cacheTile(String key, Tile tile) { if (mCache.isClosed()) { return false; } try { DiskLruCache.Editor editor = mCache.edit(key); if (editor == null) { // editor is not available return false; } writeByteArrayToStream(tile.data, editor.newOutputStream(INDEX_DATA)); writeIntToStream(tile.height, editor.newOutputStream(INDEX_HEIGHT)); writeIntToStream(tile.width, editor.newOutputStream(INDEX_WIDTH)); editor.commit(); return true; } catch (IOException e) { // Tile could not be cached } return false; }
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2) { switch (paramInt1) { default: return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2); case 1598968902: paramParcel2.writeString("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); return true; } paramParcel1.enforceInterface("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); Tile localTile = a(paramParcel1.readInt(), paramParcel1.readInt(), paramParcel1.readInt()); paramParcel2.writeNoException(); if (localTile != null) { paramParcel2.writeInt(1); localTile.writeToParcel(paramParcel2, 1); return true; } paramParcel2.writeInt(0); return true; }
/** * Load a tile from cache. * Returns null if there is no corresponding cache entry or it could not be loaded. * * @param key * @return */ private Tile getCachedTile(String key) { try { DiskLruCache.Snapshot snapshot = mCache.get(key); if (snapshot == null) { // tile is not in cache return null; } final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA)); final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT)); final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH)); if (data != null) { LogUtils.LOGD(TAG, "Cache hit for tile " + key); return new Tile(width, height, data); } } catch (IOException e) { // ignore error } return null; }
private boolean cacheTile(String key, Tile tile) { try { DiskLruCache.Editor editor = mCache.edit(key); if (editor == null) { // editor is not available return false; } writeByteArrayToStream(tile.data, editor.newOutputStream(INDEX_DATA)); writeIntToStream(tile.height, editor.newOutputStream(INDEX_HEIGHT)); writeIntToStream(tile.width, editor.newOutputStream(INDEX_WIDTH)); editor.commit(); return true; } catch (IOException e) { // Tile could not be cached } return false; }
/** * Load a tile from cache. * Returns null if there is no corresponding cache entry or it could not be loaded. * * @param key * @return */ private Tile getCachedTile(String key) { try { DiskLruCache.Snapshot snapshot = mCache.get(key); if (snapshot == null) { // tile is not in cache return null; } final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA)); final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT)); final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH)); if (data != null) { LOGD(TAG, "Cache hit for tile " + key); return new Tile(width, height, data); } } catch (IOException e) { // ignore error } return null; }
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2) { switch (paramInt1) { default: break; case 1598968902: paramParcel2.writeString("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); return true; case 1: paramParcel1.enforceInterface("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); Tile localTile = getTile(paramParcel1.readInt(), paramParcel1.readInt(), paramParcel1.readInt()); paramParcel2.writeNoException(); if (localTile != null) { paramParcel2.writeInt(1); localTile.writeToParcel(paramParcel2, 1); } else { paramParcel2.writeInt(0); } return true; } return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2); }
public Tile getTile(int paramInt1, int paramInt2, int paramInt3) { Parcel localParcel1 = Parcel.obtain(); Parcel localParcel2 = Parcel.obtain(); try { localParcel1.writeInterfaceToken("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); localParcel1.writeInt(paramInt1); localParcel1.writeInt(paramInt2); localParcel1.writeInt(paramInt3); this.dU.transact(1, localParcel1, localParcel2, 0); localParcel2.readException(); Tile localTile; if (localParcel2.readInt() != 0) localTile = Tile.CREATOR.createFromParcel(localParcel2); else localTile = null; return localTile; } finally { localParcel2.recycle(); localParcel1.recycle(); } }
@Override public Tile getTile(int x, int y, int z) { // query the provider for a tile specified by x, y and z coordinates String[] projection = new String[]{TilesContract.COLUMN_TILE_DATA}; String selection = TilesContract.COLUMN_ZOOM_LEVEL + " = ? AND " + TilesContract.COLUMN_TILE_COLUMN + "= ? AND " + TilesContract.COLUMN_TILE_ROW + "= ?"; String[] selectionArgs = new String[]{String.valueOf(z), String.valueOf(x), String.valueOf((int) (Math.pow(2, z) - y - 1))}; // .mbtiles database use TSM coordinates // we need to switch to Google compatible coordinates // https://gist.github.com/tmcw/4954720 Cursor cursor = mContext.getContentResolver().query(Uri.parse(mContentProviderPath), projection, selection, selectionArgs, null); Tile tile = TileProvider.NO_TILE; if (cursor.moveToFirst()) tile = cursorToMapItem(cursor); // make sure to close the cursor cursor.close(); return tile; }
public static synchronized void initialize(Context context) { if (instance != null) { throw new Error("attempted to initialize " + BackgroundTileProvider.class.getName() + " more than once"); } InputStream in = null; try { in = context.getAssets().open("background_tile.png"); byte[] data = new byte[in.available()]; in.read(data); tile = new Tile(TILE_WIDTH, TILE_HEIGHT, data); } catch (IOException e) { throw new Error("failed to load offline tile asset", e); } finally { if (in != null) try { in.close(); } catch (Exception ignored) {} } instance = new BackgroundTileProvider(); }
@Override public Tile getTile(int x, int y, int zoom) { Matrix matrix = new Matrix(); float scale = (float) Math.pow(2, zoom) * mScale; matrix.postScale(scale, scale); matrix.postTranslate(-x * mDimension, -y * mDimension); Bitmap bitmap = Bitmap.createBitmap(mDimension, mDimension, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); c.setMatrix(matrix); for (Point p : mPoints) { c.drawCircle((float) p.x, (float) p.y, 1, new Paint()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return new Tile(mDimension, mDimension, baos.toByteArray()); }
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2) { switch (paramInt1) { default: return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2); case 1598968902: paramParcel2.writeString("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); return true; case 1: } paramParcel1.enforceInterface("com.google.android.gms.maps.model.internal.ITileProviderDelegate"); Tile localTile = a(paramParcel1.readInt(), paramParcel1.readInt(), paramParcel1.readInt()); paramParcel2.writeNoException(); if (localTile != null) { paramParcel2.writeInt(1); localTile.writeToParcel(paramParcel2, 1); return true; } paramParcel2.writeInt(0); return true; }
@Override public Tile getTile(int x, int y, int zoom) { Bitmap coorTile = drawTileCoors(x, y, zoom); ByteArrayOutputStream stream = new ByteArrayOutputStream(); coorTile.compress(Bitmap.CompressFormat.PNG, 0, stream); byte[] bitmapData = stream.toByteArray(); return new Tile((int) (TILE_SIZE_DP * mScaleFactor), (int) (TILE_SIZE_DP * mScaleFactor), bitmapData); }
@Override public Tile getTile(int x, int y, int zoom) { MapTile tile = new MapTile(zoom, x, y); Bitmap bitmap = source.renderTile(tile); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] bitmapdata = stream.toByteArray(); return new Tile(512, 512, bitmapdata); }
@Override public Tile getTile(int x, int y, int z) { byte[] tileImage = getTileImage(x, y, z); if (tileImage != null) { return new Tile(mTileWidth / 2, mTileHeight / 2, tileImage); } return NO_TILE; }
@Override public Tile getTile(int x, int y, int zoom) { TileGenerator tileGenerator = mPool.get(); byte[] tileData = tileGenerator.getTileImageData(x, y, zoom); mPool.restore(tileGenerator); return new Tile(mDimension, mDimension, tileData); }
/** * Load a tile. * If cached, the data for the tile is read from the underlying cache, otherwise the tile is * generated by the {@link com.google.android.gms.maps.model.TileProvider} and added to the * cache. */ @Override public Tile getTile(int x, int y, int zoom) { final String key = CachedTileProvider.generateKey(x, y, zoom, mKeyTag); Tile tile = getCachedTile(key); if (tile == null) { // tile not cached, load from provider and then cache tile = mTileProvider.getTile(x, y, zoom); if (cacheTile(key, tile)) { LOGD(TAG, "Added tile to cache " + key); } } return tile; }
/** * {@inheritDoc} */ @Override public Tile retrieveTile(int x, int y, int zoom) { GeoPackageTile geoPackageTile = retriever.getTile(x, y, zoom); Tile tile = GeoPackageOverlayFactory.getTile(geoPackageTile); return tile; }
/** * {@inheritDoc} */ @Override public Tile getTile(int x, int y, int zoom) { Tile tile = null; // Check if there is a tile if (hasTile(x, y, zoom)) { // Retrieve the tile tile = retrieveTile(x, y, zoom); } return tile; }
@Override public Tile getTile(int x, int y, int zoom) { if (zoom > maxZoomLevel) { return TileProvider.NO_TILE; } final String tileUri = MapboxUtils.getMapTileURL(mapboxId, mapboxAccessToken, zoom, x, y); byte[] data = DatabaseState.getOfflineDatabaseHandlerForMapId(context, mapboxId).dataForURL(tileUri); if (data == null || data.length == 0) return TileProvider.NO_TILE; return new Tile(MapboxUtils.TILE_WIDTH, MapboxUtils.TILE_HEIGHT, data); }