org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase Java Examples
The following examples show how to use
org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase.
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: MapTileDownloader.java From osmdroid with Apache License 2.0 | 6 votes |
/** * downloads a tile and follows http redirects */ protected Drawable downloadTile(final long pMapTileIndex, final int redirectCount, final String targetUrl) throws CantContinueException { final OnlineTileSourceBase tileSource = mTileSource.get(); if (tileSource == null) { return null; } try { tileSource.acquire(); } catch(final InterruptedException e) { return null; } try { return mTileDownloader.downloadTile(pMapTileIndex, redirectCount, targetUrl, mFilesystemCache, tileSource); } finally { tileSource.release(); } }
Example #2
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 #3
Source File: CacheManager.java From osmdroid with Apache License 2.0 | 6 votes |
public CacheManagerAction getDownloadingAction() { return new CacheManagerAction() { @Override public boolean preCheck() { if (mTileSource instanceof OnlineTileSourceBase) { if (!((OnlineTileSourceBase) mTileSource).getTileSourcePolicy().acceptsBulkDownload()) { throw new TileSourcePolicyException("This online tile source doesn't support bulk download"); } return true; } else { Log.e(IMapView.LOGTAG, "TileSource is not an online tile source"); return false; } } @Override public int getProgressModulo() { return 10; } @Override public boolean tileAction(final long pMapTileIndex) { return !loadTile((OnlineTileSourceBase) mTileSource, pMapTileIndex); } }; }
Example #4
Source File: PMap.java From PHONK with GNU General Public License v3.0 | 5 votes |
/** * Set a new tile source such as mapbox and others * * @param type * @return */ @PhonkMethod public MapView tileSource(String type) { OnlineTileSourceBase source; if (type.equals("hikebikemap")) { source = TileSourceFactory.HIKEBIKEMAP; } else { source = TileSourceFactory.MAPNIK; } mapView.setTileSource(source); return mapView; }
Example #5
Source File: FragmentiGapMap.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
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 #6
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void setTileSource(final ITileSource tileSource) { // We are only interested in OnlineTileSourceBase tile sources if (tileSource instanceof OnlineTileSourceBase) { mTileSource.set((OnlineTileSourceBase) tileSource); } else { // Otherwise shut down the tile downloader mTileSource.set(null); } }
Example #7
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public Drawable loadTile(final long pMapTileIndex) throws CantContinueException { OnlineTileSourceBase tileSource = mTileSource.get(); if (tileSource == null) { return null; } if (mNetworkAvailablityCheck != null && !mNetworkAvailablityCheck.getNetworkAvailable()) { if (Configuration.getInstance().isDebugMode()) { Log.d(IMapView.LOGTAG, "Skipping " + getName() + " due to NetworkAvailabliltyCheck."); } return null; } final String tileURLString = tileSource.getTileURLString(pMapTileIndex); if (TextUtils.isEmpty(tileURLString)) { return null; //unlikely but just in case } if (mUrlBackoff.shouldWait(tileURLString)) { return null; } final Drawable result = downloadTile(pMapTileIndex, 0, tileURLString); if (result == null) { mUrlBackoff.next(tileURLString); } else { mUrlBackoff.remove(tileURLString); } return result; }
Example #8
Source File: CacheManager.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @return true if success, false if error */ public boolean loadTile(final OnlineTileSourceBase tileSource, final long pMapTileIndex) { //check if file is already downloaded: File file = getFileName(tileSource, pMapTileIndex); if (file.exists()) { return true; } //check if the destination already has the file if (mTileWriter.exists(tileSource, pMapTileIndex)){ return true; } return forceLoadTile(tileSource, pMapTileIndex); }
Example #9
Source File: CacheManager.java From osmdroid with Apache License 2.0 | 5 votes |
/** * Actual tile download, regardless of the tile being already present in the cache * * @return true if success, false if error * @since 5.6.5 */ public boolean forceLoadTile(final OnlineTileSourceBase tileSource, final long pMapTileIndex) { try { final Drawable drawable = mTileDownloader.downloadTile(pMapTileIndex, mTileWriter, tileSource); return drawable != null; } catch (CantContinueException e) { return false; } }
Example #10
Source File: Bug512CacheManagerWp.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.sample_cachemgr, container,false); btnCache = root.findViewById(R.id.btnCache); btnCache.setOnClickListener(this); btnCache.setText("Run job (watch logcat output)"); // Workaround for failing unit test due to issues with https connections on API < 9 // https://github.com/osmdroid/osmdroid/issues/1048 // https://github.com/osmdroid/osmdroid/issues/1051 // Also works around an issue with some emulator image that do not update their time/date // correctly and stay on 0 unix time. This causes SSLExceptions due to the validity of the // certificates. OnlineTileSourceBase onlineTileSourceBase = new XYTileSource("Mapnik", 0, 19, 256, ".png", new String[]{ "http://a.tile.openstreetmap.org/", "http://b.tile.openstreetmap.org/", "http://c.tile.openstreetmap.org/"}, "© OpenStreetMap contributors"); mMapView = new MapView(getActivity(), new MapTileProviderBasic( getActivity().getApplicationContext(), onlineTileSourceBase)); ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView); return root; }
Example #11
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public int getMinimumZoomLevel() { OnlineTileSourceBase tileSource = mTileSource.get(); return (tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL); }
Example #12
Source File: MapTileDownloader.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public int getMaximumZoomLevel() { OnlineTileSourceBase tileSource = mTileSource.get(); return (tileSource != null ? tileSource.getMaximumZoomLevel() : org.osmdroid.util.TileSystem.getMaximumZoomLevel()); }
Example #13
Source File: TileDownloader.java From osmdroid with Apache License 2.0 | 4 votes |
public Drawable downloadTile(final long pMapTileIndex, final IFilesystemCache pFilesystemCache, final OnlineTileSourceBase pTileSource) throws CantContinueException { return downloadTile(pMapTileIndex, 0, pTileSource.getTileURLString(pMapTileIndex), pFilesystemCache, pTileSource); }