org.osmdroid.tileprovider.tilesource.ITileSource Java Examples
The following examples show how to use
org.osmdroid.tileprovider.tilesource.ITileSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapTilePreCache.java From osmdroid with Apache License 2.0 | 6 votes |
/** * Search for a tile bitmap into the list of providers and put it in the memory cache */ private void search(final long pMapTileIndex) { for (final MapTileModuleProviderBase provider : mProviders) { try { if (provider instanceof MapTileDownloader) { final ITileSource tileSource = ((MapTileDownloader) provider).getTileSource(); if (tileSource instanceof OnlineTileSourceBase) { if (!((OnlineTileSourceBase)tileSource).getTileSourcePolicy().acceptsPreventive()) { continue; } } } final Drawable drawable = provider.getTileLoader().loadTileIfReachable(pMapTileIndex); if (drawable == null) { continue; } mCache.putTile(pMapTileIndex, drawable); return; } catch (CantContinueException exception) { // just dismiss that lazily: we don't need to be severe here } } }
Example #2
Source File: GeoPackageProvider.java From osmdroid with Apache License 2.0 | 6 votes |
public GeoPackageProvider(final IRegisterReceiver pRegisterReceiver, final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource, final Context pContext, final IFilesystemCache cacheWriter, File[] databases) { super(pTileSource, pRegisterReceiver); Log.i(IMapView.LOGTAG, "Geopackage support is BETA. Please report any issues"); if (cacheWriter != null) { tileWriter = cacheWriter; } else { if (Build.VERSION.SDK_INT < 10) { tileWriter = new TileWriter(); } else { tileWriter = new SqlTileWriter(); } } mTileProviderList.add(MapTileProviderBasic.getMapTileFileStorageProviderBase(pRegisterReceiver, pTileSource, tileWriter)); geopackage = new GeoPackageMapTileModuleProvider(databases, pContext, tileWriter); mTileProviderList.add(geopackage); }
Example #3
Source File: TileWriter.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public Drawable loadTile(final ITileSource pTileSource, final long pMapTileIndex) throws Exception{ // Check the tile source to see if its file is available and if so, then render the // drawable and return the tile final File file = getFile(pTileSource, pMapTileIndex); if (!file.exists()) { return null; } final Drawable drawable = pTileSource.getDrawable(file.getPath()); // Check to see if file has expired final long now = System.currentTimeMillis(); final long lastModified = file.lastModified(); final boolean fileExpired = lastModified < now - mMaximumCachedFileAge; if (fileExpired && drawable != null) { if (Configuration.getInstance().isDebugMode()) { Log.d(IMapView.LOGTAG,"Tile expired: " + MapTileIndex.toString(pMapTileIndex)); } ExpirableBitmapDrawable.setState(drawable, ExpirableBitmapDrawable.EXPIRED); } return drawable; }
Example #4
Source File: TilesOverlay.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(final Menu pMenu, final int pMenuIdOffset, final MapView pMapView) { final SubMenu mapMenu = pMenu.addSubMenu(0, Menu.NONE, Menu.NONE, R.string.map_mode).setIcon(R.drawable.ic_menu_mapmode); for (int a = 0; a < TileSourceFactory.getTileSources().size(); a++) { final ITileSource tileSource = TileSourceFactory.getTileSources().get(a); mapMenu.add(MENU_MAP_MODE + pMenuIdOffset, MENU_TILE_SOURCE_STARTING_ID + a + pMenuIdOffset, Menu.NONE, tileSource.name()); } mapMenu.setGroupCheckable(MENU_MAP_MODE + pMenuIdOffset, true, true); if (ctx!=null) { final String title = ctx.getString( pMapView.useDataConnection() ? R.string.set_mode_offline : R.string.set_mode_online); final Drawable icon = ctx.getResources().getDrawable(R.drawable.ic_menu_offline); pMenu.add(0, MENU_OFFLINE + pMenuIdOffset, Menu.NONE, title).setIcon(icon); pMenu.add(0, MENU_SNAPSHOT + pMenuIdOffset, Menu.NONE, R.string.snapshot); pMenu.add(0, MENU_STATES + pMenuIdOffset, Menu.NONE, R.string.states); } return true; }
Example #5
Source File: MapTileFileArchiveProvider.java From osmdroid with Apache License 2.0 | 6 votes |
/** * * @since 6.0.0 * @param pRegisterReceiver * @param pTileSource * @param pArchives * @param ignoreTileSource if true, tile source is ignored */ public MapTileFileArchiveProvider(final IRegisterReceiver pRegisterReceiver, final ITileSource pTileSource, final IArchiveFile[] pArchives, final boolean ignoreTileSource) { super(pRegisterReceiver, Configuration.getInstance().getTileFileSystemThreads(), Configuration.getInstance().getTileFileSystemMaxQueueSize()); this.ignoreTileSource=ignoreTileSource; setTileSource(pTileSource); if (pArchives == null) { mSpecificArchivesProvided = false; findArchiveFiles(); } else { mSpecificArchivesProvided = true; for (int i = pArchives.length - 1; i >= 0; i--) { mArchiveFiles.add(pArchives[i]); } } }
Example #6
Source File: MapTileFileArchiveProvider.java From osmdroid with Apache License 2.0 | 6 votes |
private synchronized InputStream getInputStream(final long pMapTileIndex, final ITileSource tileSource) { for (final IArchiveFile archiveFile : mArchiveFiles) { if (archiveFile!=null) { final InputStream in = archiveFile.getInputStream(tileSource, pMapTileIndex); if (in != null) { if (Configuration.getInstance().isDebugMode()) { Log.d(IMapView.LOGTAG, "Found tile " + MapTileIndex.toString(pMapTileIndex) + " in " + archiveFile); } return in; } } } return null; }
Example #7
Source File: TileWriter.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean remove(final ITileSource pTileSource, final long pMapTileIndex) { final File file = getFile(pTileSource, pMapTileIndex); if (file.exists()) { try { return file.delete(); }catch (Exception ex){ //potential io exception Log.i(IMapView.LOGTAG, "Unable to delete cached tile from " + pTileSource.name() + " " + MapTileIndex.toString(pMapTileIndex) , ex); } } return false; }
Example #8
Source File: TileWriter.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean saveFile(final ITileSource pTileSource, final long pMapTileIndex, final InputStream pStream, final Long pExpirationTime) { final File file = getFile(pTileSource, pMapTileIndex); if (Configuration.getInstance().isDebugTileProviders()){ Log.d(IMapView.LOGTAG, "TileWrite " + file.getAbsolutePath()); } final File parent = file.getParentFile(); if (!parent.exists() && !createFolderAndCheckIfExists(parent)) { return false; } BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()), StreamUtils.IO_BUFFER_SIZE); final long length = StreamUtils.copy(pStream, outputStream); mUsedCacheSpace += length; if (mUsedCacheSpace > Configuration.getInstance().getTileFileSystemCacheMaxBytes()) { cutCurrentCache(); // TODO perhaps we should do this in the background } } catch (final IOException e) { Counters.fileCacheSaveErrors++; return false; } finally { if (outputStream != null) { StreamUtils.closeStream(outputStream); } } return true; }
Example #9
Source File: MapView.java From osmdroid with Apache License 2.0 | 5 votes |
private void updateTileSizeForDensity(final ITileSource aTileSource) { int tile_size = aTileSource.getTileSizePixels(); float density = getResources().getDisplayMetrics().density * 256 / tile_size ; int size = (int) ( tile_size * (isTilesScaledToDpi() ? density * mTilesScaleFactor : mTilesScaleFactor)); if (Configuration.getInstance().isDebugMapView()) Log.d(IMapView.LOGTAG, "Scaling tiles to " + size); TileSystem.setTileSize(size); }
Example #10
Source File: SafeMapTileProviderBasic.java From android_frameworks_mapsv1 with Apache License 2.0 | 5 votes |
/** * Creates a {@link SafeMapTileProviderBasic}. */ public SafeMapTileProviderBasic(Context context, final IRegisterReceiver pRegisterReceiver, final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource) { super(pTileSource, pRegisterReceiver); final SafeTileWriter tileWriter = new SafeTileWriter(context); final SafeMapTileFilesystemProvider fileSystemProvider = new SafeMapTileFilesystemProvider(context, pRegisterReceiver, pTileSource); mTileProviderList.add(fileSystemProvider); final MapTileDownloader downloaderProvider = new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck); mTileProviderList.add(downloaderProvider); }
Example #11
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void setTileSource(final ITileSource aTileSource) { super.setTileSource(aTileSource); synchronized (mTileProviderList) { for (final MapTileModuleProviderBase tileProvider : mTileProviderList) { tileProvider.setTileSource(aTileSource); clearTileCache(); } } }
Example #12
Source File: MapView.java From osmdroid with Apache License 2.0 | 5 votes |
public void setTileSource(final ITileSource aTileSource) { mTileProvider.setTileSource(aTileSource); updateTileSizeForDensity(aTileSource); this.checkZoomButtons(); this.setZoomLevel(mZoomLevel); // revalidate zoom level postInvalidate(); }
Example #13
Source File: MapView.java From osmdroid with Apache License 2.0 | 5 votes |
private ITileSource getTileSourceFromAttributes(final AttributeSet aAttributeSet) { ITileSource tileSource = TileSourceFactory.DEFAULT_TILE_SOURCE; if (aAttributeSet != null) { final String tileSourceAttr = aAttributeSet.getAttributeValue(null, "tilesource"); if (tileSourceAttr != null) { try { final ITileSource r = TileSourceFactory.getTileSource(tileSourceAttr); Log.i(IMapView.LOGTAG,"Using tile source specified in layout attributes: " + r); tileSource = r; } catch (final IllegalArgumentException e) { Log.w(IMapView.LOGTAG,"Invalid tile source specified in layout attributes: " + tileSource); } } } if (aAttributeSet != null && tileSource instanceof IStyledTileSource) { final String style = aAttributeSet.getAttributeValue(null, "style"); if (style == null) { Log.i(IMapView.LOGTAG,"Using default style: 1"); } else { Log.i(IMapView.LOGTAG,"Using style specified in layout attributes: " + style); ((IStyledTileSource<?>) tileSource).setStyle(style); } } Log.i(IMapView.LOGTAG,"Using tile source: " + tileSource.name()); return tileSource; }
Example #14
Source File: GeoPackageFeatureTileProvider.java From osmdroid with Apache License 2.0 | 5 votes |
public GeoPackageFeatureTileProvider(ITileSource pTileSource) { super(pTileSource); Log.i(IMapView.LOGTAG, "Geopackage support is BETA. Please report any issues"); if (Build.VERSION.SDK_INT < 10) { tileWriter = new TileWriter(); } else { tileWriter = new SqlTileWriter(); } }
Example #15
Source File: SqliteArchiveTileWriter.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean exists(ITileSource pTileSource, final long pMapTileIndex) { try { final long index = SqlTileWriter.getIndex(pMapTileIndex); final Cursor cur = getTileCursor(SqlTileWriter.getPrimaryKeyParameters(index, pTileSource)); final boolean result = (cur.getCount() != 0); cur.close(); return result; } catch (Throwable ex) { Log.e(IMapView.LOGTAG, "Unable to store cached tile from " + pTileSource.name() + " " + MapTileIndex.toString(pMapTileIndex), ex); } return false; }
Example #16
Source File: DatabaseFileArchive.java From osmdroid with Apache License 2.0 | 5 votes |
public byte[] getImage(final ITileSource pTileSource, final long pMapTileIndex) { if (mDatabase==null || !mDatabase.isOpen()) { if (Configuration.getInstance().isDebugTileProviders()) Log.d(IMapView.LOGTAG,"Skipping DatabaseFileArchive lookup, database is closed"); return null; } try { byte[] bits=null; final String[] tile = {COLUMN_TILE}; final long x = MapTileIndex.getX(pMapTileIndex); final long y = MapTileIndex.getY(pMapTileIndex); final long z = MapTileIndex.getZoom(pMapTileIndex); final long index = ((z << z) + x << z) + y; Cursor cur; if(!mIgnoreTileSource) { cur = mDatabase.query(TABLE, tile, COLUMN_KEY+" = " + index + " and " + COLUMN_PROVIDER + " = ?", new String[]{pTileSource.name()}, null, null, null); } else { cur = mDatabase.query(TABLE, tile, COLUMN_KEY+" = " + index, null, null, null, null); } if(cur.getCount() != 0) { cur.moveToFirst(); bits = (cur.getBlob(0)); } cur.close(); if(bits != null) { return bits; } } catch(final Throwable e) { Log.w(IMapView.LOGTAG,"Error getting db stream: " + MapTileIndex.toString(pMapTileIndex), e); } return null; }
Example #17
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 5 votes |
/** * Creates an {@link MapTileProviderArray} with the specified tile providers. * * @param aRegisterReceiver * a {@link IRegisterReceiver} * @param pTileProviderArray * an array of {@link MapTileModuleProviderBase} */ public MapTileProviderArray(final ITileSource pTileSource, final IRegisterReceiver aRegisterReceiver, final MapTileModuleProviderBase[] pTileProviderArray) { super(pTileSource); mRegisterReceiver=aRegisterReceiver; mTileProviderList = new ArrayList<>(); Collections.addAll(mTileProviderList, pTileProviderArray); }
Example #18
Source File: MapTileAssetsProvider.java From osmdroid with Apache License 2.0 | 5 votes |
public MapTileAssetsProvider(final IRegisterReceiver pRegisterReceiver, final AssetManager pAssets, final ITileSource pTileSource) { this(pRegisterReceiver, pAssets, pTileSource, Configuration.getInstance().getTileDownloadThreads(), Configuration.getInstance().getTileDownloadMaxQueueSize() ); }
Example #19
Source File: MapTileAssetsProvider.java From osmdroid with Apache License 2.0 | 5 votes |
public MapTileAssetsProvider(final IRegisterReceiver pRegisterReceiver, final AssetManager pAssets, final ITileSource pTileSource, int pThreadPoolSize, int pPendingQueueSize) { super(pRegisterReceiver, pThreadPoolSize, pPendingQueueSize); setTileSource(pTileSource); mAssets = pAssets; }
Example #20
Source File: MapTileFilesystemProvider.java From osmdroid with Apache License 2.0 | 5 votes |
/** * Provides a file system based cache tile provider. Other providers can register and store data * in the cache. * * @param pRegisterReceiver */ public MapTileFilesystemProvider(final IRegisterReceiver pRegisterReceiver, final ITileSource pTileSource, final long pMaximumCachedFileAge, int pThreadPoolSize, int pPendingQueueSize) { super(pRegisterReceiver, pThreadPoolSize, pPendingQueueSize); setTileSource(pTileSource); mWriter.setMaximumCachedFileAge(pMaximumCachedFileAge); }
Example #21
Source File: SafeTileWriter.java From android_frameworks_mapsv1 with Apache License 2.0 | 5 votes |
@Override public boolean saveFile(final ITileSource pTileSource, final MapTile pTile, final InputStream pStream) { final File file = new File(safeTilePathBase, pTileSource.getTileRelativeFilenameString(pTile) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION); final File parent = file.getParentFile(); if (!parent.exists() && !createFolderAndCheckIfExists(parent)) { return false; } BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()), StreamUtils.IO_BUFFER_SIZE); final long length = StreamUtils.copy(pStream, outputStream); mUsedCacheSpace += length; if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_MAX_CACHE_SIZE_BYTES) { cutCurrentCache(); // TODO perhaps we should do this in the background } } catch (final IOException e) { return false; } finally { if (outputStream != null) { StreamUtils.closeStream(outputStream); } } return true; }
Example #22
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 5 votes |
public MapTileDownloader(final ITileSource pTileSource, final IFilesystemCache pFilesystemCache, final INetworkAvailablityCheck pNetworkAvailablityCheck) { this(pTileSource, pFilesystemCache, pNetworkAvailablityCheck, Configuration.getInstance().getTileDownloadThreads(), Configuration.getInstance().getTileDownloadMaxQueueSize()); }
Example #23
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 5 votes |
public MapTileDownloader(final ITileSource pTileSource, final IFilesystemCache pFilesystemCache, final INetworkAvailablityCheck pNetworkAvailablityCheck, int pThreadPoolSize, int pPendingQueueSize) { super(pThreadPoolSize, pPendingQueueSize); mFilesystemCache = pFilesystemCache; mNetworkAvailablityCheck = pNetworkAvailablityCheck; setTileSource(pTileSource); }
Example #24
Source File: SampleLieFi.java From osmdroid with Apache License 2.0 | 5 votes |
private MapTileProviderLieFi(final IRegisterReceiver pRegisterReceiver, final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource, final Context pContext, final IFilesystemCache cacheWriter) { super(pTileSource, pRegisterReceiver); mNetworkAvailabilityCheck = aNetworkAvailablityCheck; if (cacheWriter != null) { tileWriter = cacheWriter; } else { tileWriter = new SqlTileWriter(); } final MapTileAssetsProvider assetsProvider = new MapTileAssetsProvider( pRegisterReceiver, pContext.getAssets(), pTileSource); mTileProviderList.add(assetsProvider); final MapTileFileStorageProviderBase cacheProvider = MapTileProviderBasic.getMapTileFileStorageProviderBase(pRegisterReceiver, pTileSource, tileWriter); mTileProviderList.add(cacheProvider); final MapTileFileArchiveProvider archiveProvider = new MapTileFileArchiveProvider( pRegisterReceiver, pTileSource); mTileProviderList.add(archiveProvider); final MapTileApproximater approximationProvider = new MapTileApproximater(); mTileProviderList.add(approximationProvider); approximationProvider.addProvider(assetsProvider); approximationProvider.addProvider(cacheProvider); approximationProvider.addProvider(archiveProvider); final MapTileDownloader downloaderProvider = new MapTileDownloaderLieFi(pTileSource, tileWriter, aNetworkAvailablityCheck); mTileProviderList.add(downloaderProvider); getTileCache().getProtectedTileContainers().add(this); }
Example #25
Source File: SampleVeryHighZoomLevel.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays() { mMapView.setUseDataConnection(false); final ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mMapView); scaleBarOverlay.setCentred(true); scaleBarOverlay.setScaleBarOffset(200, 10); mMapView.getOverlays().add(scaleBarOverlay); final ITileSource tileSource = new XYTileSource( "Abstract", 0, 29, 256, ".png", new String[]{"http://localhost/"}, "abstract data"); mMapView.setUseDataConnection(false); final MapTileAssetsProvider assetsProvider = new MapTileAssetsProvider(new SimpleRegisterReceiver(getContext()), getActivity().getAssets(), tileSource); final MapTileApproximater approximationProvider = new MapTileApproximater(); approximationProvider.addProvider(assetsProvider); final MapTileProviderArray array = new MapTileProviderArray( tileSource, new SimpleRegisterReceiver(getContext()), new MapTileModuleProviderBase[]{assetsProvider, approximationProvider}); mMapView.setTileProvider(array); mMapView.getController().setZoom(29.); // cf. https://fr.wikipedia.org/wiki/Point_z%C3%A9ro_des_routes_de_France // In English: starting point of all French roads mMapView.setExpectedCenter(new GeoPoint(48.85340215825712, 2.348784611094743)); mMapView.invalidate(); }
Example #26
Source File: MapTileSqlCacheProvider.java From osmdroid with Apache License 2.0 | 5 votes |
/** * The tiles may be found on several media. This one works with tiles stored on database. * It and its friends are typically created and controlled by {@link MapTileProviderBase}. */ public MapTileSqlCacheProvider(final IRegisterReceiver pRegisterReceiver, final ITileSource pTileSource) { super(pRegisterReceiver, Configuration.getInstance().getTileFileSystemThreads(), Configuration.getInstance().getTileFileSystemMaxQueueSize()); setTileSource(pTileSource); mWriter = new SqlTileWriter(); }
Example #27
Source File: MapTileSqlCacheProvider.java From osmdroid with Apache License 2.0 | 5 votes |
/** * returns true if the given tile for the current map source exists in the cache db */ public boolean hasTile(final long pMapTileIndex) { ITileSource tileSource = mTileSource.get(); if (tileSource == null) { return false; } return mWriter.getExpirationTimestamp(tileSource, pMapTileIndex) != null; }
Example #28
Source File: MapTileFileArchiveProvider.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public Drawable loadTile(final long pMapTileIndex) { Drawable returnValue=null; ITileSource tileSource = mTileSource.get(); if (tileSource == null) { return null; } InputStream inputStream = null; try { if (Configuration.getInstance().isDebugMode()) { Log.d(IMapView.LOGTAG,"Archives - Tile doesn't exist: " + MapTileIndex.toString(pMapTileIndex)); } inputStream = getInputStream(pMapTileIndex, tileSource); if (inputStream != null) { if (Configuration.getInstance().isDebugMode()) { Log.d(IMapView.LOGTAG,"Use tile from archive: " + MapTileIndex.toString(pMapTileIndex)); } final Drawable drawable = tileSource.getDrawable(inputStream); returnValue = drawable; } } catch (final Throwable e) { Log.e(IMapView.LOGTAG,"Error loading tile", e); } finally { if (inputStream != null) { StreamUtils.closeStream(inputStream); } } return returnValue; }
Example #29
Source File: MapTileProviderBasic.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @since 6.0.3 * cf. https://github.com/osmdroid/osmdroid/issues/1172 */ public static MapTileFileStorageProviderBase getMapTileFileStorageProviderBase( final IRegisterReceiver pRegisterReceiver, final ITileSource pTileSource, final IFilesystemCache pTileWriter ) { if (pTileWriter instanceof TileWriter) { return new MapTileFilesystemProvider(pRegisterReceiver, pTileSource); } return new MapTileSqlCacheProvider(pRegisterReceiver, pTileSource); }
Example #30
Source File: CacheManager.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @since 6.0 */ public CacheManager(final ITileSource pTileSource, final IFilesystemCache pWriter, final int pMinZoomLevel, final int pMaxZoomLevel) throws TileSourcePolicyException{ mTileSource = pTileSource; mTileWriter = pWriter; mMinZoomLevel = pMinZoomLevel; mMaxZoomLevel = pMaxZoomLevel; }