org.osmdroid.tileprovider.modules.MapTileModuleProviderBase Java Examples
The following examples show how to use
org.osmdroid.tileprovider.modules.MapTileModuleProviderBase.
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: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public void detach() { synchronized (mTileProviderList) { for (final MapTileModuleProviderBase tileProvider : mTileProviderList) { tileProvider.detach(); } } synchronized (mWorking) { mWorking.clear(); } if (mRegisterReceiver!=null) { mRegisterReceiver.destroy(); mRegisterReceiver = null; } super.detach(); }
Example #2
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 6 votes |
/** * We want to not use a provider that doesn't exist anymore in the chain, and we want to not use * a provider that requires a data connection when one is not available. */ protected MapTileModuleProviderBase findNextAppropriateProvider(final MapTileRequestState aState) { MapTileModuleProviderBase provider; boolean providerDoesntExist = false, providerCantGetDataConnection = false, providerCantServiceZoomlevel = false; // The logic of the while statement is // "Keep looping until you get null, or a provider that still exists // and has a data connection if it needs one and can service the zoom level," do { provider = aState.getNextProvider(); // Perform some checks to see if we can use this provider // If any of these are true, then that disqualifies the provider for this tile request. if (provider != null) { providerDoesntExist = !this.getProviderExists(provider); providerCantGetDataConnection = !useDataConnection() && provider.getUsesDataConnection(); int zoomLevel = MapTileIndex.getZoom(aState.getMapTile()); providerCantServiceZoomlevel = zoomLevel > provider.getMaximumZoomLevel() || zoomLevel < provider.getMinimumZoomLevel(); } } while ((provider != null) && (providerDoesntExist || providerCantGetDataConnection || providerCantServiceZoomlevel)); return provider; }
Example #3
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 6 votes |
/** * @since 6.0.2 */ private void runAsyncNextProvider(final MapTileRequestState pState) { final MapTileModuleProviderBase nextProvider = findNextAppropriateProvider(pState); if (nextProvider != null) { nextProvider.loadMapTileAsync(pState); return; } final Integer status; // as Integer (and not int) for concurrency reasons synchronized (mWorking) { status = mWorking.get(pState.getMapTile()); } if (status != null && status == WORKING_STATUS_STARTED) { super.mapTileRequestFailed(pState); } remove(pState.getMapTile()); }
Example #4
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 #5
Source File: MapTileProviderBasic.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @since 6.1.0 * @return true if possible and done */ public boolean setOfflineFirst(final boolean pOfflineFirst) { int downloaderIndex = -1; int approximationIndex = -1; int i = 0; for(final MapTileModuleProviderBase provider : mTileProviderList) { if (downloaderIndex == -1 && provider == mDownloaderProvider) { downloaderIndex = i; } if (approximationIndex == -1 && provider == mApproximationProvider) { approximationIndex = i; } i++; } if (downloaderIndex == -1 || approximationIndex == -1) { return false; } if (approximationIndex < downloaderIndex && pOfflineFirst) { return true; } if (approximationIndex > downloaderIndex && !pOfflineFirst) { return true; } mTileProviderList.set(downloaderIndex, mApproximationProvider); mTileProviderList.set(approximationIndex, mDownloaderProvider); return true; }
Example #6
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 #7
Source File: SampleAssetsOnly.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays() { this.mMapView.setUseDataConnection(false); MapTileAssetsProvider prov = new MapTileAssetsProvider(new SimpleRegisterReceiver(getContext() ), getActivity().getAssets()); this.mMapView.setTileProvider(new MapTileProviderArray(TileSourceFactory.MAPNIK, new SimpleRegisterReceiver(getContext()), new MapTileModuleProviderBase[]{ prov })); }
Example #8
Source File: MapTileRequestState.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @since 6.0 */ public MapTileRequestState(final long pMapTileIndex, final List<MapTileModuleProviderBase> providers, final IMapTileProviderCallback callback) { mProviderQueue = providers; mMapTileIndex = pMapTileIndex; mCallback = callback; }
Example #9
Source File: MapTileRequestState.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @deprecated use {@link MapTileRequestState#MapTileRequestState(long, List, IMapTileProviderCallback)} instead */ @Deprecated public MapTileRequestState(final long pMapTleIndex, final MapTileModuleProviderBase[] providers, final IMapTileProviderCallback callback) { mProviderQueue = new ArrayList<>(); Collections.addAll(mProviderQueue, providers); mMapTileIndex = pMapTleIndex; mCallback = callback; }
Example #10
Source File: MapTileProviderBasic.java From osmdroid with Apache License 2.0 | 5 votes |
/** * @since 6.0.3 */ @Override protected boolean isDowngradedMode(final long pMapTileIndex) { if ((mNetworkAvailabilityCheck != null && !mNetworkAvailabilityCheck.getNetworkAvailable()) || !useDataConnection()) { return true; } int zoomMin = -1; int zoomMax = -1; for(final MapTileModuleProviderBase provider : mTileProviderList) { if (provider.getUsesDataConnection()) { int tmp; tmp = provider.getMinimumZoomLevel(); if (zoomMin == -1 || zoomMin > tmp) { zoomMin = tmp; } tmp = provider.getMaximumZoomLevel(); if (zoomMax == -1 || zoomMax < tmp) { zoomMax = tmp; } } } if (zoomMin == -1 || zoomMax == -1) { return true; } final int zoom = MapTileIndex.getZoom(pMapTileIndex); return zoom < zoomMin || zoom > zoomMax; }
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: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 5 votes |
@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 #13
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public int getMinimumZoomLevel() { int result = org.osmdroid.util.TileSystem.getMaximumZoomLevel(); synchronized (mTileProviderList) { for (final MapTileModuleProviderBase tileProvider : mTileProviderList) { if (tileProvider.getMinimumZoomLevel() < result) { result = tileProvider.getMinimumZoomLevel(); } } } return result; }
Example #14
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 #15
Source File: MapTilePreCache.java From osmdroid with Apache License 2.0 | 4 votes |
public void addProvider(final MapTileModuleProviderBase pProvider) { mProviders.add(pProvider); }
Example #16
Source File: MapTileRequestState.java From osmdroid with Apache License 2.0 | 4 votes |
public MapTileModuleProviderBase getNextProvider() { mCurrentProvider = isEmpty() ? null : mProviderQueue.get(index ++); return mCurrentProvider; }
Example #17
Source File: MapTileRequestState.java From osmdroid with Apache License 2.0 | 4 votes |
public MapTileModuleProviderBase getCurrentProvider() { return mCurrentProvider; }
Example #18
Source File: OpenStreetMapTileProviderDirectTest.java From osmdroid with Apache License 2.0 | 4 votes |
public void test_getMapTile_found() throws RemoteException, BitmapTileSourceBase.LowMemoryException, java.io.IOException { final long tile = MapTileIndex.getTileIndex(2, 3, 3); if (Build.VERSION.SDK_INT >=23) return; // create a bitmap, draw something on it, write it to a file and put it in the cache String path = getContext().getFilesDir().getAbsolutePath() + File.separator + "osmdroid" + File.separator; File temp= new File(path); if (!temp.exists()) temp.mkdirs(); Configuration.getInstance().setOsmdroidTileCache(temp);; path = path + "OpenStreetMapTileProviderTest.png"; File f = new File(path); if (f.exists()) f.delete(); final Bitmap bitmap1 = Bitmap.createBitmap( TileSourceFactory.MAPNIK.getTileSizePixels(), TileSourceFactory.MAPNIK.getTileSizePixels(), Config.ARGB_8888); bitmap1.eraseColor(Color.YELLOW); final Canvas canvas = new Canvas(bitmap1); canvas.drawText("test", 10, 20, new Paint()); try { f.createNewFile(); final FileOutputStream fos = new FileOutputStream(path); bitmap1.compress(CompressFormat.PNG, 100, fos); fos.close(); }catch (Exception ex){ ex.printStackTrace(); Assert.fail("unable to write temp tile " + ex); } final MapTileRequestState state = new MapTileRequestState(tile, new ArrayList<MapTileModuleProviderBase>(), mProvider); mProvider.mapTileRequestCompleted(state, TileSourceFactory.MAPNIK.getDrawable(path)); // do the test final Drawable drawable = mProvider.getMapTile(tile); if (f.exists()) f.delete(); assertNotNull("Expect tile to be not null from path " + path, drawable); assertTrue("Expect instance of BitmapDrawable", drawable instanceof BitmapDrawable); final Bitmap bitmap2 = ((BitmapDrawable) drawable).getBitmap(); assertNotNull("Expect tile to be not null", bitmap2); // compare a few things to see if it's the same bitmap // commented out due to a number of intermitent failures on API8 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { assertEquals("Compare config", bitmap1.getConfig(), bitmap2.getConfig()); } assertEquals("Compare width", bitmap1.getWidth(), bitmap2.getWidth()); assertEquals("Compare height", bitmap1.getHeight(), bitmap2.getHeight()); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { // compare the total thing final ByteBuffer bb1 = ByteBuffer.allocate(bitmap1.getWidth() * bitmap1.getHeight() * 4); bitmap1.copyPixelsToBuffer(bb1); final ByteBuffer bb2 = ByteBuffer.allocate(bitmap2.getWidth() * bitmap2.getHeight() * 4); bitmap2.copyPixelsToBuffer(bb2); assertEquals("Compare pixels", bb1, bb2); } }
Example #19
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 4 votes |
public boolean getProviderExists(final MapTileModuleProviderBase provider) { return mTileProviderList.contains(provider); }
Example #20
Source File: MapTileProviderArray.java From osmdroid with Apache License 2.0 | 2 votes |
/** * Creates an {@link MapTileProviderArray} with no tile providers. * * @param pRegisterReceiver * a {@link IRegisterReceiver} */ protected MapTileProviderArray(final ITileSource pTileSource, final IRegisterReceiver pRegisterReceiver) { this(pTileSource, pRegisterReceiver, new MapTileModuleProviderBase[0]); }