org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants Java Examples

The following examples show how to use org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants. 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: SafeTileWriter.java    From android_frameworks_mapsv1 with Apache License 2.0 6 votes vote down vote up
private boolean createFolderAndCheckIfExists(final File pFile) {
	if (pFile.mkdirs()) {
		return true;
	}
	if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
		Log.d(IMapView.LOGTAG,"Failed to create " + pFile + " - wait and check again");
	}

	// if create failed, wait a bit in case another thread created it
	try {
		Thread.sleep(500);
	} catch (final InterruptedException ignore) {
	}
	// and then check again
	if (pFile.exists()) {
		if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
			Log.d(IMapView.LOGTAG,"Seems like another thread created " + pFile);
		}
		return true;
	} else {
		if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
			Log.d(IMapView.LOGTAG,"File still doesn't exist: " + pFile);
		}
		return false;
	}
}
 
Example #2
Source File: TileSourcePolicy.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.1.7
 * Used to be in {@link TileDownloader}
 * @return the expiration time (as Epoch timestamp in milliseconds)
 */
public long computeExpirationTime(final String pHttpExpiresHeader, final String pHttpCacheControlHeader, final long pNow) {
    final Long override=Configuration.getInstance().getExpirationOverrideDuration();
    if (override != null) {
        return pNow + override;
    }

    final long extension = Configuration.getInstance().getExpirationExtendedDuration();
    final Long cacheControlDuration = getHttpCacheControlDuration(pHttpCacheControlHeader);
    if (cacheControlDuration != null) {
        return pNow + cacheControlDuration * 1000 + extension;
    }

    final Long httpExpiresTime = getHttpExpiresTime(pHttpExpiresHeader);
    if (httpExpiresTime != null) {
        return httpExpiresTime + extension;
    }

    return pNow + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + extension;
}
 
