org.osmdroid.tileprovider.MapTile Java Examples

The following examples show how to use org.osmdroid.tileprovider.MapTile. 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: NativeOpenStreetMapController.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@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;
  }
}
 
Example #2
Source File: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
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();
        }
    });
}
 
Example #3
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 #4
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;
}