- MapView now requires to setMapDatabase(MapOptions) explicitly
- pass MapOptions when opening MapDatabase
This commit is contained in:
parent
2ac904ecef
commit
7f598f5ccf
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||||
|
* Copyright 2012 Hannes Janetzek
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -14,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.database;
|
package org.oscim.database;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
|
|
||||||
@ -26,7 +26,6 @@ public interface IMapDatabase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a database query with the given parameters.
|
* Starts a database query with the given parameters.
|
||||||
*
|
|
||||||
* @param tile
|
* @param tile
|
||||||
* the tile to read.
|
* the tile to read.
|
||||||
* @param mapDatabaseCallback
|
* @param mapDatabaseCallback
|
||||||
@ -50,15 +49,15 @@ public interface IMapDatabase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens MapDatabase
|
* Opens MapDatabase
|
||||||
*
|
|
||||||
* @param options
|
* @param options
|
||||||
* the options.
|
* the options.
|
||||||
* @return a OpenResult containing an error message in case of a failure.
|
* @return a OpenResult containing an error message in case of a failure.
|
||||||
*/
|
*/
|
||||||
public abstract OpenResult open(Map<String, String> options);
|
public abstract OpenResult open(MapOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the map file and destroys all internal caches. Has no effect if no map file is currently opened.
|
* Closes the map file and destroys all internal caches. Has no effect if no
|
||||||
|
* map file is currently opened.
|
||||||
*/
|
*/
|
||||||
public abstract void close();
|
public abstract void close();
|
||||||
|
|
||||||
|
43
src/org/oscim/database/MapOptions.java
Normal file
43
src/org/oscim/database/MapOptions.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 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.database;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class MapOptions extends HashMap<String, String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public final MapDatabases db;
|
||||||
|
|
||||||
|
public MapOptions(MapDatabases db) {
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof MapOptions))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (this.db != ((MapOptions) other).db)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// FIXME test if this is correct!
|
||||||
|
if (!this.entrySet().equals(((MapOptions) other).entrySet()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,6 @@ package org.oscim.database.mapfile;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -25,6 +24,7 @@ import org.oscim.core.MercatorProjection;
|
|||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
import org.oscim.database.IMapDatabaseCallback;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.database.QueryResult;
|
import org.oscim.database.QueryResult;
|
||||||
import org.oscim.database.mapfile.header.MapFileHeader;
|
import org.oscim.database.mapfile.header.MapFileHeader;
|
||||||
@ -273,7 +273,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
* @see org.oscim.map.reader.IMapDatabase#openFile(java.io.File)
|
* @see org.oscim.map.reader.IMapDatabase#openFile(java.io.File)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public OpenResult open(Map<String, String> options) {
|
public OpenResult open(MapOptions options) {
|
||||||
// if (options == null) {
|
// if (options == null) {
|
||||||
// options = new HashMap<String, String>(1);
|
// options = new HashMap<String, String>(1);
|
||||||
// options.put("mapfile", "/sdcard/bremen.map");
|
// options.put("mapfile", "/sdcard/bremen.map");
|
||||||
|
@ -23,12 +23,13 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
@ -37,6 +38,7 @@ import org.oscim.core.Tile;
|
|||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
import org.oscim.database.IMapDatabaseCallback;
|
||||||
import org.oscim.database.MapInfo;
|
import org.oscim.database.MapInfo;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.database.QueryResult;
|
import org.oscim.database.QueryResult;
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
@ -60,16 +62,18 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private boolean mOpenFile = false;
|
private boolean mOpenFile = false;
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private static final String CACHE_DIRECTORY = "/Android/data/org.oscim.app/cache/";
|
private static final String CACHE_DIRECTORY = "/Android/data/org.oscim.app/cache/";
|
||||||
private static final String CACHE_FILE = "%d-%d-%d.tile";
|
private static final String CACHE_FILE = "%d-%d-%d.tile";
|
||||||
|
|
||||||
private static final String SERVER_ADDR = "city.informatik.uni-bremen.de";
|
//private static String SERVER_ADDR = "city.informatik.uni-bremen.de";
|
||||||
|
//private static int PORT = 80;
|
||||||
//private static final String URL = "/osci/map-live/";
|
//private static final String URL = "/osci/map-live/";
|
||||||
private static final String URL = "/osci/oscim/";
|
//private static String TILE_URL = "/osci/oscim/";
|
||||||
|
|
||||||
private final static float REF_TILE_SIZE = 4096.0f;
|
private final static float REF_TILE_SIZE = 4096.0f;
|
||||||
|
|
||||||
|
private static File cacheDir;
|
||||||
|
|
||||||
private int MAX_TILE_TAGS = 100;
|
private int MAX_TILE_TAGS = 100;
|
||||||
private Tag[] curTags = new Tag[MAX_TILE_TAGS];
|
private Tag[] curTags = new Tag[MAX_TILE_TAGS];
|
||||||
private int mCurTagCnt;
|
private int mCurTagCnt;
|
||||||
@ -79,6 +83,8 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private JobTile mTile;
|
private JobTile mTile;
|
||||||
private FileOutputStream mCacheFile;
|
private FileOutputStream mCacheFile;
|
||||||
|
|
||||||
|
private String mHost;
|
||||||
|
private int mPort;
|
||||||
private long mContentLenth;
|
private long mContentLenth;
|
||||||
private InputStream mInputStream;
|
private InputStream mInputStream;
|
||||||
|
|
||||||
@ -120,9 +126,6 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Network Error: " + tile);
|
Log.d(TAG, "Network Error: " + tile);
|
||||||
result = QueryResult.FAILED;
|
result = QueryResult.FAILED;
|
||||||
// clear connection, TODO cleanup properly
|
|
||||||
mSocket.close();
|
|
||||||
mSocket = null;
|
|
||||||
}
|
}
|
||||||
} catch (SocketException ex) {
|
} catch (SocketException ex) {
|
||||||
Log.d(TAG, "Socket exception: " + ex.getMessage());
|
Log.d(TAG, "Socket exception: " + ex.getMessage());
|
||||||
@ -140,13 +143,24 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
|
|
||||||
mLastRequest = SystemClock.elapsedRealtime();
|
mLastRequest = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
cacheFinish(tile, f, result == QueryResult.SUCCESS);
|
if (result == QueryResult.SUCCESS) {
|
||||||
|
|
||||||
|
cacheFinish(tile, f, true);
|
||||||
|
} else {
|
||||||
|
cacheFinish(tile, f, false);
|
||||||
|
if (mSocket != null) {
|
||||||
|
// clear connection, TODO cleanup properly
|
||||||
|
try {
|
||||||
|
mSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
mSocket = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File cacheDir;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMapProjection() {
|
public String getMapProjection() {
|
||||||
return null;
|
return null;
|
||||||
@ -163,7 +177,42 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpenResult open(Map<String, String> options) {
|
public OpenResult open(MapOptions options) {
|
||||||
|
if (mOpenFile)
|
||||||
|
return OpenResult.SUCCESS;
|
||||||
|
|
||||||
|
if (options == null || !options.containsKey("url"))
|
||||||
|
return new OpenResult("options missing");
|
||||||
|
|
||||||
|
URL url;
|
||||||
|
try {
|
||||||
|
url = new URL(options.get("url"));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
return new OpenResult("invalid url: " + options.get("url"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = url.getPort();
|
||||||
|
if (port < 0)
|
||||||
|
port = 80;
|
||||||
|
|
||||||
|
String host = url.getHost();
|
||||||
|
String path = url.getPath();
|
||||||
|
Log.d(TAG, "open oscim database: " + host + " " + port + " " + path);
|
||||||
|
|
||||||
|
REQUEST_GET_START = ("GET " + path).getBytes();
|
||||||
|
REQUEST_GET_END = (".osmtile HTTP/1.1\n" +
|
||||||
|
"Host: " + host + "\n" +
|
||||||
|
"Connection: Keep-Alive\n\n").getBytes();
|
||||||
|
|
||||||
|
mHost = host;
|
||||||
|
mPort = port;
|
||||||
|
//mSockAddr = new InetSocketAddress(host, port);
|
||||||
|
|
||||||
|
mRequestBuffer = new byte[1024];
|
||||||
|
System.arraycopy(REQUEST_GET_START, 0,
|
||||||
|
mRequestBuffer, 0, REQUEST_GET_START.length);
|
||||||
|
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
if (cacheDir == null) {
|
if (cacheDir == null) {
|
||||||
@ -175,6 +224,8 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mOpenFile = true;
|
||||||
|
|
||||||
return OpenResult.SUCCESS;
|
return OpenResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,9 +238,10 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
mSocket.close();
|
mSocket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} finally {
|
||||||
mSocket = null;
|
mSocket = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
cacheDir = null;
|
cacheDir = null;
|
||||||
@ -755,10 +807,8 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
||||||
private final static int RESPONSE_EXPECTED_TIMEOUT = 10000;
|
private final static int RESPONSE_EXPECTED_TIMEOUT = 10000;
|
||||||
|
|
||||||
private final static byte[] REQUEST_GET_START = ("GET " + URL).getBytes();
|
private byte[] REQUEST_GET_START;
|
||||||
private final static byte[] REQUEST_GET_END = (".osmtile HTTP/1.1\n" +
|
private byte[] REQUEST_GET_END;
|
||||||
"Host: " + SERVER_ADDR + "\n" +
|
|
||||||
"Connection: Keep-Alive\n\n").getBytes();
|
|
||||||
|
|
||||||
private byte[] mRequestBuffer;
|
private byte[] mRequestBuffer;
|
||||||
|
|
||||||
@ -821,9 +871,6 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean lwHttpSendRequest(Tile tile) throws IOException {
|
private boolean lwHttpSendRequest(Tile tile) throws IOException {
|
||||||
if (mSockAddr == null) {
|
|
||||||
mSockAddr = new InetSocketAddress(SERVER_ADDR, 80);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSocket != null && ((mMaxReq-- <= 0)
|
if (mSocket != null && ((mMaxReq-- <= 0)
|
||||||
|| (SystemClock.elapsedRealtime() - mLastRequest
|
|| (SystemClock.elapsedRealtime() - mLastRequest
|
||||||
@ -887,11 +934,8 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean lwHttpConnect() throws IOException {
|
private boolean lwHttpConnect() throws IOException {
|
||||||
if (mRequestBuffer == null) {
|
if (mSockAddr == null)
|
||||||
mRequestBuffer = new byte[1024];
|
mSockAddr = new InetSocketAddress(mHost, mPort);
|
||||||
System.arraycopy(REQUEST_GET_START, 0,
|
|
||||||
mRequestBuffer, 0, REQUEST_GET_START.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
mSocket = new Socket();
|
mSocket = new Socket();
|
||||||
mSocket.connect(mSockAddr, 30000);
|
mSocket.connect(mSockAddr, 30000);
|
||||||
|
@ -22,8 +22,8 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
@ -34,25 +34,6 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.HttpStatus;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.params.HttpClientParams;
|
|
||||||
import org.apache.http.client.protocol.RequestAddCookies;
|
|
||||||
import org.apache.http.client.protocol.RequestProxyAuthentication;
|
|
||||||
import org.apache.http.client.protocol.RequestTargetAuthentication;
|
|
||||||
import org.apache.http.client.protocol.ResponseProcessCookies;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpConnectionParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.protocol.RequestExpectContinue;
|
|
||||||
import org.apache.http.protocol.RequestUserAgent;
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
@ -60,6 +41,7 @@ import org.oscim.core.Tile;
|
|||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
import org.oscim.database.IMapDatabaseCallback;
|
||||||
import org.oscim.database.MapInfo;
|
import org.oscim.database.MapInfo;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.database.QueryResult;
|
import org.oscim.database.QueryResult;
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
@ -84,16 +66,16 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private static final boolean USE_APACHE_HTTP = false;
|
// private static final boolean USE_APACHE_HTTP = false;
|
||||||
private static final boolean USE_LW_HTTP = true;
|
// private static final boolean USE_LW_HTTP = true;
|
||||||
|
|
||||||
private static final String CACHE_DIRECTORY = "/Android/data/org.oscim.app/cache/";
|
private static final String CACHE_DIRECTORY = "/Android/data/org.oscim.app/cache/";
|
||||||
private static final String CACHE_FILE = "%d-%d-%d.tile";
|
private static final String CACHE_FILE = "%d-%d-%d.tile";
|
||||||
|
|
||||||
private static final String SERVER_ADDR = "city.informatik.uni-bremen.de";
|
// private static final String SERVER_ADDR = "city.informatik.uni-bremen.de";
|
||||||
// private static final String URL =
|
// private static final String URL =
|
||||||
// "http://city.informatik.uni-bremen.de:8020/test/%d/%d/%d.osmtile";
|
// "http://city.informatik.uni-bremen.de:8020/test/%d/%d/%d.osmtile";
|
||||||
private static final String URL = "http://city.informatik.uni-bremen.de/osmstache/test/%d/%d/%d.osmtile";
|
//private static final String URL = "http://city.informatik.uni-bremen.de/osmstache/test/%d/%d/%d.osmtile";
|
||||||
//private static final String URL = "http://city.informatik.uni-bremen.de/osmstache/gis-live/%d/%d/%d.osmtile";
|
//private static final String URL = "http://city.informatik.uni-bremen.de/osmstache/gis-live/%d/%d/%d.osmtile";
|
||||||
|
|
||||||
// private static final String URL =
|
// private static final String URL =
|
||||||
@ -107,14 +89,16 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private Tag[] curTags = new Tag[MAX_TILE_TAGS];
|
private Tag[] curTags = new Tag[MAX_TILE_TAGS];
|
||||||
private int mCurTagCnt;
|
private int mCurTagCnt;
|
||||||
|
|
||||||
private HttpClient mClient;
|
// private HttpClient mClient;
|
||||||
private HttpGet mRequest = null;
|
// private HttpGet mRequest = null;
|
||||||
|
|
||||||
private IMapDatabaseCallback mMapGenerator;
|
private IMapDatabaseCallback mMapGenerator;
|
||||||
private float mScaleFactor;
|
private float mScaleFactor;
|
||||||
private JobTile mTile;
|
private JobTile mTile;
|
||||||
private FileOutputStream mCacheFile;
|
private FileOutputStream mCacheFile;
|
||||||
|
|
||||||
|
private String mHost;
|
||||||
|
private int mPort;
|
||||||
private long mContentLenth;
|
private long mContentLenth;
|
||||||
private InputStream mInputStream;
|
private InputStream mInputStream;
|
||||||
|
|
||||||
@ -163,23 +147,23 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
return QueryResult.SUCCESS;
|
return QueryResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = null;
|
// String url = null;
|
||||||
HttpGet getRequest;
|
// HttpGet getRequest;
|
||||||
|
|
||||||
if (!USE_LW_HTTP) {
|
// if (!USE_LW_HTTP) {
|
||||||
url = String.format(URL,
|
// url = String.format(URL,
|
||||||
Integer.valueOf(tile.zoomLevel),
|
// Integer.valueOf(tile.zoomLevel),
|
||||||
Integer.valueOf(tile.tileX),
|
// Integer.valueOf(tile.tileX),
|
||||||
Integer.valueOf(tile.tileY));
|
// Integer.valueOf(tile.tileY));
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (USE_APACHE_HTTP) {
|
// if (USE_APACHE_HTTP) {
|
||||||
getRequest = new HttpGet(url);
|
// getRequest = new HttpGet(url);
|
||||||
mRequest = getRequest;
|
// mRequest = getRequest;
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (USE_LW_HTTP) {
|
// if (USE_LW_HTTP) {
|
||||||
if (lwHttpSendRequest(tile) && lwHttpReadHeader() > 0) {
|
if (lwHttpSendRequest(tile) && lwHttpReadHeader() > 0) {
|
||||||
cacheBegin(tile, f);
|
cacheBegin(tile, f);
|
||||||
decode();
|
decode();
|
||||||
@ -187,51 +171,52 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
result = QueryResult.FAILED;
|
result = QueryResult.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (USE_APACHE_HTTP) {
|
// }
|
||||||
HttpResponse response = mClient.execute(getRequest);
|
// else if (USE_APACHE_HTTP) {
|
||||||
final int statusCode = response.getStatusLine().getStatusCode();
|
// HttpResponse response = mClient.execute(getRequest);
|
||||||
final HttpEntity entity = response.getEntity();
|
// final int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
// final HttpEntity entity = response.getEntity();
|
||||||
if (statusCode != HttpStatus.SC_OK) {
|
//
|
||||||
Log.d(TAG, "Http response " + statusCode);
|
// if (statusCode != HttpStatus.SC_OK) {
|
||||||
entity.consumeContent();
|
// Log.d(TAG, "Http response " + statusCode);
|
||||||
return QueryResult.FAILED;
|
// entity.consumeContent();
|
||||||
}
|
// return QueryResult.FAILED;
|
||||||
if (!mTile.isLoading) {
|
// }
|
||||||
Log.d(TAG, "1 loading canceled " + mTile);
|
// if (!mTile.isLoading) {
|
||||||
entity.consumeContent();
|
// Log.d(TAG, "1 loading canceled " + mTile);
|
||||||
|
// entity.consumeContent();
|
||||||
return QueryResult.FAILED;
|
//
|
||||||
}
|
// return QueryResult.FAILED;
|
||||||
|
// }
|
||||||
InputStream is = null;
|
//
|
||||||
// GZIPInputStream zis = null;
|
// InputStream is = null;
|
||||||
try {
|
// // GZIPInputStream zis = null;
|
||||||
is = entity.getContent();
|
// try {
|
||||||
|
// is = entity.getContent();
|
||||||
mContentLenth = entity.getContentLength();
|
//
|
||||||
mInputStream = is;
|
// mContentLenth = entity.getContentLength();
|
||||||
cacheBegin(tile, f);
|
// mInputStream = is;
|
||||||
// zis = new GZIPInputStream(is);
|
// cacheBegin(tile, f);
|
||||||
decode();
|
// // zis = new GZIPInputStream(is);
|
||||||
} finally {
|
// decode();
|
||||||
// if (zis != null)
|
// } finally {
|
||||||
// zis.close();
|
// // if (zis != null)
|
||||||
if (is != null)
|
// // zis.close();
|
||||||
is.close();
|
// if (is != null)
|
||||||
entity.consumeContent();
|
// is.close();
|
||||||
}
|
// entity.consumeContent();
|
||||||
} else {
|
// }
|
||||||
HttpURLConnection urlConn =
|
// } else {
|
||||||
(HttpURLConnection) new URL(url).openConnection();
|
// HttpURLConnection urlConn =
|
||||||
|
// (HttpURLConnection) new URL(url).openConnection();
|
||||||
InputStream in = urlConn.getInputStream();
|
//
|
||||||
try {
|
// InputStream in = urlConn.getInputStream();
|
||||||
decode();
|
// try {
|
||||||
} finally {
|
// decode();
|
||||||
urlConn.disconnect();
|
// } finally {
|
||||||
}
|
// urlConn.disconnect();
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
} catch (SocketException ex) {
|
} catch (SocketException ex) {
|
||||||
Log.d(TAG, "Socket exception: " + ex.getMessage());
|
Log.d(TAG, "Socket exception: " + ex.getMessage());
|
||||||
result = QueryResult.FAILED;
|
result = QueryResult.FAILED;
|
||||||
@ -248,8 +233,8 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
|
|
||||||
mLastRequest = SystemClock.elapsedRealtime();
|
mLastRequest = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
if (USE_APACHE_HTTP)
|
// if (USE_APACHE_HTTP)
|
||||||
mRequest = null;
|
// mRequest = null;
|
||||||
|
|
||||||
cacheFinish(tile, f, result == QueryResult.SUCCESS);
|
cacheFinish(tile, f, result == QueryResult.SUCCESS);
|
||||||
|
|
||||||
@ -273,36 +258,73 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
return mOpenFile;
|
return mOpenFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createClient() {
|
// private void createClient() {
|
||||||
mOpenFile = true;
|
// mOpenFile = true;
|
||||||
HttpParams params = new BasicHttpParams();
|
// HttpParams params = new BasicHttpParams();
|
||||||
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
// HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
||||||
HttpConnectionParams.setTcpNoDelay(params, true);
|
// HttpConnectionParams.setTcpNoDelay(params, true);
|
||||||
HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
|
// HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
|
||||||
HttpConnectionParams.setSoTimeout(params, 60 * 1000);
|
// HttpConnectionParams.setSoTimeout(params, 60 * 1000);
|
||||||
HttpConnectionParams.setSocketBufferSize(params, 32768);
|
// HttpConnectionParams.setSocketBufferSize(params, 32768);
|
||||||
HttpClientParams.setRedirecting(params, false);
|
// HttpClientParams.setRedirecting(params, false);
|
||||||
|
//
|
||||||
DefaultHttpClient client = new DefaultHttpClient(params);
|
// DefaultHttpClient client = new DefaultHttpClient(params);
|
||||||
client.removeRequestInterceptorByClass(RequestAddCookies.class);
|
// client.removeRequestInterceptorByClass(RequestAddCookies.class);
|
||||||
client.removeResponseInterceptorByClass(ResponseProcessCookies.class);
|
// client.removeResponseInterceptorByClass(ResponseProcessCookies.class);
|
||||||
client.removeRequestInterceptorByClass(RequestUserAgent.class);
|
// client.removeRequestInterceptorByClass(RequestUserAgent.class);
|
||||||
client.removeRequestInterceptorByClass(RequestExpectContinue.class);
|
// client.removeRequestInterceptorByClass(RequestExpectContinue.class);
|
||||||
client.removeRequestInterceptorByClass(RequestTargetAuthentication.class);
|
// client.removeRequestInterceptorByClass(RequestTargetAuthentication.class);
|
||||||
client.removeRequestInterceptorByClass(RequestProxyAuthentication.class);
|
// client.removeRequestInterceptorByClass(RequestProxyAuthentication.class);
|
||||||
|
//
|
||||||
mClient = client;
|
// mClient = client;
|
||||||
|
//
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
// SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(new Scheme("http",
|
// schemeRegistry.register(new Scheme("http",
|
||||||
PlainSocketFactory.getSocketFactory(), 80));
|
// PlainSocketFactory.getSocketFactory(), 80));
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpenResult open(Map<String, String> options) {
|
public OpenResult open(MapOptions options) {
|
||||||
|
|
||||||
if (USE_APACHE_HTTP)
|
//if (USE_APACHE_HTTP)
|
||||||
createClient();
|
// createClient();
|
||||||
|
|
||||||
|
if (mOpenFile)
|
||||||
|
return OpenResult.SUCCESS;
|
||||||
|
|
||||||
|
if (options == null || !options.containsKey("url"))
|
||||||
|
return new OpenResult("options missing");
|
||||||
|
|
||||||
|
URL url;
|
||||||
|
try {
|
||||||
|
url = new URL(options.get("url"));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
return new OpenResult("invalid url: " + options.get("url"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = url.getPort();
|
||||||
|
if (port < 0)
|
||||||
|
port = 80;
|
||||||
|
|
||||||
|
String host = url.getHost();
|
||||||
|
String path = url.getPath();
|
||||||
|
Log.d(TAG, "open oscim database: " + host + " " + port + " " + path);
|
||||||
|
|
||||||
|
REQUEST_GET_START = ("GET " + path).getBytes();
|
||||||
|
REQUEST_GET_END = (".osmtile HTTP/1.1\n" +
|
||||||
|
"Host: " + host + "\n" +
|
||||||
|
"Connection: Keep-Alive\n\n").getBytes();
|
||||||
|
|
||||||
|
mHost = host;
|
||||||
|
mPort = port;
|
||||||
|
|
||||||
|
//mSockAddr = new InetSocketAddress(host, port);
|
||||||
|
|
||||||
|
mRequestBuffer = new byte[1024];
|
||||||
|
System.arraycopy(REQUEST_GET_START, 0,
|
||||||
|
mRequestBuffer, 0, REQUEST_GET_START.length);
|
||||||
|
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
if (cacheDir == null) {
|
if (cacheDir == null) {
|
||||||
@ -314,20 +336,25 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mOpenFile = true;
|
||||||
|
|
||||||
return OpenResult.SUCCESS;
|
return OpenResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
mOpenFile = false;
|
mOpenFile = false;
|
||||||
if (USE_APACHE_HTTP) {
|
// if (USE_APACHE_HTTP) {
|
||||||
if (mClient != null) {
|
// if (mClient != null) {
|
||||||
mClient.getConnectionManager().shutdown();
|
// mClient.getConnectionManager().shutdown();
|
||||||
mClient = null;
|
// mClient = null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// if (USE_LW_HTTP) {
|
||||||
|
|
||||||
|
mSockAddr = null;
|
||||||
|
|
||||||
if (USE_LW_HTTP) {
|
|
||||||
if (mSocket != null) {
|
if (mSocket != null) {
|
||||||
try {
|
try {
|
||||||
mSocket.close();
|
mSocket.close();
|
||||||
@ -336,7 +363,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
mSocket = null;
|
mSocket = null;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
cacheDir = null;
|
cacheDir = null;
|
||||||
}
|
}
|
||||||
@ -861,10 +888,10 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
if (mCacheFile != null)
|
if (mCacheFile != null)
|
||||||
mCacheFile.write(mReadBuffer, mBufferSize, len);
|
mCacheFile.write(mReadBuffer, mBufferSize, len);
|
||||||
|
|
||||||
if (USE_LW_HTTP) {
|
// if (USE_LW_HTTP) {
|
||||||
if (mReadPos == mContentLenth)
|
if (mReadPos == mContentLenth)
|
||||||
break;
|
break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
mBufferSize += len;
|
mBufferSize += len;
|
||||||
}
|
}
|
||||||
@ -874,10 +901,10 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
if (mRequest != null) {
|
// if (mRequest != null) {
|
||||||
mRequest.abort();
|
// mRequest.abort();
|
||||||
mRequest = null;
|
// mRequest = null;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private int decodeVarint32() throws IOException {
|
private int decodeVarint32() throws IOException {
|
||||||
@ -953,10 +980,11 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
||||||
private final static int RESPONSE_EXPECTED_TIMEOUT = 10000;
|
private final static int RESPONSE_EXPECTED_TIMEOUT = 10000;
|
||||||
|
|
||||||
private final static byte[] REQUEST_GET_START = "GET /osmstache/test/".getBytes();
|
private byte[] REQUEST_GET_START;// = "GET /osmstache/test/".getBytes();
|
||||||
private final static byte[] REQUEST_GET_END = (".osmtile HTTP/1.1\n" +
|
private byte[] REQUEST_GET_END;
|
||||||
"Host: " + SERVER_ADDR + "\n" +
|
// = (".osmtile HTTP/1.1\n" +
|
||||||
"Connection: Keep-Alive\n\n").getBytes();
|
//"Host: " + SERVER_ADDR + "\n" +
|
||||||
|
//"Connection: Keep-Alive\n\n").getBytes();
|
||||||
|
|
||||||
private byte[] mRequestBuffer;
|
private byte[] mRequestBuffer;
|
||||||
|
|
||||||
@ -1033,7 +1061,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
|
|
||||||
private boolean lwHttpSendRequest(Tile tile) throws IOException {
|
private boolean lwHttpSendRequest(Tile tile) throws IOException {
|
||||||
if (mSockAddr == null) {
|
if (mSockAddr == null) {
|
||||||
mSockAddr = new InetSocketAddress(SERVER_ADDR, 80);
|
mSockAddr = new InetSocketAddress(mHost, mPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSocket != null && ((mMaxReq-- <= 0)
|
if (mSocket != null && ((mMaxReq-- <= 0)
|
||||||
@ -1099,12 +1127,12 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean lwHttpConnect() throws IOException {
|
private boolean lwHttpConnect() throws IOException {
|
||||||
if (mRequestBuffer == null) {
|
// if (mRequestBuffer == null) {
|
||||||
mRequestBuffer = new byte[1024];
|
// mRequestBuffer = new byte[1024];
|
||||||
System.arraycopy(REQUEST_GET_START,
|
// System.arraycopy(REQUEST_GET_START,
|
||||||
0, mRequestBuffer, 0,
|
// 0, mRequestBuffer, 0,
|
||||||
REQUEST_GET_START.length);
|
// REQUEST_GET_START.length);
|
||||||
}
|
// }
|
||||||
|
|
||||||
mSocket = new Socket();
|
mSocket = new Socket();
|
||||||
mSocket.connect(mSockAddr, 30000);
|
mSocket.connect(mSockAddr, 30000);
|
||||||
|
@ -20,7 +20,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -31,6 +30,7 @@ import org.oscim.core.WebMercator;
|
|||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
import org.oscim.database.IMapDatabaseCallback;
|
||||||
import org.oscim.database.MapInfo;
|
import org.oscim.database.MapInfo;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.database.QueryResult;
|
import org.oscim.database.QueryResult;
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
@ -210,7 +210,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpenResult open(Map<String, String> options) {
|
public OpenResult open(MapOptions options) {
|
||||||
mOpenFile = true;
|
mOpenFile = true;
|
||||||
if (mCoords == null) {
|
if (mCoords == null) {
|
||||||
mCoords = new float[100000];
|
mCoords = new float[100000];
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.database.test;
|
package org.oscim.database.test;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
@ -22,6 +21,7 @@ import org.oscim.core.Tile;
|
|||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
import org.oscim.database.IMapDatabaseCallback;
|
||||||
import org.oscim.database.MapInfo;
|
import org.oscim.database.MapInfo;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.database.QueryResult;
|
import org.oscim.database.QueryResult;
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
@ -195,7 +195,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpenResult open(Map<String, String> options) {
|
public OpenResult open(MapOptions options) {
|
||||||
mOpenFile = true;
|
mOpenFile = true;
|
||||||
return OpenResult.SUCCESS;
|
return OpenResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class MapWorker extends PausableThread {
|
|||||||
THREAD_NAME = "MapWorker" + id;
|
THREAD_NAME = "MapWorker" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileGenerator getMapGenerator() {
|
public TileGenerator getTileGenerator() {
|
||||||
return mMapGenerator;
|
return mMapGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,6 +478,9 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
|
|||||||
private String mMapProjection;
|
private String mMapProjection;
|
||||||
|
|
||||||
public void setMapDatabase(IMapDatabase mapDatabase) {
|
public void setMapDatabase(IMapDatabase mapDatabase) {
|
||||||
|
if (mMapDatabase != null)
|
||||||
|
mMapDatabase.close();
|
||||||
|
|
||||||
mMapDatabase = mapDatabase;
|
mMapDatabase = mapDatabase;
|
||||||
mMapProjection = mMapDatabase.getMapProjection();
|
mMapProjection = mMapDatabase.getMapProjection();
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ import org.oscim.core.MapPosition;
|
|||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.database.IMapDatabase;
|
import org.oscim.database.IMapDatabase;
|
||||||
import org.oscim.database.MapDatabaseFactory;
|
import org.oscim.database.MapDatabaseFactory;
|
||||||
import org.oscim.database.MapDatabases;
|
|
||||||
import org.oscim.database.MapInfo;
|
import org.oscim.database.MapInfo;
|
||||||
|
import org.oscim.database.MapOptions;
|
||||||
import org.oscim.database.OpenResult;
|
import org.oscim.database.OpenResult;
|
||||||
import org.oscim.generator.JobQueue;
|
import org.oscim.generator.JobQueue;
|
||||||
import org.oscim.generator.JobTile;
|
import org.oscim.generator.JobTile;
|
||||||
@ -69,8 +69,6 @@ public class MapView extends RelativeLayout {
|
|||||||
public static final boolean testRegionZoom = false;
|
public static final boolean testRegionZoom = false;
|
||||||
private static final boolean debugDatabase = false;
|
private static final boolean debugDatabase = false;
|
||||||
|
|
||||||
// RegionLookup mRegionLookup;
|
|
||||||
|
|
||||||
public boolean enableRotation = false;
|
public boolean enableRotation = false;
|
||||||
public boolean enableCompass = false;
|
public boolean enableCompass = false;
|
||||||
|
|
||||||
@ -82,8 +80,7 @@ public class MapView extends RelativeLayout {
|
|||||||
private final TouchHandler mTouchEventHandler;
|
private final TouchHandler mTouchEventHandler;
|
||||||
private final Compass mCompass;
|
private final Compass mCompass;
|
||||||
|
|
||||||
private IMapDatabase mMapDatabase;
|
//private MapDatabases mMapDatabaseType;
|
||||||
private MapDatabases mMapDatabaseType;
|
|
||||||
|
|
||||||
private TileManager mTileManager;
|
private TileManager mTileManager;
|
||||||
private final OverlayManager mOverlayManager;
|
private final OverlayManager mOverlayManager;
|
||||||
@ -95,9 +92,11 @@ public class MapView extends RelativeLayout {
|
|||||||
private final MapWorker mMapWorkers[];
|
private final MapWorker mMapWorkers[];
|
||||||
private final int mNumMapWorkers = 4;
|
private final int mNumMapWorkers = 4;
|
||||||
|
|
||||||
|
private MapOptions mMapOptions;
|
||||||
|
private IMapDatabase mMapDatabase;
|
||||||
|
|
||||||
private DebugSettings debugSettings;
|
private DebugSettings debugSettings;
|
||||||
private String mRenderTheme;
|
private String mRenderTheme;
|
||||||
private Map<String, String> mMapOptions;
|
|
||||||
|
|
||||||
private boolean mClearTiles;
|
private boolean mClearTiles;
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ public class MapView extends RelativeLayout {
|
|||||||
* {@link MapActivity} .
|
* {@link MapActivity} .
|
||||||
*/
|
*/
|
||||||
public MapView(Context context) {
|
public MapView(Context context) {
|
||||||
this(context, null, MapDatabases.MAP_READER);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,13 +120,8 @@ public class MapView extends RelativeLayout {
|
|||||||
* if the context object is not an instance of
|
* if the context object is not an instance of
|
||||||
* {@link MapActivity} .
|
* {@link MapActivity} .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public MapView(Context context, AttributeSet attributeSet) {
|
public MapView(Context context, AttributeSet attributeSet) {
|
||||||
this(context, attributeSet, MapDatabaseFactory.getMapDatabase(attributeSet));
|
|
||||||
}
|
|
||||||
|
|
||||||
private MapView(Context context, AttributeSet attributeSet,
|
|
||||||
MapDatabases mapDatabaseType) {
|
|
||||||
|
|
||||||
super(context, attributeSet);
|
super(context, attributeSet);
|
||||||
|
|
||||||
if (!(context instanceof MapActivity)) {
|
if (!(context instanceof MapActivity)) {
|
||||||
@ -135,8 +129,6 @@ public class MapView extends RelativeLayout {
|
|||||||
"context is not an instance of MapActivity");
|
"context is not an instance of MapActivity");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "create MapView: " + mapDatabaseType.name());
|
|
||||||
// this.setDrawingCacheEnabled(true);
|
|
||||||
this.setWillNotDraw(true);
|
this.setWillNotDraw(true);
|
||||||
|
|
||||||
// TODO set tilesize, make this dpi dependent
|
// TODO set tilesize, make this dpi dependent
|
||||||
@ -144,12 +136,8 @@ public class MapView extends RelativeLayout {
|
|||||||
|
|
||||||
MapActivity mapActivity = (MapActivity) context;
|
MapActivity mapActivity = (MapActivity) context;
|
||||||
|
|
||||||
// mHandler = new DelayedTaskHandler();
|
|
||||||
|
|
||||||
debugSettings = new DebugSettings(false, false, false, false);
|
debugSettings = new DebugSettings(false, false, false, false);
|
||||||
|
|
||||||
mMapDatabaseType = mapDatabaseType;
|
|
||||||
|
|
||||||
mMapViewPosition = new MapViewPosition(this);
|
mMapViewPosition = new MapViewPosition(this);
|
||||||
mMapPosition = new MapPosition();
|
mMapPosition = new MapPosition();
|
||||||
|
|
||||||
@ -168,32 +156,13 @@ public class MapView extends RelativeLayout {
|
|||||||
mMapWorkers = new MapWorker[mNumMapWorkers];
|
mMapWorkers = new MapWorker[mNumMapWorkers];
|
||||||
|
|
||||||
for (int i = 0; i < mNumMapWorkers; i++) {
|
for (int i = 0; i < mNumMapWorkers; i++) {
|
||||||
IMapDatabase mapDatabase;
|
|
||||||
if (debugDatabase) {
|
|
||||||
// mapDatabase = MapDatabaseFactory
|
|
||||||
// .createMapDatabase(MapDatabases.TEST_READER);
|
|
||||||
mapDatabase = MapDatabaseFactory
|
|
||||||
.createMapDatabase(MapDatabases.MAP_READER);
|
|
||||||
// mNumMapWorkers = 1;
|
|
||||||
} else {
|
|
||||||
mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseType);
|
|
||||||
}
|
|
||||||
|
|
||||||
TileGenerator tileGenerator = new TileGenerator(this);
|
TileGenerator tileGenerator = new TileGenerator(this);
|
||||||
tileGenerator.setMapDatabase(mapDatabase);
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
mMapDatabase = mapDatabase;
|
|
||||||
|
|
||||||
mMapWorkers[i] = new MapWorker(i, mJobQueue, tileGenerator, mTileManager);
|
mMapWorkers[i] = new MapWorker(i, mJobQueue, tileGenerator, mTileManager);
|
||||||
|
mMapWorkers[i].start();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapActivity.registerMapView(this);
|
mapActivity.registerMapView(this);
|
||||||
|
|
||||||
if (!mMapDatabase.isOpen()) {
|
|
||||||
Log.d(TAG, "open database with defaults");
|
|
||||||
setMapOptions(null);
|
|
||||||
}
|
|
||||||
if (!mMapViewPosition.isValid()) {
|
if (!mMapViewPosition.isValid()) {
|
||||||
Log.d(TAG, "set default start position");
|
Log.d(TAG, "set default start position");
|
||||||
setMapCenter(getStartPosition());
|
setMapCenter(getStartPosition());
|
||||||
@ -205,17 +174,10 @@ public class MapView extends RelativeLayout {
|
|||||||
|
|
||||||
addView(mGLView, params);
|
addView(mGLView, params);
|
||||||
|
|
||||||
// if (testRegionZoom)
|
|
||||||
// mRegionLookup = new RegionLookup(this);
|
|
||||||
|
|
||||||
mMapZoomControls = new MapZoomControls(mapActivity, this);
|
mMapZoomControls = new MapZoomControls(mapActivity, this);
|
||||||
mMapZoomControls.setShowMapZoomControls(true);
|
mMapZoomControls.setShowMapZoomControls(true);
|
||||||
|
|
||||||
enableRotation = true;
|
enableRotation = true;
|
||||||
|
|
||||||
for (MapWorker worker : mMapWorkers)
|
|
||||||
worker.start();
|
|
||||||
|
|
||||||
mOverlayManager.add(new LabelingOverlay(this));
|
mOverlayManager.add(new LabelingOverlay(this));
|
||||||
//mOverlayManager.add(new GenericOverlay(this, new OverlayGrid(this)));
|
//mOverlayManager.add(new GenericOverlay(this, new OverlayGrid(this)));
|
||||||
|
|
||||||
@ -245,6 +207,10 @@ public class MapView extends RelativeLayout {
|
|||||||
// mOverlayManager.add(pathOverlay);
|
// mOverlayManager.add(pathOverlay);
|
||||||
|
|
||||||
// mMapViewPosition.animateTo(new GeoPoint(53.067221, 8.78767));
|
// mMapViewPosition.animateTo(new GeoPoint(53.067221, 8.78767));
|
||||||
|
|
||||||
|
// if (testRegionZoom)
|
||||||
|
// mRegionLookup = new RegionLookup(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
@ -252,12 +218,12 @@ public class MapView extends RelativeLayout {
|
|||||||
mGLView.requestRender();
|
mGLView.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @return the map database which is used for reading map files.
|
// * @return the map database which is used for reading map files.
|
||||||
*/
|
// */
|
||||||
public IMapDatabase getMapDatabase() {
|
// public IMapDatabase getMapDatabase() {
|
||||||
return mMapDatabase;
|
// return mMapDatabase;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current position and zoom level of this MapView.
|
* @return the current position and zoom level of this MapView.
|
||||||
@ -344,48 +310,6 @@ public class MapView extends RelativeLayout {
|
|||||||
return mMapOptions;
|
return mMapOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the map file for this MapView.
|
|
||||||
* @param mapOptions
|
|
||||||
* ...
|
|
||||||
* @return true if the map file was set correctly, false otherwise.
|
|
||||||
*/
|
|
||||||
public boolean setMapOptions(Map<String, String> mapOptions) {
|
|
||||||
OpenResult openResult = null;
|
|
||||||
|
|
||||||
boolean initialized = false;
|
|
||||||
|
|
||||||
mJobQueue.clear();
|
|
||||||
mapWorkersPause(true);
|
|
||||||
|
|
||||||
for (MapWorker mapWorker : mMapWorkers) {
|
|
||||||
|
|
||||||
TileGenerator tileGenerator = mapWorker.getMapGenerator();
|
|
||||||
IMapDatabase mapDatabase = tileGenerator.getMapDatabase();
|
|
||||||
|
|
||||||
mapDatabase.close();
|
|
||||||
openResult = mapDatabase.open(null);
|
|
||||||
|
|
||||||
if (openResult.isSuccess())
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mapWorkersProceed();
|
|
||||||
|
|
||||||
if (initialized) {
|
|
||||||
mMapOptions = mapOptions;
|
|
||||||
clearAndRedrawMap();
|
|
||||||
|
|
||||||
Log.i(TAG, "MapDatabase ready");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMapOptions = null;
|
|
||||||
Log.i(TAG, "Opening MapDatabase failed");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MapPosition getStartPosition() {
|
private MapPosition getStartPosition() {
|
||||||
if (mMapDatabase == null)
|
if (mMapDatabase == null)
|
||||||
return new MapPosition();
|
return new MapPosition();
|
||||||
@ -410,34 +334,44 @@ public class MapView extends RelativeLayout {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the MapDatabase for this MapView.
|
* Sets the MapDatabase for this MapView.
|
||||||
* @param mapDatabaseType
|
* @param options
|
||||||
* the new MapDatabase.
|
* the new MapDatabase options.
|
||||||
|
* @return ...
|
||||||
*/
|
*/
|
||||||
|
public boolean setMapDatabase(MapOptions options) {
|
||||||
public void setMapDatabase(MapDatabases mapDatabaseType) {
|
|
||||||
if (debugDatabase)
|
if (debugDatabase)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
Log.i(TAG, "setMapDatabase " + mapDatabaseType.name());
|
Log.i(TAG, "setMapDatabase " + options.db.name());
|
||||||
|
|
||||||
if (mMapDatabaseType == mapDatabaseType)
|
if (mMapOptions != null && mMapOptions.equals(options))
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
mMapDatabaseType = mapDatabaseType;
|
|
||||||
mapWorkersPause(true);
|
mapWorkersPause(true);
|
||||||
|
|
||||||
for (MapWorker mapWorker : mMapWorkers) {
|
|
||||||
TileGenerator tileGenerator = mapWorker.getMapGenerator();
|
|
||||||
|
|
||||||
tileGenerator.setMapDatabase(MapDatabaseFactory
|
|
||||||
.createMapDatabase(mapDatabaseType));
|
|
||||||
}
|
|
||||||
|
|
||||||
mJobQueue.clear();
|
mJobQueue.clear();
|
||||||
mClearTiles = true;
|
mClearTiles = true;
|
||||||
|
mMapOptions = options;
|
||||||
|
|
||||||
|
for (int i = 0; i < mNumMapWorkers; i++) {
|
||||||
|
MapWorker mapWorker = mMapWorkers[i];
|
||||||
|
|
||||||
|
IMapDatabase mapDatabase = MapDatabaseFactory
|
||||||
|
.createMapDatabase(options.db);
|
||||||
|
|
||||||
|
OpenResult result = mapDatabase.open(options);
|
||||||
|
|
||||||
|
if (result != OpenResult.SUCCESS) {
|
||||||
|
Log.d(TAG, "failed open db: " + result.getErrorMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
TileGenerator tileGenerator = mapWorker.getTileGenerator();
|
||||||
|
tileGenerator.setMapDatabase(mapDatabase);
|
||||||
|
}
|
||||||
|
|
||||||
setMapOptions(null);
|
|
||||||
mapWorkersProceed();
|
mapWorkersProceed();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRenderTheme() {
|
public String getRenderTheme() {
|
||||||
@ -556,8 +490,8 @@ public class MapView extends RelativeLayout {
|
|||||||
// restore the interrupted status
|
// restore the interrupted status
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
IMapDatabase mapDatabase = mapWorker.getMapGenerator().getMapDatabase();
|
TileGenerator tileGenerator = mapWorker.getTileGenerator();
|
||||||
mapDatabase.close();
|
tileGenerator.getMapDatabase().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user