diff --git a/vtm-android-example/src/org/oscim/android/test/BitmapTileMapActivity.java b/vtm-android-example/src/org/oscim/android/test/BitmapTileMapActivity.java index 927f30a6..f59c2557 100644 --- a/vtm-android-example/src/org/oscim/android/test/BitmapTileMapActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/BitmapTileMapActivity.java @@ -16,8 +16,8 @@ package org.oscim.android.test; import org.oscim.android.MapActivity; import org.oscim.android.MapView; -import org.oscim.layers.tile.bitmap.BitmapTileLayer; -import org.oscim.layers.tile.bitmap.StamenTonerTiles; +import org.oscim.layers.tile.BitmapTileLayer; +import org.oscim.tiling.source.bitmap.DefaultSources.OpenStreetMap; import android.os.Bundle; @@ -30,8 +30,13 @@ public class BitmapTileMapActivity extends MapActivity { setContentView(R.layout.activity_map); mMapView = (MapView) findViewById(R.id.mapView); - //registerMapView(mMapView); + registerMapView(mMapView); - mMap.getLayers().add(new BitmapTileLayer(mMap, StamenTonerTiles.INSTANCE, 20)); + mMap.getLayers().add(new BitmapTileLayer(mMap, new OpenStreetMap(), 20)); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new ImagicoLandcover(), 20)); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new ArcGISWorldShaded(), 20)); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new HillShadeHD(), 20)); + + mMap.setMapPosition(0, 0, 1 << 2); } } diff --git a/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java b/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java index 86b62368..3b023845 100644 --- a/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java @@ -24,8 +24,6 @@ import org.oscim.android.MapView; import org.oscim.backend.canvas.Color; import org.oscim.core.GeoPoint; import org.oscim.layers.PathLayer; -import org.oscim.layers.tile.bitmap.BitmapTileLayer; -import org.oscim.layers.tile.bitmap.StamenTonerTiles; import android.os.Bundle; @@ -41,8 +39,6 @@ public class PathOverlayActivity extends MapActivity { mMapView = (MapView) findViewById(R.id.mapView); registerMapView(mMapView); - mMap.getLayers().add(new BitmapTileLayer(mMap, StamenTonerTiles.INSTANCE, 20)); - for (double lon = -180; lon < 180; lon += 5) { List pts = new ArrayList(); diff --git a/vtm-gdx-desktop/src/org/oscim/gdx/GdxMapApp.java b/vtm-gdx-desktop/src/org/oscim/gdx/GdxMapApp.java index 8651604b..4f4442ba 100644 --- a/vtm-gdx-desktop/src/org/oscim/gdx/GdxMapApp.java +++ b/vtm-gdx-desktop/src/org/oscim/gdx/GdxMapApp.java @@ -21,7 +21,6 @@ import java.nio.Buffer; import org.oscim.awt.AwtGraphics; import org.oscim.backend.CanvasAdapter; import org.oscim.backend.GLAdapter; -import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.tiling.source.TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; @@ -33,6 +32,9 @@ import com.badlogic.gdx.backends.lwjgl.LwjglGL20; import com.badlogic.gdx.utils.SharedLibraryLoader; public class GdxMapApp extends GdxMap { + static { + System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); + } // wrap LwjglGL20 to add GL20 interface static class GdxGL extends LwjglGL20 implements org.oscim.backend.GL20 { @@ -78,16 +80,16 @@ public class GdxMapApp extends GdxMap { @Override public void createLayers() { TileSource tileSource = new OSciMap4TileSource(); - tileSource.setOption("url", "http://opensciencemap.org/tiles/vtm"); // TileSource tileSource = new MapFileTileSource(); // tileSource.setOption("file", "/home/jeff/germany.map"); initDefaultLayers(tileSource, false, true, true); - MapPosition p = new MapPosition(); - p.setZoomLevel(14); - p.setPosition(53.08, 8.83); - mMap.setMapPosition(p); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new ImagicoLandcover(), 20)); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new OSMTileSource(), 20)); + //mMap.getLayers().add(new BitmapTileLayer(mMap, new ArcGISWorldShaded(), 20)); + + mMap.setMapPosition(0, 0, 1 << 2); } } diff --git a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java index 3d9d6e06..a4eb8464 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java +++ b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java @@ -22,10 +22,10 @@ import org.oscim.backend.GLAdapter; import org.oscim.core.MapPosition; import org.oscim.core.MercatorProjection; import org.oscim.gdx.GdxMap; -import org.oscim.layers.tile.bitmap.BitmapTileLayer; -import org.oscim.layers.tile.bitmap.NaturalEarth; +import org.oscim.layers.tile.BitmapTileLayer; import org.oscim.renderer.MapRenderer; import org.oscim.tiling.source.TileSource; +import org.oscim.tiling.source.bitmap.DefaultSources.NaturalEarth; import org.oscim.tiling.source.oscimap2.OSciMap2TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.slf4j.Logger; @@ -116,7 +116,7 @@ class GwtGdxMap extends GdxMap { initDefaultLayers(tileSource, false, true, true); if ("naturalearth".equals(c.getBackgroundLayer())) - mMap.setBackgroundMap(new BitmapTileLayer(mMap, NaturalEarth.INSTANCE)); + mMap.setBackgroundMap(new BitmapTileLayer(mMap, new NaturalEarth())); mSearchBox = new SearchBox(mMap); diff --git a/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java b/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java deleted file mode 100644 index 28fd800d..00000000 --- a/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2013 Hannes Janetzek - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.URL; - -import org.oscim.backend.canvas.Bitmap; -import org.oscim.core.MapPosition; -import org.oscim.core.Tile; -import org.oscim.gdx.client.GwtBitmap; -import org.oscim.layers.tile.TileLayer; -import org.oscim.layers.tile.bitmap.TileSource.FadeStep; -import org.oscim.map.Map; -import org.oscim.renderer.elements.BitmapLayer; -import org.oscim.renderer.elements.ElementLayers; -import org.oscim.tiling.MapTile; -import org.oscim.tiling.TileLoader; -import org.oscim.tiling.TileManager; -import org.oscim.utils.FastMath; - -import com.google.gwt.event.dom.client.ErrorEvent; -import com.google.gwt.event.dom.client.ErrorHandler; -import com.google.gwt.event.dom.client.LoadEvent; -import com.google.gwt.event.dom.client.LoadHandler; -import com.google.gwt.user.client.ui.Image; -import com.google.gwt.user.client.ui.RootPanel; - -public class BitmapTileLayer extends TileLayer { - - private final static int CACHE_LIMIT = 50; - - final TileSource mTileSource; - private final FadeStep[] mFade; - - public BitmapTileLayer(Map map, TileSource tileSource) { - this(map, tileSource, CACHE_LIMIT); - } - - public BitmapTileLayer(Map map, TileSource tileSource, int cacheLimit) { - super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), cacheLimit); - mTileSource = tileSource; - mFade = mTileSource.getFadeSteps(); - } - - @Override - public void onMapUpdate(MapPosition pos, boolean changed, boolean clear) { - super.onMapUpdate(pos, changed, clear); - - if (mFade == null) { - mRenderLayer.setBitmapAlpha(1); - return; - } - - float alpha = 0; - for (FadeStep f : mFade) { - if (pos.scale < f.scaleStart || pos.scale > f.scaleEnd) - continue; - - if (f.alphaStart == f.alphaEnd) { - alpha = f.alphaStart; - break; - } - double range = f.scaleEnd / f.scaleStart; - float a = (float) ((range - (pos.scale / f.scaleStart)) / range); - a = FastMath.clamp(a, 0, 1); - // interpolate alpha between start and end - alpha = a * f.alphaStart + (1 - a) * f.alphaEnd; - break; - } - - mRenderLayer.setBitmapAlpha(alpha); - } - - @Override - protected TileLoader createLoader(TileManager tm) { - return new TileLoader(tm) { - - private void loadImage(final MapTile tile, final String url) { - final Image img = new Image(url); - RootPanel.get().add(img); - img.setVisible(false); - - img.addLoadHandler(new LoadHandler() { - public void onLoad(LoadEvent event) { - - Bitmap bitmap = new GwtBitmap(img); - tile.layers = new ElementLayers(); - BitmapLayer l = new BitmapLayer(false); - l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE); - - tile.layers.textureLayers = l; - tile.loader.jobCompleted(tile, true); - } - }); - - img.addErrorHandler(new ErrorHandler() { - - @Override - public void onError(ErrorEvent event) { - tile.loader.jobCompleted(tile, false); - } - }); - } - - @Override - protected boolean executeJob(MapTile tile) { - URL url; - try { - url = mTileSource.getTileUrl(tile); - loadImage(tile, url.toString()); - } catch (Exception e) { - e.printStackTrace(); - tile.loader.jobCompleted(tile, false); - return false; - } - - return false; - } - - @Override - public void cleanup() { - } - }; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java b/vtm/src/org/oscim/layers/tile/BitmapTileLayer.java similarity index 54% rename from vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java rename to vtm/src/org/oscim/layers/tile/BitmapTileLayer.java index ee4c5818..e2cc974e 100644 --- a/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java +++ b/vtm/src/org/oscim/layers/tile/BitmapTileLayer.java @@ -14,26 +14,23 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.layers.tile.bitmap; +package org.oscim.layers.tile; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.zip.GZIPInputStream; - -import org.oscim.backend.CanvasAdapter; import org.oscim.backend.canvas.Bitmap; +import org.oscim.core.MapElement; import org.oscim.core.MapPosition; import org.oscim.core.Tile; -import org.oscim.layers.tile.TileLayer; -import org.oscim.layers.tile.bitmap.TileSource.FadeStep; import org.oscim.map.Map; import org.oscim.renderer.elements.BitmapLayer; import org.oscim.renderer.elements.ElementLayers; import org.oscim.tiling.MapTile; import org.oscim.tiling.TileLoader; import org.oscim.tiling.TileManager; +import org.oscim.tiling.source.ITileDataSink; +import org.oscim.tiling.source.ITileDataSource; +import org.oscim.tiling.source.ITileDataSource.QueryResult; +import org.oscim.tiling.source.TileSource; +import org.oscim.tiling.source.bitmap.BitmapTileSource; import org.oscim.utils.FastMath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,20 +41,27 @@ public class BitmapTileLayer extends TileLayer { private final static int CACHE_LIMIT = 50; - private static final int TIMEOUT_CONNECT = 5000; - private static final int TIMEOUT_READ = 10000; + private final BitmapTileSource mTileSource; - final TileSource mTileSource; - private final FadeStep[] mFade; + public static class FadeStep { + public final double scaleStart, scaleEnd; + public final float alphaStart, alphaEnd; - public BitmapTileLayer(Map map, TileSource tileSource) { + public FadeStep(int zoomStart, int zoomEnd, float alphaStart, float alphaEnd) { + this.scaleStart = 1 << zoomStart; + this.scaleEnd = 1 << zoomEnd; + this.alphaStart = alphaStart; + this.alphaEnd = alphaEnd; + } + } + + public BitmapTileLayer(Map map, BitmapTileSource tileSource) { this(map, tileSource, CACHE_LIMIT); } - public BitmapTileLayer(Map map, TileSource tileSource, int cacheLimit) { + public BitmapTileLayer(Map map, BitmapTileSource tileSource, int cacheLimit) { super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), cacheLimit); mTileSource = tileSource; - mFade = mTileSource.getFadeSteps(); initLoader(); } @@ -65,13 +69,15 @@ public class BitmapTileLayer extends TileLayer { public void onMapUpdate(MapPosition pos, boolean changed, boolean clear) { super.onMapUpdate(pos, changed, clear); - if (mFade == null) { + FadeStep[] fade = mTileSource.getFadeSteps(); + + if (fade == null) { mRenderLayer.setBitmapAlpha(1); return; } float alpha = 0; - for (FadeStep f : mFade) { + for (FadeStep f : fade) { if (pos.scale < f.scaleStart || pos.scale > f.scaleEnd) continue; @@ -92,47 +98,54 @@ public class BitmapTileLayer extends TileLayer { @Override protected TileLoader createLoader(TileManager tm) { - return new TileLoader(tm) { - - @Override - protected boolean executeJob(MapTile tile) { - URL url; - try { - url = mTileSource.getTileUrl(tile); - URLConnection urlConnection = getURLConnection(url); - InputStream inputStream = getInputStream(urlConnection); - Bitmap bitmap = CanvasAdapter.g.decodeBitmap(inputStream); - - tile.layers = new ElementLayers(); - BitmapLayer l = new BitmapLayer(false); - l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE); - - tile.layers.textureLayers = l; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - return true; - } - - @Override - public void cleanup() { - } - - private InputStream getInputStream(URLConnection urlConnection) throws IOException { - if ("gzip".equals(urlConnection.getContentEncoding())) { - return new GZIPInputStream(urlConnection.getInputStream()); - } - return urlConnection.getInputStream(); - } - - private URLConnection getURLConnection(URL url) throws IOException { - URLConnection urlConnection = url.openConnection(); - urlConnection.setConnectTimeout(TIMEOUT_CONNECT); - urlConnection.setReadTimeout(TIMEOUT_READ); - return urlConnection; - } - }; + return new BitmapTileLoader(tm, mTileSource); } + + class BitmapTileLoader extends TileLoader implements ITileDataSink { + + private final ITileDataSource mTileDataSource; + private MapTile mTile; + + public BitmapTileLoader(TileManager tileManager, TileSource tileSource) { + super(tileManager); + mTileDataSource = tileSource.getDataSource(); + } + + @Override + public void cleanup() { + + } + + @Override + protected boolean executeJob(MapTile tile) { + QueryResult result; + + try { + mTile = tile; + result = mTileDataSource.executeQuery(tile, this); + } finally { + mTile = null; + } + return result == QueryResult.SUCCESS; + } + + @Override + public void setTileImage(Bitmap bitmap) { + BitmapLayer l = new BitmapLayer(false); + l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE); + mTile.layers = new ElementLayers(); + mTile.layers.textureLayers = l; + } + + @Override + public void process(MapElement element) { + + } + + @Override + public void completed(boolean success) { + + } + } + } diff --git a/vtm/src/org/oscim/layers/tile/bitmap/AbstractTileSource.java b/vtm/src/org/oscim/layers/tile/bitmap/AbstractTileSource.java deleted file mode 100644 index 24abc2a1..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/AbstractTileSource.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -public abstract class AbstractTileSource implements TileSource { - protected final String hostName; - protected final int port; - - protected AbstractTileSource(String hostName, int port) { - if (hostName == null || hostName.isEmpty()) { - throw new IllegalArgumentException("no host name specified"); - } else if (port < 0 || port > 65535) { - throw new IllegalArgumentException("invalid port number: " + port); - } - - this.hostName = hostName; - this.port = port; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (!(obj instanceof AbstractTileSource)) { - return false; - } - AbstractTileSource other = (AbstractTileSource) obj; - if (!this.hostName.equals(other.hostName)) { - return false; - } else if (this.port != other.port) { - return false; - } - return true; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this.hostName.hashCode(); - result = prime * result + this.port; - return result; - } - - @Override - public FadeStep[] getFadeSteps() { - return null; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/ArcGISWorldShaded.java b/vtm/src/org/oscim/layers/tile/bitmap/ArcGISWorldShaded.java deleted file mode 100644 index 01c562dd..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/ArcGISWorldShaded.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; -//http://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/5/14/14 -//http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer - -public class ArcGISWorldShaded extends AbstractTileSource { - public static final ArcGISWorldShaded INSTANCE = new ArcGISWorldShaded("server.arcgisonline.com", - 80); - private static final int PARALLEL_REQUESTS_LIMIT = 4; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 6; - private static final int ZOOM_LEVEL_MIN = 0; - - public ArcGISWorldShaded(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - //stringBuilder.append("/ArcGIS/rest/services/World_Imagery/MapServer/tile/"); - stringBuilder.append("/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/HillShadeTiles.java b/vtm/src/org/oscim/layers/tile/bitmap/HillShadeTiles.java deleted file mode 100644 index 33a495f5..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/HillShadeTiles.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class HillShadeTiles extends AbstractTileSource { - - //public static final HillShadeTiles INSTANCE = new HillShadeTiles("toolserver.org", 80); - - // from http://openmapsurfer.uni-hd.de/ - public static final HillShadeTiles INSTANCE = new HillShadeTiles("129.206.74.245", 8004); - - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 18; - private static final int ZOOM_LEVEL_MIN = 2; - - public HillShadeTiles(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - //tms_hs.ashx?x=131&y=94&z=8 - - stringBuilder.append("/tms_hs.ashx?x="); - stringBuilder.append(tile.tileX); - stringBuilder.append("&y="); - stringBuilder.append(tile.tileY); - stringBuilder.append("&z="); - stringBuilder.append(tile.zoomLevel); - - //stringBuilder.append("/~cmarqu/hill/"); - //stringBuilder.append(tile.zoomLevel); - //stringBuilder.append('/'); - //stringBuilder.append(tile.tileX); - //stringBuilder.append('/'); - //stringBuilder.append(tile.tileY); - //stringBuilder.append(".png"); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/MapQuestAerial.java b/vtm/src/org/oscim/layers/tile/bitmap/MapQuestAerial.java deleted file mode 100644 index 8f440fa2..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/MapQuestAerial.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class MapQuestAerial extends AbstractTileSource { - public static final MapQuestAerial INSTANCE = new MapQuestAerial("otile1.mqcdn.com", 80); - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 8; - private static final int ZOOM_LEVEL_MIN = 0; - - public MapQuestAerial(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - stringBuilder.append("/tiles/1.0.0/sat/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".jpg"); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/NaturalEarth.java b/vtm/src/org/oscim/layers/tile/bitmap/NaturalEarth.java deleted file mode 100644 index 7125afa8..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/NaturalEarth.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class NaturalEarth extends AbstractTileSource { - public static final NaturalEarth INSTANCE = new NaturalEarth("city.informatik.uni-bremen.de", - 80); - private static final int PARALLEL_REQUESTS_LIMIT = 4; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 8; - private static final int ZOOM_LEVEL_MIN = 0; - - public NaturalEarth(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - stringBuilder.append("/tiles/ne/"); - //stringBuilder.append("/osci/ne_image2/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".png"); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } - - @Override - public FadeStep[] getFadeSteps() { - return new FadeStep[] { - new FadeStep(ZOOM_LEVEL_MIN, ZOOM_LEVEL_MAX - 1, 1, 0.7f), - // dont fade between zoom-min/max - // fade above zoom max + 2, interpolate 1 to 0 - new FadeStep(ZOOM_LEVEL_MAX - 1, ZOOM_LEVEL_MAX + 1, 0.7f, 0) - }; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMap.java b/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMap.java deleted file mode 100644 index 6874b4c5..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMap.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class OpenStreetMap extends AbstractTileSource { - public static final OpenStreetMap INSTANCE = new OpenStreetMap(".tile.openstreetmap.org", - 80); - - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 18; - private static final int ZOOM_LEVEL_MIN = 0; - - public OpenStreetMap(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - private char[] subdomains = { 'a', 'b', 'c', 'd' }; - private int curDomain = 0; - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - //stringBuilder.append("/osm/osm/"); - stringBuilder.append("/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".png"); - - String host; - synchronized (this) { - curDomain = (curDomain++) % 4; - host = subdomains[curDomain] + hostName; - } - - return new URL(PROTOCOL, host, port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapMapnik.java b/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapMapnik.java deleted file mode 100644 index 326dbde3..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapMapnik.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class OpenStreetMapMapnik extends AbstractTileSource { - public static final OpenStreetMapMapnik INSTANCE = new OpenStreetMapMapnik("tile.openstreetmap.org", 80); - - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 18; - private static final int ZOOM_LEVEL_MIN = 0; - - public OpenStreetMapMapnik(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - //stringBuilder.append("/osm/osm/"); - stringBuilder.append("/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".png"); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapTransport.java b/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapTransport.java deleted file mode 100644 index ef9c0c32..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/OpenStreetMapTransport.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class OpenStreetMapTransport extends AbstractTileSource { - //http://tile.thunderforest.com/transport/3/3/3.png - - public static final OpenStreetMapTransport INSTANCE = - new OpenStreetMapTransport(".tile.thunderforest.com", 80); - - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 18; - private static final int ZOOM_LEVEL_MIN = 0; - - public OpenStreetMapTransport(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - private char[] subdomains = { 'a', 'b', 'c', 'd' }; - private int curDomain = 0; - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - //stringBuilder.append("/transport/"); - stringBuilder.append("/outdoors/"); - //stringBuilder.append("/landscape/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".png"); - - String host; - synchronized (this) { - curDomain = (curDomain++) % 4; - host = subdomains[curDomain] + hostName; - } - - return new URL(PROTOCOL, host, port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/StamenTonerTiles.java b/vtm/src/org/oscim/layers/tile/bitmap/StamenTonerTiles.java deleted file mode 100644 index a53b01ec..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/StamenTonerTiles.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class StamenTonerTiles extends AbstractTileSource { - public static final StamenTonerTiles INSTANCE = new StamenTonerTiles(".tile.stamen.com", 80); - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 16; - private static final int ZOOM_LEVEL_MIN = 0; - - public StamenTonerTiles(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - private char[] subdomains = { 'a', 'b', 'c', 'd' }; - private int curDomain = 0; - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - stringBuilder.append("/toner/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".png"); - - curDomain = (curDomain++) % 4; - - return new URL(PROTOCOL, subdomains[curDomain] + hostName, port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/StamenWaterTiles.java b/vtm/src/org/oscim/layers/tile/bitmap/StamenWaterTiles.java deleted file mode 100644 index 1c50c935..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/StamenWaterTiles.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public class StamenWaterTiles extends AbstractTileSource { - public static final StamenWaterTiles INSTANCE = new StamenWaterTiles("tile.stamen.com", 80); - private static final int PARALLEL_REQUESTS_LIMIT = 8; - private static final String PROTOCOL = "http"; - private static final int ZOOM_LEVEL_MAX = 16; - private static final int ZOOM_LEVEL_MIN = 0; - - public StamenWaterTiles(String hostName, int port) { - super(hostName, port); - } - - @Override - public int getParallelRequestsLimit() { - return PARALLEL_REQUESTS_LIMIT; - } - - @Override - public URL getTileUrl(Tile tile) throws MalformedURLException { - StringBuilder stringBuilder = new StringBuilder(32); - - stringBuilder.append("/watercolor/"); - stringBuilder.append(tile.zoomLevel); - stringBuilder.append('/'); - stringBuilder.append(tile.tileX); - stringBuilder.append('/'); - stringBuilder.append(tile.tileY); - stringBuilder.append(".jpg"); - - return new URL(PROTOCOL, this.hostName, this.port, stringBuilder.toString()); - } - - @Override - public byte getZoomLevelMax() { - return ZOOM_LEVEL_MAX; - } - - @Override - public byte getZoomLevelMin() { - return ZOOM_LEVEL_MIN; - } -} diff --git a/vtm/src/org/oscim/layers/tile/bitmap/TileSource.java b/vtm/src/org/oscim/layers/tile/bitmap/TileSource.java deleted file mode 100644 index b229ac07..00000000 --- a/vtm/src/org/oscim/layers/tile/bitmap/TileSource.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2010, 2011, 2012 mapsforge.org - * Copyright 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ -package org.oscim.layers.tile.bitmap; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.oscim.core.Tile; - -public interface TileSource { - /** - * @return the maximum number of parallel requests which this - * {@code TileSource} supports. - */ - int getParallelRequestsLimit(); - - /** - * @return the download URL for the given {@code Tile}. - */ - URL getTileUrl(Tile tile) throws MalformedURLException; - - /** - * @return the maximum zoom level which this {@code TileSource} supports. - */ - byte getZoomLevelMax(); - - /** - * @return the minimum zoom level which this {@code TileSource} supports. - */ - byte getZoomLevelMin(); - - FadeStep[] getFadeSteps(); - - public class FadeStep { - public final double scaleStart, scaleEnd; - public final float alphaStart, alphaEnd; - - public FadeStep(int zoomStart, int zoomEnd, float alphaStart, float alphaEnd) { - this.scaleStart = 1 << zoomStart; - this.scaleEnd = 1 << zoomEnd; - this.alphaStart = alphaStart; - this.alphaEnd = alphaEnd; - } - } -} diff --git a/vtm/src/org/oscim/map/Map.java b/vtm/src/org/oscim/map/Map.java index ace3b6e8..9ee8f2b1 100644 --- a/vtm/src/org/oscim/map/Map.java +++ b/vtm/src/org/oscim/map/Map.java @@ -24,7 +24,7 @@ import org.oscim.event.Gesture; import org.oscim.event.GestureDetector; import org.oscim.event.MotionEvent; import org.oscim.layers.MapEventLayer; -import org.oscim.layers.tile.bitmap.BitmapTileLayer; +import org.oscim.layers.tile.BitmapTileLayer; import org.oscim.layers.tile.vector.VectorTileLayer; import org.oscim.renderer.MapRenderer; import org.oscim.theme.IRenderTheme; @@ -79,7 +79,7 @@ public abstract class Map { private Set mUpdateListenerSet = new LinkedHashSet(); private UpdateListener[] mUpdateListeners; - protected boolean mClearMap; + protected boolean mClearMap = true; public Map() { mViewport = new Viewport(this); diff --git a/vtm/src/org/oscim/tiling/source/bitmap/BitmapTileSource.java b/vtm/src/org/oscim/tiling/source/bitmap/BitmapTileSource.java new file mode 100644 index 00000000..d94e7b07 --- /dev/null +++ b/vtm/src/org/oscim/tiling/source/bitmap/BitmapTileSource.java @@ -0,0 +1,94 @@ +package org.oscim.tiling.source.bitmap; + +import java.io.IOException; +import java.io.InputStream; + +import org.oscim.backend.CanvasAdapter; +import org.oscim.backend.canvas.Bitmap; +import org.oscim.core.Tile; +import org.oscim.layers.tile.BitmapTileLayer.FadeStep; +import org.oscim.tiling.source.ITileDataSink; +import org.oscim.tiling.source.ITileDataSource; +import org.oscim.tiling.source.ITileDecoder; +import org.oscim.tiling.source.common.LwHttp; +import org.oscim.tiling.source.common.UrlTileDataSource; +import org.oscim.tiling.source.common.UrlTileSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class BitmapTileSource extends UrlTileSource { + static final Logger log = LoggerFactory.getLogger(LwHttp.class); + + private final int mZoomMin; + private final int mZoomMax; + private final String mFileExtension; + private final String mMimeType; + + public BitmapTileSource(String url) { + this(url, 0, 17); + } + + public BitmapTileSource(String url, int zoomMin, int zoomMax) { + this(url, zoomMin, zoomMax, "image/png", ".png"); + } + + public BitmapTileSource(String url, int zoomMin, int zoomMax, String mimeType, + String fileExtension) { + super(url); + mZoomMin = zoomMin; + mZoomMax = zoomMax; + mFileExtension = fileExtension; + mMimeType = mimeType; + } + + @Override + public ITileDataSource getDataSource() { + LwHttp conn = new LwHttp(mUrl, mMimeType, mFileExtension, false) { + @Override + protected int formatTilePath(Tile tile, byte[] path, int curPos) { + String p = getTileUrl(tile); + if (p == null) + return super.formatTilePath(tile, path, curPos); + + byte[] b = p.getBytes(); + System.arraycopy(b, 0, path, curPos, b.length); + + return curPos + b.length; + } + }; + return new UrlTileDataSource(this, new BitmapTileDecoder(), conn); + } + + public int getZoomLevelMax() { + return mZoomMax; + } + + public int getZoomLevelMin() { + return mZoomMin; + } + + public FadeStep[] getFadeSteps() { + return null; + } + + public String getTileUrl(Tile tile) { + return null; + } + + public class BitmapTileDecoder implements ITileDecoder { + + @Override + public boolean decode(Tile tile, ITileDataSink sink, InputStream is) + throws IOException { + + Bitmap bitmap = CanvasAdapter.g.decodeBitmap(is); + if (!bitmap.isValid()) { + log.debug("invalid bitmap"); + return false; + } + sink.setTileImage(bitmap); + + return true; + } + } +} diff --git a/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java b/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java new file mode 100644 index 00000000..39a49858 --- /dev/null +++ b/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java @@ -0,0 +1,102 @@ +package org.oscim.tiling.source.bitmap; + +import org.oscim.core.Tile; +import org.oscim.layers.tile.BitmapTileLayer.FadeStep; + +public class DefaultSources { + + public static class OpenStreetMap extends BitmapTileSource { + public OpenStreetMap() { + super("http://tile.openstreetmap.org", 0, 18); + } + } + + public static class OSMTransport extends BitmapTileSource { + public OSMTransport() { + super("http://a.tile.thunderforest.com/transport", 0, 18); + } + } + + public static class StamenToner extends BitmapTileSource { + public StamenToner() { + super("http://a.tile.stamen.com/toner", 0, 16); + } + } + + public static class StamenWatercolor extends BitmapTileSource { + public StamenWatercolor() { + super("http://a.tile.stamen.com/watercolor", 0, 16); + } + } + + public static class ImagicoLandcover extends BitmapTileSource { + public ImagicoLandcover() { + super("http://www.imagico.de/map/tiles/landcover", + 0, 6, "image/jpeg", ".jpg"); + } + } + + public static class MapQuestAerial extends BitmapTileSource { + public MapQuestAerial() { + super("http://otile1.mqcdn.com/tiles/1.0.0/sat", + 0, 8, "image/jpeg", ".jpg"); + } + + @Override + public FadeStep[] getFadeSteps() { + return fadeSteps; + } + } + + public static class NaturalEarth extends BitmapTileSource { + public NaturalEarth() { + super("http://opensciencemap.org/tiles/ne", 0, 8); + } + + @Override + public FadeStep[] getFadeSteps() { + return fadeSteps; + } + } + + public static class ArcGISWorldShaded extends BitmapTileSource { + public ArcGISWorldShaded() { + super("http://server.arcgisonline.com/ArcGIS/rest/services", + 0, 6, "image/jpg", ""); + } + + @Override + public String getTileUrl(Tile tile) { + StringBuilder sb = new StringBuilder(32); + //sb.append("/World_Imagery/MapServer/tile/"); + sb.append("/World_Shaded_Relief/MapServer/tile/"); + sb.append(tile.zoomLevel); + sb.append('/').append(tile.tileY); + sb.append('/').append(tile.tileX); + return sb.toString(); + } + } + + public static class HillShadeHD extends BitmapTileSource { + public HillShadeHD() { + super("http://129.206.74.245:8004/tms_hs.ashx", + 2, 16, "image/png", ""); + } + + @Override + public String getTileUrl(Tile tile) { + StringBuilder sb = new StringBuilder(32); + sb.append("?x=").append(tile.tileX); + sb.append("&y=").append(tile.tileY); + sb.append("&z=").append(tile.zoomLevel); + return sb.toString(); + } + } + + final static FadeStep[] fadeSteps = new FadeStep[] { + new FadeStep(0, 8 - 1, 1, 0.7f), + // dont fade between zoom-min/max + // fade above zoom max + 2, interpolate 1 to 0 + new FadeStep(8 - 1, 8 + 1, 0.7f, 0) + }; +}