Example #3
Source File: TileDownloader.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.0.3
 * @return the expiration time (as Epoch timestamp in milliseconds)
 * @deprecated Use {@link TileSourcePolicy#computeExpirationTime(HttpURLConnection, long)} instead
 */
@Deprecated
public long computeExpirationTime(final String pHttpExpiresHeader, final String pHttpCacheControlHeader, final long pNow) {
    final Long override=Configuration.getInstance().getExpirationOverrideDuration();
    if (override != null) {
        return pNow + override;
    }

    final long extension = Configuration.getInstance().getExpirationExtendedDuration();
    final Long cacheControlDuration = getHttpCacheControlDuration(pHttpCacheControlHeader);
    if (cacheControlDuration != null) {
        return pNow + cacheControlDuration * 1000 + extension;
    }

    final Long httpExpiresTime = getHttpExpiresTime(pHttpExpiresHeader);
    if (httpExpiresTime != null) {
        return httpExpiresTime + extension;
    }

    return pNow + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + extension;
}
 
Example #4
Source File: TileSourcePolicy.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.1.7
 * @return the expiration time (as Epoch timestamp in milliseconds)
 */
public long computeExpirationTime(final HttpURLConnection pHttpURLConnection, final long pNow) {
    final String expires = pHttpURLConnection.getHeaderField(OpenStreetMapTileProviderConstants.HTTP_EXPIRES_HEADER);
    final String cacheControl = pHttpURLConnection.getHeaderField(OpenStreetMapTileProviderConstants.HTTP_CACHECONTROL_HEADER);
    final long result = computeExpirationTime(expires, cacheControl, pNow);
    if (Configuration.getInstance().isDebugMapTileDownloader()) {
        Log.d(IMapView.LOGTAG, "computeExpirationTime('" + expires + "','" + cacheControl + "'," + pNow + "=" + result);
    }
    return result;
}
 
Example #5
Source File: SafeTileWriter.java    From android_frameworks_mapsv1 with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: MapTileApproximater.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Approximate a tile from a lower zoom level
 *
 * @since 6.0.0
 * @param pMapTileIndex Destination tile, for the same place on the planet as the source, but on a higher zoom
 * @return
 */
public Bitmap approximateTileFromLowerZoom(final long pMapTileIndex) {
    for (int zoomDiff = 1; MapTileIndex.getZoom(pMapTileIndex) - zoomDiff >= OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL ; zoomDiff ++) {
        final Bitmap bitmap = approximateTileFromLowerZoom(pMapTileIndex, zoomDiff);
        if (bitmap != null) {
            return bitmap;
        }
    }
    return null;
}
 
Example #7
Source File: MapTileApproximater.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
private void computeZoomLevels() {
    boolean first = true;
    minZoomLevel = OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
    for (final MapTileModuleProviderBase provider : mProviders) {
        final int otherMin = provider.getMinimumZoomLevel();;
        if (first) {
            first = false;
            minZoomLevel = otherMin;
        } else {
            minZoomLevel = Math.min(minZoomLevel, otherMin);
        }
    }
}
 
Example #8
Source File: MapTileProviderArray.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public int getMaximumZoomLevel() {
	int result = OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
	synchronized (mTileProviderList) {
		for (final MapTileModuleProviderBase tileProvider : mTileProviderList) {
			if (tileProvider.getMaximumZoomLevel() > result) {
				result = tileProvider.getMaximumZoomLevel();
			}
		}
	}
	return result;
}
 
Example #9
Source File: SafeTileWriter.java    From android_frameworks_mapsv1 with Apache License 2.0 5 votes vote down vote up
/**
 * If the cache size is greater than the max then trim it down to the trim level. This method is
 * synchronized so that only one thread can run it at a time.
 */
private void cutCurrentCache() {

	final File lock=safeTilePathBase;
	synchronized (lock) {

		if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {

			Log.d(IMapView.LOGTAG,"Trimming tile cache from " + mUsedCacheSpace + " to "
					+ OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES);

			final List<File> z = getDirectoryFileList(safeTilePathBase);

			// order list by files day created from old to new
			final File[] files = z.toArray(new File[0]);
			Arrays.sort(files, new Comparator<File>() {
				@Override
				public int compare(final File f1, final File f2) {
					return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
				}
			});

			for (final File file : files) {
				if (mUsedCacheSpace <= OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {
					break;
				}

				final long length = file.length();
				if (file.delete()) {
					mUsedCacheSpace -= length;
				}
			}

			Log.d(IMapView.LOGTAG,"Finished trimming tile cache");
		}
	}
}
 
Example #10
Source File: TileWriter.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @since 5.6.5
 */
public File getFile(final ITileSource pTileSource, final long pMapTileIndex) {
	return new File(Configuration.getInstance().getOsmdroidTileCache(), pTileSource.getTileRelativeFilenameString(pMapTileIndex)
			+ OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
}
 
Example #11
Source File: SafeMapTileFilesystemProvider.java    From android_frameworks_mapsv1 with Apache License 2.0 4 votes vote down vote up
@Override
public Drawable loadTile(final MapTileRequestState pState) throws CantContinueException {

	ITileSource tileSource = mTileSource.get();
	if (tileSource == null) {
		return null;
	}

	final MapTile tile = pState.getMapTile();

	// if there's no sdcard then don't do anything
	if (!getSdCardAvailable()) {
		if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
			Log.d(IMapView.LOGTAG,"No sdcard - do nothing for tile: " + tile);
		}
		return null;
	}

	// 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 = new File(safeTilePathBase,
			tileSource.getTileRelativeFilenameString(tile) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
	if (file.exists()) {

		try {
			final Drawable drawable = tileSource.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 (OpenStreetMapTileProviderConstants.DEBUGMODE) {
					Log.d(IMapView.LOGTAG,"Tile expired: " + tile);
				}
				ExpirableBitmapDrawable.setDrawableExpired(drawable);
			}

			return drawable;
		} catch (final LowMemoryException e) {
			// low memory so empty the queue
			Log.w(IMapView.LOGTAG,"LowMemoryException downloading MapTile: " + tile + " : " + e);
			throw new CantContinueException(e);
		}
	}

	// If we get here then there is no file in the file cache
	return null;
}
 
Example #12
Source File: SafeMapTileFilesystemProvider.java    From android_frameworks_mapsv1 with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
Example #13
Source File: MapTileAssetsProvider.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
Example #14
Source File: MapTileFilesystemProvider.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public MapTileFilesystemProvider(final IRegisterReceiver pRegisterReceiver,
		final ITileSource aTileSource) {
	this(pRegisterReceiver, aTileSource, Configuration.getInstance().getExpirationExtendedDuration() + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE);
}
 
Example #15
Source File: MapTileFilesystemProvider.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
Example #16
Source File: MapTileDownloader.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
	OnlineTileSourceBase tileSource = mTileSource.get();
	return (tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL);
}
 
Example #17
Source File: MapTileSqlCacheProvider.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
    ITileSource tileSource = mTileSource.get();
    return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
Example #18
Source File: MapTileFileArchiveProvider.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
Example #19
Source File: SafeMapTileFilesystemProvider.java    From android_frameworks_mapsv1 with Apache License 2.0 4 votes vote down vote up
public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
									 final ITileSource pTileSource, final long pMaximumCachedFileAge) {
	this(context, pRegisterReceiver, pTileSource, pMaximumCachedFileAge,
			OpenStreetMapTileProviderConstants.NUMBER_OF_TILE_FILESYSTEM_THREADS,
			OpenStreetMapTileProviderConstants.TILE_FILESYSTEM_MAXIMUM_QUEUE_SIZE);
}
 
Example #20
Source File: CacheManager.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public static File getFileName(ITileSource tileSource, final long pMapTileIndex) {
    final File file = new File(Configuration.getInstance().getOsmdroidTileCache(),
            tileSource.getTileRelativeFilenameString(pMapTileIndex) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
    return file;
}
 
Example #21
Source File: SafeMapTileFilesystemProvider.java    From android_frameworks_mapsv1 with Apache License 2.0 4 votes vote down vote up
public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
								 final ITileSource aTileSource) {
	this(context, pRegisterReceiver, aTileSource, OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE);
}