Merge branch 'unify_tilesources'
This commit is contained in:
commit
c8949194cc
@ -45,7 +45,6 @@ public class BaseMapActivity extends MapActivity {
|
||||
registerMapView(mMapView);
|
||||
|
||||
mTileSource = new OSciMap4TileSource();
|
||||
mTileSource.setOption("url", "http://opensciencemap.org/tiles/vtm");
|
||||
|
||||
if (USE_CACHE) {
|
||||
mCache = new TileCache(this, "cachedir", "testdb");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<GeoPoint> pts = new ArrayList<GeoPoint>();
|
||||
|
||||
|
||||
@ -25,11 +25,15 @@ import android.opengl.GLUtils;
|
||||
|
||||
public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
final Bitmap mBitmap;
|
||||
|
||||
public AndroidBitmap(InputStream inputStream) {
|
||||
mBitmap = BitmapFactory.decodeStream(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(){
|
||||
return mBitmap != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param format ignored always ARGB8888
|
||||
*/
|
||||
|
||||
@ -85,4 +85,9 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
public void recycle() {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return mBitmap != null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,10 +57,7 @@ public class MainActivity extends AndroidApplication {
|
||||
class GdxMapAndroid extends GdxMap {
|
||||
@Override
|
||||
public void createLayers() {
|
||||
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
ts.setOption("url", "http://opensciencemap.org/tiles/vtm");
|
||||
|
||||
initDefaultLayers(ts, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,4 +134,9 @@ public class AwtBitmap implements Bitmap {
|
||||
@Override
|
||||
public void recycle() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,4 +88,9 @@ public class GwtBitmap implements Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,17 +19,17 @@ package org.oscim.gdx.client;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
@ -108,17 +108,15 @@ class GwtGdxMap extends GdxMap {
|
||||
|
||||
TileSource tileSource;
|
||||
if ("oscimap4".equals(sourceName))
|
||||
tileSource = new OSciMap4TileSource();
|
||||
tileSource = new OSciMap4TileSource(url);
|
||||
else
|
||||
//if ("oscimap2".equals(source))
|
||||
tileSource = new OSciMap2TileSource();
|
||||
|
||||
tileSource.setOption("url", url);
|
||||
tileSource = new OSciMap2TileSource(url);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<TileLoader> {
|
||||
|
||||
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() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,7 @@
|
||||
*/
|
||||
package org.oscim.layers.tile.vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
@ -47,6 +46,8 @@ import org.oscim.tiling.source.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.ITileDataSource.QueryResult;
|
||||
import org.oscim.utils.LineClipper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class VectorTileLoader extends TileLoader implements IRenderTheme.Callback, ITileDataSink {
|
||||
|
||||
@ -425,4 +426,10 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
}
|
||||
l.add(mElement, height, minHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileImage(Bitmap bitmap) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,9 +76,9 @@ public class LwHttp {
|
||||
mHttpRequest.abort();
|
||||
}
|
||||
|
||||
private PbfTileDataSource mDataSource;
|
||||
private UrlTileDataSource mDataSource;
|
||||
|
||||
public boolean sendRequest(Tile tile, PbfTileDataSource dataSource) throws IOException {
|
||||
public boolean sendRequest(Tile tile, UrlTileDataSource dataSource) throws IOException {
|
||||
mDataSource = dataSource;
|
||||
|
||||
byte[] request = mRequestBuffer;
|
||||
@ -116,9 +116,9 @@ public class LwHttp {
|
||||
if (status == 200) {
|
||||
Uint8Array buf = Uint8ArrayNative.create(xhr.getResponseArrayBuffer());
|
||||
|
||||
mDataSource.process(new Buffer(buf), buf.byteLength());
|
||||
mDataSource.process(new Buffer(buf));
|
||||
} else {
|
||||
mDataSource.process(null, -1);
|
||||
mDataSource.process(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,24 +18,22 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.tiling.MapTile;
|
||||
import org.oscim.tiling.source.ITileCache;
|
||||
import org.oscim.tiling.source.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.ITileDecoder;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class PbfTileDataSource implements ITileDataSource {
|
||||
static final Logger log = LoggerFactory.getLogger(PbfTileDataSource.class);
|
||||
public class UrlTileDataSource implements ITileDataSource {
|
||||
static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
|
||||
|
||||
protected LwHttp mConn;
|
||||
protected final PbfDecoder mTileDecoder;
|
||||
protected final LwHttp mConn;
|
||||
protected final ITileDecoder mTileDecoder;
|
||||
|
||||
public PbfTileDataSource(PbfDecoder tileDecoder, ITileCache cache) {
|
||||
public UrlTileDataSource(TileSource tileSource, ITileDecoder tileDecoder, LwHttp conn) {
|
||||
mTileDecoder = tileDecoder;
|
||||
mConn = conn;
|
||||
}
|
||||
|
||||
private ITileDataSink mSink;
|
||||
@ -56,12 +54,12 @@ public abstract class PbfTileDataSource implements ITileDataSource {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void process(InputStream is, int length) {
|
||||
public void process(InputStream is) {
|
||||
|
||||
boolean win = false;
|
||||
if (length >= 0) {
|
||||
if (is != null) {
|
||||
try {
|
||||
win = mTileDecoder.decode(mTile, mSink, is, length);
|
||||
win = mTileDecoder.decode(mTile, mSink, is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -60,4 +60,6 @@ public interface Bitmap {
|
||||
* @param replace true, when glSubImage2D can be used for upload
|
||||
*/
|
||||
void uploadToTexture(boolean replace);
|
||||
|
||||
boolean isValid();
|
||||
}
|
||||
|
||||
@ -14,26 +14,23 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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,33 +41,43 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
@ -91,47 +98,54 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
|
||||
|
||||
@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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,15 +53,18 @@ public abstract class TileLayer<T extends TileLoader> extends Layer implements M
|
||||
|
||||
// Instantiate TileLoader threads
|
||||
mTileLoader = new ArrayList<T>();
|
||||
|
||||
// RenderLayer is working in GL Thread and actually
|
||||
// drawing loaded tiles to screen.
|
||||
mRenderer = mRenderLayer = new TileRenderer(mTileManager);
|
||||
}
|
||||
|
||||
protected void initLoader() {
|
||||
for (int i = 0; i < mNumTileLoader; i++) {
|
||||
T tileGenerator = createLoader(mTileManager);
|
||||
mTileLoader.add(tileGenerator);
|
||||
tileGenerator.start();
|
||||
}
|
||||
|
||||
// RenderLayer is working in GL Thread and actually
|
||||
// drawing loaded tiles to screen.
|
||||
mRenderer = mRenderLayer = new TileRenderer(mTileManager);
|
||||
}
|
||||
|
||||
abstract protected T createLoader(TileManager tm);
|
||||
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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)
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,10 +39,12 @@ public class VectorTileLayer extends TileLayer<VectorTileLoader> {
|
||||
|
||||
public VectorTileLayer(Map map) {
|
||||
super(map);
|
||||
initLoader();
|
||||
}
|
||||
|
||||
public VectorTileLayer(Map map, int minZoom, int maxZoom, int cacheLimit) {
|
||||
super(map, minZoom, maxZoom, cacheLimit);
|
||||
initLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -18,6 +18,7 @@ package org.oscim.layers.tile.vector;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
@ -463,4 +464,9 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
@Override
|
||||
public void completed(boolean success) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileImage(Bitmap bitmap) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<UpdateListener> mUpdateListenerSet = new LinkedHashSet<UpdateListener>();
|
||||
private UpdateListener[] mUpdateListeners;
|
||||
|
||||
protected boolean mClearMap;
|
||||
protected boolean mClearMap = true;
|
||||
|
||||
public Map() {
|
||||
mViewport = new Viewport(this);
|
||||
|
||||
@ -165,6 +165,11 @@ public class TileManager {
|
||||
* current MapPosition
|
||||
*/
|
||||
public boolean update(MapPosition pos) {
|
||||
|
||||
// FIXME cant expect init to be called otherwise
|
||||
if (mNewTiles == null)
|
||||
init();
|
||||
|
||||
// clear JobQueue and set tiles to state == NONE.
|
||||
// one could also append new tiles and sort in JobQueue
|
||||
// but this has the nice side-effect that MapWorkers dont
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.oscim.tiling.source;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
|
||||
/**
|
||||
@ -28,5 +29,7 @@ public interface ITileDataSink {
|
||||
|
||||
void process(MapElement element);
|
||||
|
||||
void setTileImage(Bitmap bitmap);
|
||||
|
||||
void completed(boolean success);
|
||||
}
|
||||
|
||||
12
vtm/src/org/oscim/tiling/source/ITileDecoder.java
Normal file
12
vtm/src/org/oscim/tiling/source/ITileDecoder.java
Normal file
@ -0,0 +1,12 @@
|
||||
package org.oscim.tiling.source;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
|
||||
public interface ITileDecoder {
|
||||
|
||||
boolean decode(Tile tile, ITileDataSink sink, InputStream is)
|
||||
throws IOException;
|
||||
}
|
||||
94
vtm/src/org/oscim/tiling/source/bitmap/BitmapTileSource.java
Normal file
94
vtm/src/org/oscim/tiling/source/bitmap/BitmapTileSource.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
102
vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java
Normal file
102
vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java
Normal file
@ -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)
|
||||
};
|
||||
}
|
||||
@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class LwHttp {
|
||||
static final Logger log = LoggerFactory.getLogger(LwHttp.class);
|
||||
static final boolean DBG = false;
|
||||
|
||||
private final static byte[] HEADER_HTTP_OK = "200 OK".getBytes();
|
||||
private final static byte[] HEADER_CONTENT_TYPE = "Content-Type".getBytes();
|
||||
@ -46,7 +47,7 @@ public class LwHttp {
|
||||
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
||||
private final static long RESPONSE_TIMEOUT = (long) 10E9; // 10 second in nanosecond
|
||||
|
||||
private final static int BUFFER_SIZE = 1024;
|
||||
private final static int BUFFER_SIZE = 8192;
|
||||
private final byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
private final String mHost;
|
||||
@ -55,7 +56,7 @@ public class LwHttp {
|
||||
private int mMaxReq = 0;
|
||||
private Socket mSocket;
|
||||
private OutputStream mCommandStream;
|
||||
private InputStream mResponseStream;
|
||||
private Buffer mResponseStream;
|
||||
private OutputStream mCacheOutputStream;
|
||||
private long mLastRequest = 0;
|
||||
private SocketAddress mSockAddr;
|
||||
@ -67,8 +68,6 @@ public class LwHttp {
|
||||
private final boolean mInflateContent;
|
||||
private final byte[] mContentType;
|
||||
|
||||
private int mContentLength = -1;
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* Base url for tiles
|
||||
@ -93,7 +92,7 @@ public class LwHttp {
|
||||
|
||||
REQUEST_GET_START = ("GET " + path).getBytes();
|
||||
|
||||
REQUEST_GET_END = ("." + extension + " HTTP/1.1" +
|
||||
REQUEST_GET_END = (extension + " HTTP/1.1" +
|
||||
"\nHost: " + host +
|
||||
"\nConnection: Keep-Alive" +
|
||||
"\n\n").getBytes();
|
||||
@ -106,18 +105,40 @@ public class LwHttp {
|
||||
mRequestBuffer, 0, REQUEST_GET_START.length);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// to avoid a copy in PbfDecoder one could manage the buffer
|
||||
// array directly and provide access to it.
|
||||
static class Buffer extends BufferedInputStream {
|
||||
final OutputStream mCacheOutputstream;
|
||||
OutputStream mCacheOutputstream;
|
||||
int sumRead = 0;
|
||||
int mContentLength;
|
||||
|
||||
public Buffer(InputStream is, OutputStream cache) {
|
||||
super(is, 4096);
|
||||
public Buffer(InputStream is) {
|
||||
super(is, BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public void setCache(OutputStream cache) {
|
||||
mCacheOutputstream = cache;
|
||||
}
|
||||
|
||||
public void start(int length) {
|
||||
sumRead = 0;
|
||||
mContentLength = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (sumRead >= mContentLength)
|
||||
return -1;
|
||||
|
||||
int data = super.read();
|
||||
if (data >= 0)
|
||||
|
||||
sumRead += 1;
|
||||
|
||||
if (DBG)
|
||||
log.debug("read {} {}", sumRead, mContentLength);
|
||||
|
||||
if (mCacheOutputstream != null)
|
||||
mCacheOutputstream.write(data);
|
||||
|
||||
return data;
|
||||
@ -126,13 +147,25 @@ public class LwHttp {
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int byteCount)
|
||||
throws IOException {
|
||||
int len = super.read(buffer, offset, byteCount);
|
||||
|
||||
if (len >= 0)
|
||||
mCacheOutputstream.write(buffer, offset, len);
|
||||
if (sumRead >= mContentLength)
|
||||
return -1;
|
||||
|
||||
int len = super.read(buffer, offset, byteCount);
|
||||
sumRead += len;
|
||||
|
||||
if (DBG)
|
||||
log.debug("read {} {} {}", len, sumRead, mContentLength);
|
||||
|
||||
if (mCacheOutputstream != null)
|
||||
mCacheOutputstream.write(buffer, offset, byteCount);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
public byte[] getArray() {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@ -149,8 +182,9 @@ public class LwHttp {
|
||||
|
||||
public InputStream readHeader() throws IOException {
|
||||
|
||||
InputStream is = mResponseStream;
|
||||
is.mark(4096);
|
||||
Buffer is = mResponseStream;
|
||||
is.mark(BUFFER_SIZE);
|
||||
is.start(BUFFER_SIZE);
|
||||
|
||||
byte[] buf = buffer;
|
||||
boolean first = true;
|
||||
@ -161,7 +195,7 @@ public class LwHttp {
|
||||
int end = 0;
|
||||
int len = 0;
|
||||
|
||||
mContentLength = -1;
|
||||
int contentLength = -1;
|
||||
|
||||
// header may not be larger than BUFFER_SIZE for this to work
|
||||
for (; (pos < read) || ((read < BUFFER_SIZE) &&
|
||||
@ -202,11 +236,11 @@ public class LwHttp {
|
||||
|
||||
} else if (check(HEADER_CONTENT_LENGTH, buf, pos, end)) {
|
||||
// parse Content-Length
|
||||
mContentLength = parseInt(buf, pos +
|
||||
contentLength = parseInt(buf, pos +
|
||||
HEADER_CONTENT_LENGTH.length + 2, end - 1);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!ok || DBG) {
|
||||
String line = new String(buf, pos, end - pos - 1);
|
||||
log.debug("> {} <", line);
|
||||
}
|
||||
@ -223,9 +257,8 @@ public class LwHttp {
|
||||
is.mark(0);
|
||||
is.skip(end);
|
||||
|
||||
if (mCacheOutputStream != null) {
|
||||
is = new Buffer(is, mCacheOutputStream);
|
||||
}
|
||||
is.setCache(mCacheOutputStream);
|
||||
is.start(contentLength);
|
||||
|
||||
if (mInflateContent)
|
||||
return new InflaterInputStream(is);
|
||||
@ -238,14 +271,10 @@ public class LwHttp {
|
||||
if (mSocket != null && ((mMaxReq-- <= 0)
|
||||
|| (System.nanoTime() - mLastRequest > RESPONSE_TIMEOUT))) {
|
||||
|
||||
try {
|
||||
mSocket.close();
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
close();
|
||||
|
||||
// log.debug("not alive - recreate connection " + mMaxReq);
|
||||
mSocket = null;
|
||||
if (DBG)
|
||||
log.debug("not alive - recreate connection " + mMaxReq);
|
||||
}
|
||||
|
||||
if (mSocket == null) {
|
||||
@ -267,23 +296,16 @@ public class LwHttp {
|
||||
|
||||
byte[] request = mRequestBuffer;
|
||||
int pos = REQUEST_GET_START.length;
|
||||
int newPos = 0;
|
||||
|
||||
if ((newPos = formatTilePath(tile, request, pos)) == 0) {
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.zoomLevel, pos, request);
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.tileX, pos, request);
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.tileY, pos, request);
|
||||
} else {
|
||||
pos = newPos;
|
||||
}
|
||||
pos = formatTilePath(tile, request, pos);
|
||||
|
||||
int len = REQUEST_GET_END.length;
|
||||
System.arraycopy(REQUEST_GET_END, 0, request, pos, len);
|
||||
len += pos;
|
||||
|
||||
if (DBG)
|
||||
log.debug("request: {}", new String(request, 0, len));
|
||||
|
||||
try {
|
||||
mCommandStream.write(request, 0, len);
|
||||
mCommandStream.flush();
|
||||
@ -309,7 +331,7 @@ public class LwHttp {
|
||||
mSocket.setTcpNoDelay(true);
|
||||
|
||||
mCommandStream = mSocket.getOutputStream();
|
||||
mResponseStream = new BufferedInputStream(mSocket.getInputStream());
|
||||
mResponseStream = new Buffer(mSocket.getInputStream());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -366,10 +388,6 @@ public class LwHttp {
|
||||
close();
|
||||
}
|
||||
|
||||
public int getContentLength() {
|
||||
return mContentLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write custom tile url
|
||||
*
|
||||
@ -378,8 +396,14 @@ public class LwHttp {
|
||||
* @param curPos current position
|
||||
* @return new position
|
||||
*/
|
||||
protected int formatTilePath(Tile tile, byte[] path, int curPos) {
|
||||
return 0;
|
||||
protected int formatTilePath(Tile tile, byte[] request, int pos) {
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.zoomLevel, pos, request);
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.tileX, pos, request);
|
||||
request[pos++] = '/';
|
||||
pos = writeInt(tile.tileY, pos, request);
|
||||
return pos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,13 +19,12 @@ package org.oscim.tiling.source.common;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.source.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDecoder;
|
||||
import org.oscim.utils.UTF8Decoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class PbfDecoder {
|
||||
public abstract class PbfDecoder implements ITileDecoder {
|
||||
static final Logger log = LoggerFactory.getLogger(PbfDecoder.class);
|
||||
|
||||
private final static int S1 = 7;
|
||||
@ -73,9 +72,6 @@ public abstract class PbfDecoder {
|
||||
// offset of buffer in message
|
||||
private int mBufferOffset;
|
||||
|
||||
// max bytes to read: message = header + content
|
||||
private int mMsgEnd;
|
||||
|
||||
// overall bytes of message read
|
||||
private int mMsgPos;
|
||||
|
||||
@ -87,10 +83,7 @@ public abstract class PbfDecoder {
|
||||
mStringDecoder = new UTF8Decoder();
|
||||
}
|
||||
|
||||
public abstract boolean decode(Tile tile, ITileDataSink sink,
|
||||
InputStream is, int contentLength) throws IOException;
|
||||
|
||||
public void setInputStream(InputStream is, int contentLength) {
|
||||
public void setInputStream(InputStream is) {
|
||||
mInputStream = is;
|
||||
|
||||
bufferFill = 0;
|
||||
@ -98,7 +91,6 @@ public abstract class PbfDecoder {
|
||||
mBufferOffset = 0;
|
||||
|
||||
mMsgPos = 0;
|
||||
mMsgEnd = contentLength;
|
||||
}
|
||||
|
||||
protected int decodeVarint32() throws IOException {
|
||||
@ -401,8 +393,8 @@ public abstract class PbfDecoder {
|
||||
}
|
||||
|
||||
public boolean hasData() throws IOException {
|
||||
if (mBufferOffset + bufferPos >= mMsgEnd)
|
||||
return false;
|
||||
//if (mBufferOffset + bufferPos >= mMsgEnd)
|
||||
// return false;
|
||||
|
||||
return fillBuffer(1) > 0;
|
||||
}
|
||||
@ -418,10 +410,6 @@ public abstract class PbfDecoder {
|
||||
if (bytesLeft >= size)
|
||||
return bytesLeft;
|
||||
|
||||
// check if inputstream is read to the end
|
||||
if (mMsgPos >= mMsgEnd)
|
||||
return bytesLeft;
|
||||
|
||||
int maxSize = buffer.length;
|
||||
|
||||
if (size > maxSize) {
|
||||
@ -458,10 +446,7 @@ public abstract class PbfDecoder {
|
||||
}
|
||||
|
||||
while ((bufferFill - bufferPos) < size) {
|
||||
|
||||
int max = maxSize - bufferFill;
|
||||
if (max > mMsgEnd - mMsgPos)
|
||||
max = mMsgEnd - mMsgPos;
|
||||
|
||||
if (max <= 0) {
|
||||
// should not be possible
|
||||
@ -472,9 +457,8 @@ public abstract class PbfDecoder {
|
||||
int len = mInputStream.read(buffer, bufferFill, max);
|
||||
|
||||
if (len < 0) {
|
||||
mMsgEnd = mMsgPos;
|
||||
if (debug)
|
||||
log.debug(" finished reading " + mMsgPos);
|
||||
log.debug("finished reading {}", mMsgPos);
|
||||
|
||||
// finished reading, mark end
|
||||
buffer[bufferFill] = 0;
|
||||
@ -483,10 +467,6 @@ public abstract class PbfDecoder {
|
||||
|
||||
mMsgPos += len;
|
||||
bufferFill += len;
|
||||
|
||||
if (mMsgPos == mMsgEnd)
|
||||
break;
|
||||
|
||||
}
|
||||
return bufferFill - bufferPos;
|
||||
}
|
||||
|
||||
@ -26,20 +26,23 @@ import org.oscim.tiling.MapTile;
|
||||
import org.oscim.tiling.source.ITileCache;
|
||||
import org.oscim.tiling.source.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.ITileDecoder;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.oscim.utils.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class PbfTileDataSource implements ITileDataSource {
|
||||
static final Logger log = LoggerFactory.getLogger(PbfTileDataSource.class);
|
||||
public class UrlTileDataSource implements ITileDataSource {
|
||||
static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
|
||||
|
||||
protected LwHttp mConn;
|
||||
protected final PbfDecoder mTileDecoder;
|
||||
protected final LwHttp mConn;
|
||||
protected final ITileDecoder mTileDecoder;
|
||||
protected final ITileCache mTileCache;
|
||||
|
||||
public PbfTileDataSource(PbfDecoder tileDecoder, ITileCache tileCache) {
|
||||
public UrlTileDataSource(TileSource tileSource, ITileDecoder tileDecoder, LwHttp conn) {
|
||||
mTileDecoder = tileDecoder;
|
||||
mTileCache = tileCache;
|
||||
mTileCache = tileSource.tileCache;
|
||||
mConn = conn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,7 +57,7 @@ public abstract class PbfTileDataSource implements ITileDataSource {
|
||||
} else {
|
||||
InputStream is = c.getInputStream();
|
||||
try {
|
||||
if (mTileDecoder.decode(tile, sink, is, c.getBytes())) {
|
||||
if (mTileDecoder.decode(tile, sink, is)) {
|
||||
return QueryResult.SUCCESS;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -76,15 +79,14 @@ public abstract class PbfTileDataSource implements ITileDataSource {
|
||||
} else if ((is = mConn.readHeader()) == null) {
|
||||
log.debug("{} Network Error", tile);
|
||||
} else {
|
||||
int bytes = mConn.getContentLength();
|
||||
success = mTileDecoder.decode(tile, sink, is, bytes);
|
||||
success = mTileDecoder.decode(tile, sink, is);
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
log.debug("{} Socket exception: {}", tile, e.getMessage());
|
||||
} catch (SocketTimeoutException e) {
|
||||
log.debug("{} Socket Timeout", tile);
|
||||
} catch (UnknownHostException e) {
|
||||
log.debug("{} No Network", tile);
|
||||
log.debug("{} Unknown host: {}", tile, e.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -22,22 +22,21 @@ import java.net.URL;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
|
||||
public abstract class UrlTileSource extends TileSource {
|
||||
private final static String KEY_URL = "url";
|
||||
|
||||
protected URL mUrl;
|
||||
protected final URL mUrl;
|
||||
|
||||
public UrlTileSource(String urlString) {
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(urlString);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpenResult open() {
|
||||
if (!options.containsKey(KEY_URL))
|
||||
return new OpenResult("no url set");
|
||||
String urlString = options.get(KEY_URL);
|
||||
try {
|
||||
mUrl = new URL(urlString);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return new OpenResult("invalid url " + urlString);
|
||||
}
|
||||
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -45,9 +44,4 @@ public abstract class UrlTileSource extends TileSource {
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
public boolean setUrl(String urlString) {
|
||||
options.put("url", urlString);
|
||||
return open() == OpenResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,50 +16,43 @@
|
||||
*/
|
||||
package org.oscim.tiling.source.mapnik;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.oscim.tiling.source.common.LwHttp;
|
||||
import org.oscim.tiling.source.common.PbfTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileSource;
|
||||
|
||||
public class MapnikVectorTileSource extends UrlTileSource {
|
||||
|
||||
public MapnikVectorTileSource() {
|
||||
super("http://d1s11ojcu7opje.cloudfront.net/dev/764e0b8d");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new TileDataSource(this, mUrl);
|
||||
}
|
||||
LwHttp conn = new LwHttp(mUrl, "image/png", ".vector.pbf", true) {
|
||||
@Override
|
||||
protected int formatTilePath(Tile tile, byte[] path, int pos) {
|
||||
// url formatter for mapbox streets
|
||||
byte[] hexTable = {
|
||||
'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f'
|
||||
};
|
||||
|
||||
static class TileDataSource extends PbfTileDataSource {
|
||||
|
||||
public TileDataSource(TileSource tileSource, URL url) {
|
||||
super(new TileDecoder(), tileSource.tileCache);
|
||||
|
||||
mConn = new LwHttp(url, "image/png", "vector.pbf", true) {
|
||||
@Override
|
||||
protected int formatTilePath(Tile tile, byte[] path, int pos) {
|
||||
// url formatter for mapbox streets
|
||||
byte[] hexTable = {
|
||||
'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f'
|
||||
};
|
||||
|
||||
path[pos++] = '/';
|
||||
path[pos++] = hexTable[(tile.tileX) % 16];
|
||||
path[pos++] = hexTable[(tile.tileY) % 16];
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.zoomLevel, pos, path);
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.tileX, pos, path);
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.tileY, pos, path);
|
||||
return pos;
|
||||
}
|
||||
};
|
||||
}
|
||||
path[pos++] = '/';
|
||||
path[pos++] = hexTable[(tile.tileX) % 16];
|
||||
path[pos++] = hexTable[(tile.tileY) % 16];
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.zoomLevel, pos, path);
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.tileX, pos, path);
|
||||
path[pos++] = '/';
|
||||
pos = LwHttp.writeInt(tile.tileY, pos, path);
|
||||
return pos;
|
||||
}
|
||||
};
|
||||
return new UrlTileDataSource(this, new TileDecoder(), conn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,13 +71,13 @@ public class TileDecoder extends PbfDecoder {
|
||||
private float mScale;
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink mapDataCallback, InputStream is,
|
||||
int contentLength)
|
||||
public boolean decode(Tile tile, ITileDataSink mapDataCallback, InputStream is)
|
||||
throws IOException {
|
||||
|
||||
if (debug)
|
||||
log.debug(tile + " decode");
|
||||
|
||||
setInputStream(is, Integer.MAX_VALUE);
|
||||
setInputStream(is);
|
||||
mTile = tile;
|
||||
mMapDataCallback = mapDataCallback;
|
||||
mScale = REF_TILE_SIZE / Tile.SIZE;
|
||||
|
||||
@ -16,12 +16,9 @@
|
||||
*/
|
||||
package org.oscim.tiling.source.oscimap;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.oscim.tiling.source.common.LwHttp;
|
||||
import org.oscim.tiling.source.common.PbfTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileSource;
|
||||
|
||||
/**
|
||||
@ -30,15 +27,13 @@ import org.oscim.tiling.source.common.UrlTileSource;
|
||||
*/
|
||||
public class OSciMap1TileSource extends UrlTileSource {
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new TileDataSource(this, mUrl);
|
||||
public OSciMap1TileSource(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
class TileDataSource extends PbfTileDataSource {
|
||||
public TileDataSource(TileSource tileSource, URL url) {
|
||||
super(new TileDecoder(), tileSource.tileCache);
|
||||
mConn = new LwHttp(url, "application/osmtile", "osmtile", false);
|
||||
}
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
LwHttp conn = new LwHttp(mUrl, "application/osmtile", ".osmtile", false);
|
||||
return new UrlTileDataSource(this, new TileDecoder(), conn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,10 +68,10 @@ public class TileDecoder extends PbfDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is, int contentLength)
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is)
|
||||
throws IOException {
|
||||
|
||||
setInputStream(is, contentLength);
|
||||
setInputStream(is);
|
||||
|
||||
mTile = tile;
|
||||
mSink = sink;
|
||||
|
||||
@ -18,7 +18,6 @@ package org.oscim.tiling.source.oscimap2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
@ -28,26 +27,23 @@ import org.oscim.core.TagSet;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.source.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.oscim.tiling.source.common.LwHttp;
|
||||
import org.oscim.tiling.source.common.PbfDecoder;
|
||||
import org.oscim.tiling.source.common.PbfTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class OSciMap2TileSource extends UrlTileSource {
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new TileDataSource(this, mUrl);
|
||||
public OSciMap2TileSource(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
class TileDataSource extends PbfTileDataSource {
|
||||
public TileDataSource(TileSource tileSource, URL url) {
|
||||
super(new TileDecoder(), tileSource.tileCache);
|
||||
mConn = new LwHttp(url, "application/osmtile", "osmtile", false);
|
||||
}
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
LwHttp conn = new LwHttp(mUrl, "application/osmtile", ".osmtile", false);
|
||||
return new UrlTileDataSource(this, new TileDecoder(), conn);
|
||||
}
|
||||
|
||||
static class TileDecoder extends PbfDecoder {
|
||||
@ -92,17 +88,12 @@ public class OSciMap2TileSource extends UrlTileSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is, int contentLength)
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is)
|
||||
throws IOException {
|
||||
|
||||
int byteCount = readUnsignedInt(is, buffer);
|
||||
//log.debug(tile + " contentLength:" + byteCount);
|
||||
if (byteCount < 0) {
|
||||
log.debug(tile + " invalid content length: " + byteCount);
|
||||
return false;
|
||||
}
|
||||
readUnsignedInt(is, buffer);
|
||||
|
||||
setInputStream(is, byteCount);
|
||||
setInputStream(is);
|
||||
|
||||
mTile = tile;
|
||||
mMapDataSink = sink;
|
||||
|
||||
@ -16,26 +16,25 @@
|
||||
*/
|
||||
package org.oscim.tiling.source.oscimap4;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.oscim.tiling.source.ITileDataSource;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
import org.oscim.tiling.source.common.LwHttp;
|
||||
import org.oscim.tiling.source.common.PbfTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.common.UrlTileSource;
|
||||
|
||||
public class OSciMap4TileSource extends UrlTileSource {
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new TileDataSource(this, mUrl);
|
||||
public OSciMap4TileSource() {
|
||||
super("http://opensciencemap.org/tiles/vtm");
|
||||
}
|
||||
|
||||
class TileDataSource extends PbfTileDataSource {
|
||||
public TileDataSource(TileSource tileSource, URL url) {
|
||||
super(new TileDecoder(), tileSource.tileCache);
|
||||
//mConn = new LwHttp(url, "application/x-protobuf", "vtm", false);
|
||||
mConn = new LwHttp(url, "image/png", "vtm", false);
|
||||
}
|
||||
public OSciMap4TileSource(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
//LwHttp conn = new LwHttp(url, "application/x-protobuf", ".vtm", false);
|
||||
LwHttp conn = new LwHttp(mUrl, "image/png", ".vtm", false);
|
||||
return new UrlTileDataSource(this, new TileDecoder(), conn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,17 +76,13 @@ public class TileDecoder extends PbfDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is, int contentLength)
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is)
|
||||
throws IOException {
|
||||
|
||||
int byteCount = readUnsignedInt(is, buffer);
|
||||
readUnsignedInt(is, buffer);
|
||||
//log.debug(tile + " contentLength:" + byteCount);
|
||||
if (byteCount < 0) {
|
||||
log.debug("invalid contentLength: " + byteCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
setInputStream(is, byteCount);
|
||||
setInputStream(is);
|
||||
|
||||
mTile = tile;
|
||||
mMapDataSink = sink;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user