Java源码示例:org.osmdroid.tileprovider.MapTile
示例1
@Override
public void handleMessage(final Message msg) {
switch (msg.what) {
case MapTile.MAPTILE_SUCCESS_ID:
if (!ready && form.canDispatchEvent(null, "MapReady")) {
ready = true;
form.runOnUiThread(new Runnable() {
@Override
public void run() {
for (MapEventListener l : eventListeners) {
l.onReady(NativeOpenStreetMapController.this);
}
}
});
}
view.invalidate();
break;
}
}
示例2
public void setTile(final boolean state) {
map.setTileSource(new OnlineTileSourceBase("USGS Topo", ZOOM_LEVEL_MIN, ZOOM_LEVEL_MAX, 256, ".png", new String[]{url}) {
@Override
public String getTileURLString(MapTile aTile) {
if (state)
return "http://mt1.google.com/vt/lyrs=m&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel();
else
return "http://mt1.google.com/vt/lyrs=y&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel();
}
});
}
示例3
@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;
}
示例4
@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;
}