some more refactoring:
- pass map<key,val> as settings to db open instead of mapfile - started to clean up this 'get start position' mess
This commit is contained in:
parent
ab69675d69
commit
489f07dd5d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
@ -21,12 +21,10 @@ import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
public class Compass {
|
||||
|
||||
private final SensorEventListener mListener = new SensorEventListener() {
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// if (true) Log.d(TAG,
|
||||
// "sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");
|
||||
// mValues = event.values;
|
||||
if (Math.abs(event.values[0] - mAngle) > 0.25) {
|
||||
mAngle = event.values[0];
|
||||
|
||||
@ -48,12 +46,11 @@ public class Compass {
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mSensor;
|
||||
|
||||
// private float[] mValues;
|
||||
|
||||
public Compass(MapActivity mapActivity, MapView mapView) {
|
||||
mMapView = mapView;
|
||||
mSensorManager = (SensorManager) mapActivity
|
||||
.getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
||||
}
|
||||
|
||||
|
||||
@ -48,46 +48,8 @@ public abstract class MapActivity extends Activity {
|
||||
&& sharedPreferences.contains(KEY_ZOOM_LEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal list which contains references to all running MapView objects.
|
||||
*/
|
||||
private MapView mMapView;
|
||||
|
||||
private void restoreMapView(MapView mapView) {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
|
||||
MODE_PRIVATE);
|
||||
|
||||
if (containsMapViewPosition(sharedPreferences)) {
|
||||
|
||||
if (sharedPreferences.contains(KEY_MAP_FILE)) {
|
||||
// get and set the map file
|
||||
mapView.setMapFile(sharedPreferences.getString(KEY_MAP_FILE, null));
|
||||
}
|
||||
|
||||
// get and set the map position and zoom level
|
||||
int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
|
||||
int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0);
|
||||
int zoomLevel = sharedPreferences.getInt(KEY_ZOOM_LEVEL, -1);
|
||||
|
||||
GeoPoint geoPoint = new GeoPoint(latitudeE6, longitudeE6);
|
||||
MapPosition mapPosition = new MapPosition(geoPoint, (byte) zoomLevel, 1);
|
||||
mapView.setCenterAndZoom(mapPosition);
|
||||
}
|
||||
|
||||
String theme = sharedPreferences.getString(KEY_THEME,
|
||||
InternalRenderTheme.OSMARENDER.name());
|
||||
|
||||
if (theme.startsWith("/")) {
|
||||
try {
|
||||
mapView.setRenderTheme(theme);
|
||||
} catch (FileNotFoundException e) {
|
||||
mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
||||
}
|
||||
} else {
|
||||
mapView.setRenderTheme(InternalRenderTheme.valueOf(theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -111,10 +73,10 @@ public abstract class MapActivity extends Activity {
|
||||
editor.putInt(KEY_ZOOM_LEVEL, mapPosition.zoomLevel);
|
||||
}
|
||||
|
||||
if (mMapView.getMapFile() != null) {
|
||||
// save the map file
|
||||
editor.putString(KEY_MAP_FILE, mMapView.getMapFile());
|
||||
}
|
||||
// if (mMapView.getMapFile() != null) {
|
||||
// // save the map file
|
||||
// editor.putString(KEY_MAP_FILE, mMapView.getMapFile());
|
||||
// }
|
||||
|
||||
editor.putString(KEY_THEME, mMapView.getRenderTheme());
|
||||
|
||||
@ -134,10 +96,40 @@ public abstract class MapActivity extends Activity {
|
||||
* the calling MapView.
|
||||
*/
|
||||
final void registerMapView(MapView mapView) {
|
||||
if (mMapView != null)
|
||||
return;
|
||||
|
||||
mMapView = mapView;
|
||||
restoreMapView(mapView);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
|
||||
MODE_PRIVATE);
|
||||
|
||||
if (containsMapViewPosition(sharedPreferences)) {
|
||||
//
|
||||
// if (sharedPreferences.contains(KEY_MAP_FILE)) {
|
||||
// // get and set the map file
|
||||
// mapView.setMapFile(sharedPreferences.getString(KEY_MAP_FILE, null));
|
||||
// }
|
||||
|
||||
// get and set the map position and zoom level
|
||||
int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
|
||||
int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0);
|
||||
int zoomLevel = sharedPreferences.getInt(KEY_ZOOM_LEVEL, -1);
|
||||
|
||||
GeoPoint geoPoint = new GeoPoint(latitudeE6, longitudeE6);
|
||||
MapPosition mapPosition = new MapPosition(geoPoint, (byte) zoomLevel, 1);
|
||||
|
||||
mapView.setMapCenter(mapPosition);
|
||||
}
|
||||
|
||||
String theme = sharedPreferences.getString(KEY_THEME,
|
||||
InternalRenderTheme.OSMARENDER.name());
|
||||
|
||||
if (theme.startsWith("/")) {
|
||||
try {
|
||||
mapView.setRenderTheme(theme);
|
||||
} catch (FileNotFoundException e) {
|
||||
mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
||||
}
|
||||
} else {
|
||||
mapView.setRenderTheme(InternalRenderTheme.valueOf(theme));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,11 +14,11 @@
|
||||
*/
|
||||
package org.mapsforge.android;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
@ -39,10 +39,9 @@ import org.mapsforge.android.utils.GlConfigChooser;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.MapPosition;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.MapInfo;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.content.Context;
|
||||
@ -53,16 +52,7 @@ import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* A MapView shows a map on the display of the device. It handles all user input and touch gestures to move and zoom the
|
||||
* map. This MapView also includes a scale bar and zoom controls.
|
||||
* <p>
|
||||
* This implementation supports offline map rendering as well as downloading map images (tiles) over an Internet
|
||||
* connection. The operation mode of a MapView can be set in the constructor and changed at runtime with the
|
||||
* {@link #setMapDatabase(MapDatabases)} method. Some MapView parameters depend on the selected operation mode.
|
||||
* <p>
|
||||
* In offline rendering mode a special database file is required which contains the map data. Map files can be stored in
|
||||
* any folder. The current map file is set by calling {@link #setMapFile(String)}. To retrieve the current
|
||||
* {@link MapDatabase}, use the {@link #getMapDatabase()} method.
|
||||
* <p>
|
||||
* map.
|
||||
*/
|
||||
public class MapView extends GLSurfaceView {
|
||||
|
||||
@ -74,7 +64,7 @@ public class MapView extends GLSurfaceView {
|
||||
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
|
||||
|
||||
// private static final float DEFAULT_TEXT_SCALE = 1;
|
||||
private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
|
||||
// private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
|
||||
|
||||
public final static boolean debugFrameTime = false;
|
||||
|
||||
@ -95,7 +85,7 @@ public class MapView extends GLSurfaceView {
|
||||
private MapWorker mMapWorkers[];
|
||||
private int mNumMapWorkers = 4;
|
||||
private DebugSettings debugSettings;
|
||||
private String mMapFile;
|
||||
private String mRenderTheme;
|
||||
|
||||
/**
|
||||
* @param context
|
||||
@ -178,47 +168,26 @@ public class MapView extends GLSurfaceView {
|
||||
mMapWorkers[i].start();
|
||||
}
|
||||
|
||||
setMapFile("default");
|
||||
|
||||
initMapStartPosition();
|
||||
|
||||
mapActivity.registerMapView(this);
|
||||
|
||||
// if (!setRenderTheme(DEFAULT_RENDER_THEME)) {
|
||||
// Log.d(TAG, "X could not parse theme");
|
||||
// // FIXME show init error dialog
|
||||
// }
|
||||
if (!mMapDatabase.isOpen()) {
|
||||
Log.d(TAG, "open database with defaults");
|
||||
setMapOptions(null);
|
||||
}
|
||||
if (!mMapViewPosition.isValid()) {
|
||||
Log.d(TAG, "set default start position");
|
||||
setMapCenter(getStartPosition());
|
||||
}
|
||||
|
||||
setEGLConfigChooser(new GlConfigChooser());
|
||||
setEGLContextClientVersion(2);
|
||||
|
||||
// setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
|
||||
|
||||
setRenderer(mMapRenderer);
|
||||
|
||||
if (!debugFrameTime)
|
||||
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
||||
|
||||
// mCompass.enable();
|
||||
}
|
||||
|
||||
private void initMapStartPosition() {
|
||||
GeoPoint startPoint = getStartPoint();
|
||||
if (startPoint != null) {
|
||||
mMapViewPosition.setMapCenter(startPoint);
|
||||
Log.d(TAG, "got start");
|
||||
|
||||
Byte startZoomLevel = getStartZoomLevel();
|
||||
if (startZoomLevel != null) {
|
||||
mMapViewPosition.setZoomLevel(startZoomLevel.byteValue());
|
||||
Log.d(TAG, "got zoom");
|
||||
} else
|
||||
mMapViewPosition.setZoomLevel((byte) 2);
|
||||
}
|
||||
else {
|
||||
startPoint = new GeoPoint(0, 0);
|
||||
mMapViewPosition.setMapCenter(startPoint);
|
||||
mMapViewPosition.setZoomLevel((byte) 4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,13 +211,6 @@ public class MapView extends GLSurfaceView {
|
||||
return mMapDatabase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currently used map file.
|
||||
*/
|
||||
public String getMapFile() {
|
||||
return mMapFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current position and zoom level of this MapView.
|
||||
*/
|
||||
@ -275,63 +237,37 @@ public class MapView extends GLSurfaceView {
|
||||
* Calculates all necessary tiles and adds jobs accordingly.
|
||||
*/
|
||||
public void redrawTiles() {
|
||||
if (getWidth() <= 0 || getHeight() <= 0)
|
||||
return;
|
||||
|
||||
mMapRenderer.updateMap(false);
|
||||
}
|
||||
|
||||
private void clearAndRedrawMapView() {
|
||||
if (getWidth() <= 0 || getHeight() <= 0)
|
||||
return;
|
||||
|
||||
mMapRenderer.updateMap(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the center of the MapView and triggers a redraw.
|
||||
*
|
||||
* @param geoPoint
|
||||
* the new center point of the map.
|
||||
*/
|
||||
public void setCenter(GeoPoint geoPoint) {
|
||||
MapPosition mapPosition = new MapPosition(geoPoint,
|
||||
mMapViewPosition.getZoomLevel(), 1);
|
||||
|
||||
setCenterAndZoom(mapPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param debugSettings
|
||||
* the new DebugSettings for this MapView.
|
||||
*/
|
||||
public void setDebugSettings(DebugSettings debugSettings) {
|
||||
this.debugSettings = debugSettings;
|
||||
mMapRenderer.updateMap(true);
|
||||
}
|
||||
|
||||
clearAndRedrawMapView();
|
||||
private Map<String, String> mMapOptions;
|
||||
|
||||
public Map<String, String> getMapOptions() {
|
||||
return mMapOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the map file for this MapView.
|
||||
*
|
||||
* @param mapFile
|
||||
* the path to the map file.
|
||||
* @param mapOptions
|
||||
* ...
|
||||
* @return true if the map file was set correctly, false otherwise.
|
||||
*/
|
||||
public boolean setMapFile(String mapFile) {
|
||||
FileOpenResult fileOpenResult = null;
|
||||
|
||||
Log.i(TAG, "set mapfile " + mapFile);
|
||||
|
||||
if (mapFile != null && mapFile.equals(mMapFile)) {
|
||||
// same map file as before
|
||||
return false;
|
||||
}
|
||||
public boolean setMapOptions(Map<String, String> mapOptions) {
|
||||
OpenResult openResult = null;
|
||||
|
||||
boolean initialized = false;
|
||||
|
||||
mJobQueue.clear();
|
||||
|
||||
mapWorkersPause(true);
|
||||
|
||||
for (MapWorker mapWorker : mMapWorkers) {
|
||||
@ -339,17 +275,11 @@ public class MapView extends GLSurfaceView {
|
||||
IMapGenerator mapGenerator = mapWorker.getMapGenerator();
|
||||
IMapDatabase mapDatabase = mapGenerator.getMapDatabase();
|
||||
|
||||
mapDatabase.closeFile();
|
||||
mapDatabase.close();
|
||||
openResult = mapDatabase.open(null);
|
||||
|
||||
if (mapFile != null)
|
||||
fileOpenResult = mapDatabase.openFile(new File(mapFile));
|
||||
else
|
||||
fileOpenResult = mapDatabase.openFile(null);
|
||||
|
||||
if (fileOpenResult != null && fileOpenResult.isSuccess()) {
|
||||
mMapFile = mapFile;
|
||||
|
||||
if (!initialized)
|
||||
if (openResult != null && openResult.isSuccess()) {
|
||||
mMapOptions = mapOptions;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@ -357,41 +287,37 @@ public class MapView extends GLSurfaceView {
|
||||
mapWorkersProceed();
|
||||
|
||||
if (initialized) {
|
||||
clearAndRedrawMapView();
|
||||
Log.i(TAG, "mapfile set");
|
||||
mMapRenderer.updateMap(true);
|
||||
Log.i(TAG, "MapDatabase ready");
|
||||
return true;
|
||||
}
|
||||
|
||||
mMapFile = null;
|
||||
Log.i(TAG, "loading mapfile failed");
|
||||
mMapOptions = null;
|
||||
Log.i(TAG, "Opening MapDatabase failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private GeoPoint getStartPoint() {
|
||||
if (mMapDatabase != null && mMapDatabase.hasOpenFile()) {
|
||||
MapFileInfo mapFileInfo = mMapDatabase.getMapFileInfo();
|
||||
private MapPosition getStartPosition() {
|
||||
if (mMapDatabase == null)
|
||||
return new MapPosition();
|
||||
|
||||
if (mapFileInfo.startPosition != null) {
|
||||
return mapFileInfo.startPosition;
|
||||
} else if (mapFileInfo.mapCenter != null) {
|
||||
return mapFileInfo.mapCenter;
|
||||
}
|
||||
}
|
||||
MapInfo mapInfo = mMapDatabase.getMapInfo();
|
||||
if (mapInfo == null)
|
||||
return new MapPosition();
|
||||
|
||||
return null;
|
||||
}
|
||||
GeoPoint startPos = mapInfo.startPosition;
|
||||
|
||||
private Byte getStartZoomLevel() {
|
||||
if (mMapDatabase != null && mMapDatabase.hasOpenFile()) {
|
||||
MapFileInfo mapFileInfo = mMapDatabase.getMapFileInfo();
|
||||
if (startPos == null)
|
||||
startPos = mapInfo.mapCenter;
|
||||
|
||||
if (mapFileInfo.startZoomLevel != null) {
|
||||
return mapFileInfo.startZoomLevel;
|
||||
}
|
||||
}
|
||||
if (startPos == null)
|
||||
startPos = new GeoPoint(0, 0);
|
||||
|
||||
return DEFAULT_START_ZOOM_LEVEL;
|
||||
if (mapInfo.startZoomLevel != null)
|
||||
return new MapPosition(startPos, (mapInfo.startZoomLevel).byteValue(), 1);
|
||||
|
||||
return new MapPosition(startPos, (byte) 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -425,15 +351,13 @@ public class MapView extends GLSurfaceView {
|
||||
|
||||
mJobQueue.clear();
|
||||
|
||||
String mapFile = mMapFile;
|
||||
mMapFile = null;
|
||||
setMapFile(mapFile);
|
||||
// String mapFile = mMapFile;
|
||||
// mMapFile = null;
|
||||
setMapOptions(null);
|
||||
|
||||
mapWorkersProceed();
|
||||
}
|
||||
|
||||
private String mRenderTheme;
|
||||
|
||||
public String getRenderTheme() {
|
||||
return mRenderTheme;
|
||||
}
|
||||
@ -456,8 +380,7 @@ public class MapView extends GLSurfaceView {
|
||||
if (ret) {
|
||||
mRenderTheme = internalRenderTheme.name();
|
||||
}
|
||||
|
||||
clearAndRedrawMapView();
|
||||
mMapRenderer.updateMap(true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -480,8 +403,7 @@ public class MapView extends GLSurfaceView {
|
||||
if (ret) {
|
||||
mRenderTheme = renderThemePath;
|
||||
}
|
||||
|
||||
clearAndRedrawMapView();
|
||||
mMapRenderer.updateMap(true);
|
||||
}
|
||||
|
||||
private boolean setRenderTheme(Theme theme) {
|
||||
@ -515,16 +437,51 @@ public class MapView extends GLSurfaceView {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text scale for the map rendering. Has no effect in downloading mode.
|
||||
*
|
||||
* @param textScale
|
||||
* the new text scale for the map rendering.
|
||||
*/
|
||||
// public void setTextScale(float textScale) {
|
||||
// mJobParameters = new JobParameters(mJobParameters.theme, textScale);
|
||||
// clearAndRedrawMapView();
|
||||
// }
|
||||
@Override
|
||||
protected synchronized void onSizeChanged(int width, int height,
|
||||
int oldWidth, int oldHeight) {
|
||||
|
||||
mJobQueue.clear();
|
||||
mapWorkersPause(true);
|
||||
|
||||
super.onSizeChanged(width, height, oldWidth, oldHeight);
|
||||
|
||||
mapWorkersProceed();
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
for (MapWorker mapWorker : mMapWorkers) {
|
||||
mapWorker.pause();
|
||||
mapWorker.interrupt();
|
||||
|
||||
try {
|
||||
mapWorker.join();
|
||||
} catch (InterruptedException e) {
|
||||
// restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
IMapDatabase mapDatabase = mapWorker.getMapGenerator().getMapDatabase();
|
||||
mapDatabase.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapWorkersPause(false);
|
||||
|
||||
if (this.enableCompass)
|
||||
mCompass.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapWorkersProceed();
|
||||
|
||||
if (this.enableCompass)
|
||||
mCompass.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zooms in or out by the given amount of zoom levels.
|
||||
@ -550,42 +507,11 @@ public class MapView extends GLSurfaceView {
|
||||
}
|
||||
|
||||
mMapViewPosition.setZoomLevel((byte) z);
|
||||
|
||||
redrawTiles();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void onSizeChanged(int width, int height, int oldWidth,
|
||||
int oldHeight) {
|
||||
|
||||
mJobQueue.clear();
|
||||
mCompass.disable();
|
||||
mapWorkersPause(true);
|
||||
|
||||
super.onSizeChanged(width, height, oldWidth, oldHeight);
|
||||
|
||||
mapWorkersProceed();
|
||||
mCompass.enable();
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
for (MapWorker mapWorker : mMapWorkers) {
|
||||
mapWorker.pause();
|
||||
mapWorker.interrupt();
|
||||
|
||||
try {
|
||||
mapWorker.join();
|
||||
} catch (InterruptedException e) {
|
||||
// restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
IMapDatabase mapDatabase = mapWorker.getMapGenerator().getMapDatabase();
|
||||
mapDatabase.closeFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum possible zoom level.
|
||||
*/
|
||||
@ -599,13 +525,16 @@ public class MapView extends GLSurfaceView {
|
||||
* @return true if the current center position of this MapView is valid, false otherwise.
|
||||
*/
|
||||
boolean hasValidCenter() {
|
||||
if (!mMapViewPosition.isValid()) {
|
||||
MapInfo mapInfo;
|
||||
|
||||
if (!mMapViewPosition.isValid())
|
||||
return false;
|
||||
} else if (!mMapDatabase.hasOpenFile()
|
||||
|| !mMapDatabase.getMapFileInfo().boundingBox.contains(getMapPosition()
|
||||
.getMapCenter())) {
|
||||
|
||||
if ((mapInfo = mMapDatabase.getMapInfo()) == null)
|
||||
return false;
|
||||
|
||||
if (!mapInfo.boundingBox.contains(getMapPosition().getMapCenter()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -615,38 +544,33 @@ public class MapView extends GLSurfaceView {
|
||||
mMapZoomControls.getZoomLevelMin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapWorkersPause(false);
|
||||
|
||||
if (this.enableCompass)
|
||||
mCompass.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapWorkersProceed();
|
||||
|
||||
if (this.enableCompass)
|
||||
mCompass.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the center and zoom level of this MapView and triggers a redraw.
|
||||
*
|
||||
* @param mapPosition
|
||||
* the new map position of this MapView.
|
||||
*/
|
||||
void setCenterAndZoom(MapPosition mapPosition) {
|
||||
Log.d(TAG, "setCenterAndZoom "
|
||||
public void setMapCenter(MapPosition mapPosition) {
|
||||
Log.d(TAG, "setMapCenter "
|
||||
+ " lat: " + mapPosition.lat
|
||||
+ " lon: " + mapPosition.lon);
|
||||
mMapViewPosition.setMapCenterAndZoomLevel(mapPosition);
|
||||
mMapViewPosition.setMapCenter(mapPosition);
|
||||
redrawTiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the center of the MapView and triggers a redraw.
|
||||
*
|
||||
* @param geoPoint
|
||||
* the new center point of the map.
|
||||
*/
|
||||
public void setCenter(GeoPoint geoPoint) {
|
||||
MapPosition mapPosition = new MapPosition(geoPoint,
|
||||
mMapViewPosition.getZoomLevel(), 1);
|
||||
|
||||
setMapCenter(mapPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MapPosition
|
||||
*/
|
||||
@ -696,9 +620,8 @@ public class MapView extends GLSurfaceView {
|
||||
public void enableRotation(boolean enable) {
|
||||
enableRotation = enable;
|
||||
|
||||
if (enable && this.enableCompass) {
|
||||
this.enableCompass = false;
|
||||
mCompass.disable();
|
||||
if (enable) {
|
||||
enableCompass(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,7 +632,7 @@ public class MapView extends GLSurfaceView {
|
||||
this.enableCompass = enable;
|
||||
|
||||
if (enable)
|
||||
this.enableRotation = false;
|
||||
enableRotation(false);
|
||||
|
||||
if (enable)
|
||||
mCompass.enable();
|
||||
@ -729,6 +652,17 @@ public class MapView extends GLSurfaceView {
|
||||
//
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Sets the text scale for the map rendering. Has no effect in downloading mode.
|
||||
// *
|
||||
// * @param textScale
|
||||
// * the new text scale for the map rendering.
|
||||
// */
|
||||
// public void setTextScale(float textScale) {
|
||||
// mJobParameters = new JobParameters(mJobParameters.theme, textScale);
|
||||
// clearAndRedrawMapView();
|
||||
// }
|
||||
|
||||
// public final int
|
||||
// public Handler messageHandler = new Handler() {
|
||||
//
|
||||
|
||||
@ -19,6 +19,7 @@ import org.mapsforge.core.MapPosition;
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
|
||||
import android.util.FloatMath;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A MapPosition stores the latitude and longitude coordinate of a MapView together with its zoom level.
|
||||
@ -140,6 +141,7 @@ public class MapViewPosition {
|
||||
|
||||
public synchronized void rotateMap(float angle, float cx, float cy) {
|
||||
moveMap(cx, cy);
|
||||
Log.d("MapViewPosition", "rotate:" + angle + " " + (mRotation - angle));
|
||||
mRotation -= angle;
|
||||
}
|
||||
|
||||
@ -152,7 +154,7 @@ public class MapViewPosition {
|
||||
mLongitude = MercatorProjection.limitLongitude(geoPoint.getLongitude());
|
||||
}
|
||||
|
||||
synchronized void setMapCenterAndZoomLevel(MapPosition mapPosition) {
|
||||
synchronized void setMapCenter(MapPosition mapPosition) {
|
||||
mLatitude = MercatorProjection.limitLatitude(mapPosition.lat);
|
||||
mLongitude = MercatorProjection.limitLongitude(mapPosition.lon);
|
||||
mZoomLevel = mMapView.limitZoomLevel(mapPosition.zoomLevel);
|
||||
|
||||
@ -19,6 +19,7 @@ import org.mapsforge.core.Tile;
|
||||
import android.content.Context;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
@ -41,7 +42,7 @@ public class TouchHandler {
|
||||
private boolean mRotationStart;
|
||||
private float mPosX;
|
||||
private float mPosY;
|
||||
private float mAngle;
|
||||
private double mAngle;
|
||||
|
||||
private int mActivePointerId;
|
||||
|
||||
@ -125,24 +126,27 @@ public class TouchHandler {
|
||||
double dy = y1 - y2;
|
||||
|
||||
double rad = Math.atan2(dy, dx);
|
||||
float angle = (float) Math.toDegrees(rad);
|
||||
|
||||
// focus point relative to center
|
||||
double cx = (mMapView.getWidth() >> 1) - (x1 + x2) / 2;
|
||||
double cy = (mMapView.getHeight() >> 1) - (y1 + y2) / 2;
|
||||
double r = Math.toRadians(angle - mAngle);
|
||||
double r = rad - mAngle;
|
||||
|
||||
double rsin = Math.sin(r);
|
||||
double rcos = Math.cos(r);
|
||||
|
||||
float x = (float) (cx * rcos + cy * -rsin - cx);
|
||||
float y = (float) (cx * rsin + cy * rcos - cy);
|
||||
|
||||
double x = cx * Math.cos(r) + cy * -Math.sin(r) - cx;
|
||||
double y = cx * Math.sin(r) + cy * Math.cos(r) - cy;
|
||||
// Log.d("...", "move " + x + " " + y + " " + cx + " " + cy);
|
||||
|
||||
if (!mRotationStart) {
|
||||
if (Math.abs(angle - mAngle) > 3.0)
|
||||
if (Math.abs(rad - mAngle) > 0.001)
|
||||
mRotationStart = true;
|
||||
}
|
||||
else {
|
||||
mMapPosition.rotateMap(angle - mAngle, (float) x, (float) y);
|
||||
mAngle = angle;
|
||||
mMapPosition.rotateMap((float) Math.toDegrees(rad - mAngle), x, y);
|
||||
mAngle = rad;
|
||||
mMapView.redrawTiles();
|
||||
}
|
||||
}
|
||||
@ -170,10 +174,8 @@ public class TouchHandler {
|
||||
if (multi == 1) {
|
||||
double dx = event.getX(0) - event.getX(1);
|
||||
double dy = event.getY(0) - event.getY(1);
|
||||
double rad = Math.atan2(dy, dx);
|
||||
mAngle = (float) Math.toDegrees(rad);
|
||||
mAngle = Math.atan2(dy, dx);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -326,10 +328,57 @@ public class TouchHandler {
|
||||
|
||||
private DecelerateInterpolator mBounce = new DecelerateInterpolator();
|
||||
|
||||
private boolean mZooutOut = true;
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
// mMapView.zoom((byte) 1);
|
||||
// Log.d("mapsforge", "long press");
|
||||
Log.d("mapsforge", "long press");
|
||||
|
||||
// mMapView.zoom((byte) -1);
|
||||
|
||||
mPrevScale = 0;
|
||||
|
||||
mTimer = new CountDownTimer((int) mScaleDuration, 30) {
|
||||
@Override
|
||||
public void onTick(long tick) {
|
||||
scale2(tick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
scale2(0);
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
boolean scale2(long tick) {
|
||||
|
||||
if (mPrevScale >= 1) {
|
||||
mTimer = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
float adv = (mScaleDuration - tick) / mScaleDuration;
|
||||
adv = mBounce.getInterpolation(adv);
|
||||
|
||||
float scale = adv - mPrevScale;
|
||||
mPrevScale += scale;
|
||||
|
||||
if (mZooutOut) {
|
||||
mMapPosition.scaleMap(1 - scale, 0, 0);
|
||||
}
|
||||
// } else {
|
||||
// mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
|
||||
// }
|
||||
|
||||
mMapView.redrawTiles();
|
||||
|
||||
if (tick == 0)
|
||||
mTimer = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private final float mScaleDuration = 300;
|
||||
|
||||
@ -131,6 +131,9 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void updateMap(boolean clear) {
|
||||
if (mWidth <= 0 || mHeight <= 0)
|
||||
return;
|
||||
|
||||
TileLoader.updateMap(clear);
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ public class TextRenderer {
|
||||
private final static int TEXTURE_HEIGHT = 256;
|
||||
private final static float SCALE = 8.0f;
|
||||
private final static int LBIT_MASK = 0xfffffffe;
|
||||
private final static int L2BIT_MASK = 0xfffffffc;
|
||||
// private final static int L2BIT_MASK = 0xfffffffc;
|
||||
|
||||
final static int INDICES_PER_SPRITE = 6;
|
||||
final static int VERTICES_PER_SPRITE = 4;
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.mapsforge.android.mapgenerator;
|
||||
|
||||
//import static org.mapsforge.android.mapgenerator.JobTile.LOADING;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
@ -40,6 +42,7 @@ public class JobQueue {
|
||||
// mPriorityQueue.addAll(tiles);
|
||||
for (int i = 0, n = tiles.size(); i < n; i++) {
|
||||
JobTile tile = tiles.get(i);
|
||||
// tile.state = LOADING;
|
||||
tile.isLoading = true;
|
||||
mPriorityQueue.offer(tile);
|
||||
}
|
||||
@ -51,6 +54,7 @@ public class JobQueue {
|
||||
public synchronized void clear() {
|
||||
for (int i = 0, n = mPriorityQueue.size(); i < n; i++) {
|
||||
JobTile tile = mPriorityQueue.poll();
|
||||
// tile.state = 0;
|
||||
tile.isLoading = false;
|
||||
}
|
||||
mPriorityQueue.clear();
|
||||
|
||||
@ -172,8 +172,8 @@ public class RenderTheme {
|
||||
|
||||
}
|
||||
|
||||
private int missCnt = 0;
|
||||
private int hitCnt = 0;
|
||||
// private int missCnt = 0;
|
||||
// private int hitCnt = 0;
|
||||
private MatchingCacheKey mCacheKey = new MatchingCacheKey();
|
||||
|
||||
/**
|
||||
|
||||
@ -458,10 +458,6 @@ public class MapGenerator implements IMapGenerator, IRenderCallback,
|
||||
// WayDecorator.renderText(this, paint, outline, mCoords, mWayDataContainer, mWayNames);
|
||||
}
|
||||
|
||||
String getWayName() {
|
||||
return mMapDatabase.readString(mWayDataContainer.textPos[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMapDatabase(IMapDatabase mapDatabase) {
|
||||
mMapDatabase = mapDatabase;
|
||||
|
||||
@ -189,8 +189,8 @@ final class WayDecorator {
|
||||
|
||||
if (wayNameWidth < 0) {
|
||||
if (text == null) {
|
||||
text = mapGenerator.getWayName();
|
||||
if (text == null)
|
||||
// text = mapGenerator.getWayName();
|
||||
// if (text == null)
|
||||
text = "blub";
|
||||
}
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ package org.mapsforge.app;
|
||||
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mapsforge.android.DebugSettings;
|
||||
import org.mapsforge.android.MapActivity;
|
||||
@ -16,9 +14,8 @@ import org.mapsforge.app.filefilter.ValidMapFile;
|
||||
import org.mapsforge.app.filefilter.ValidRenderTheme;
|
||||
import org.mapsforge.app.filepicker.FilePicker;
|
||||
import org.mapsforge.app.preferences.EditPreferences;
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.core.MapPosition;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActionBar;
|
||||
@ -56,7 +53,7 @@ import android.widget.Toast;
|
||||
*/
|
||||
public class TileMap extends MapActivity {
|
||||
// implements ActionBar.OnNavigationListener {
|
||||
private static final String BUNDLE_CENTER_AT_FIRST_FIX = "centerAtFirstFix";
|
||||
// private static final String BUNDLE_CENTER_AT_FIRST_FIX = "centerAtFirstFix";
|
||||
private static final String BUNDLE_SHOW_MY_LOCATION = "showMyLocation";
|
||||
private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation";
|
||||
private static final int DIALOG_ENTER_COORDINATES = 0;
|
||||
@ -156,7 +153,7 @@ public class TileMap extends MapActivity {
|
||||
mLocation.disableSnapToLocation(true);
|
||||
|
||||
mMapView.setCenter(mMapView.getMapDatabase()
|
||||
.getMapFileInfo().mapCenter);
|
||||
.getMapInfo().mapCenter);
|
||||
return true;
|
||||
|
||||
case R.id.menu_preferences:
|
||||
@ -282,21 +279,22 @@ public class TileMap extends MapActivity {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == SELECT_MAP_FILE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
|
||||
mLocation.disableSnapToLocation(true);
|
||||
|
||||
if (intent != null) {
|
||||
if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
||||
mMapView.setMapFile(intent
|
||||
.getStringExtra(FilePicker.SELECTED_FILE));
|
||||
}
|
||||
}
|
||||
} else if (resultCode == RESULT_CANCELED) {
|
||||
startActivity(new Intent(this, EditPreferences.class));
|
||||
}
|
||||
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
|
||||
// if (requestCode == SELECT_MAP_FILE) {
|
||||
// if (resultCode == RESULT_OK) {
|
||||
//
|
||||
// mLocation.disableSnapToLocation(true);
|
||||
//
|
||||
// if (intent != null) {
|
||||
// if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
||||
// mMapView.setMapFile(intent
|
||||
// .getStringExtra(FilePicker.SELECTED_FILE));
|
||||
// }
|
||||
// }
|
||||
// } else if (resultCode == RESULT_CANCELED) {
|
||||
// startActivity(new Intent(this, EditPreferences.class));
|
||||
// }
|
||||
// } else
|
||||
if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
|
||||
&& intent != null
|
||||
&& intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
||||
try {
|
||||
@ -380,14 +378,16 @@ public class TileMap extends MapActivity {
|
||||
.toString());
|
||||
double longitude = Double.parseDouble(longitudeView.getText()
|
||||
.toString());
|
||||
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
||||
TileMap.this.mMapView.setCenter(geoPoint);
|
||||
|
||||
SeekBar zoomLevelView = (SeekBar) view
|
||||
.findViewById(R.id.zoomLevel);
|
||||
|
||||
TileMap.this.mMapView.zoom((byte) (zoomLevelView
|
||||
.getProgress() - mMapView.getMapPosition()
|
||||
.getZoomLevel()));
|
||||
byte zoom = (byte) (zoomLevelView.getProgress());
|
||||
|
||||
MapPosition mapPosition = new MapPosition(latitude,
|
||||
longitude, zoom, 1, 0);
|
||||
|
||||
TileMap.this.mMapView.setMapCenter(mapPosition);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
@ -443,62 +443,62 @@ public class TileMap extends MapActivity {
|
||||
final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue);
|
||||
textView.setText(String.valueOf(zoomlevel.getProgress()));
|
||||
zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView));
|
||||
} else if (id == DIALOG_INFO_MAP_FILE) {
|
||||
MapFileInfo mapFileInfo = mMapView.getMapDatabase().getMapFileInfo();
|
||||
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
|
||||
textView.setText(mMapView.getMapFile());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
|
||||
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize,
|
||||
getResources()));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
|
||||
textView.setText(String.valueOf(mapFileInfo.fileVersion));
|
||||
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
|
||||
// if (mapFileInfo.debugFile) {
|
||||
// textView.setText(R.string.info_map_file_debug_yes);
|
||||
// } else if (id == DIALOG_INFO_MAP_FILE) {
|
||||
// MapInfo mapInfo = mMapView.getMapDatabase().getMapInfo();
|
||||
//
|
||||
// TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
|
||||
// textView.setText(mMapView.getMapFile());
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
|
||||
// textView.setText(FileUtils.formatFileSize(mapInfo.fileSize,
|
||||
// getResources()));
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
|
||||
// textView.setText(String.valueOf(mapInfo.fileVersion));
|
||||
//
|
||||
// // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
|
||||
// // if (mapFileInfo.debugFile) {
|
||||
// // textView.setText(R.string.info_map_file_debug_yes);
|
||||
// // } else {
|
||||
// // textView.setText(R.string.info_map_file_debug_no);
|
||||
// // }
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate);
|
||||
// Date date = new Date(mapInfo.mapDate);
|
||||
// textView.setText(DateFormat.getDateTimeInstance().format(date));
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
|
||||
// BoundingBox boundingBox = mapInfo.boundingBox;
|
||||
// textView.setText(boundingBox.getMinLatitude() + ", "
|
||||
// + boundingBox.getMinLongitude() + " - \n"
|
||||
// + boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
|
||||
// GeoPoint startPosition = mapInfo.startPosition;
|
||||
// if (startPosition == null) {
|
||||
// textView.setText(null);
|
||||
// } else {
|
||||
// textView.setText(R.string.info_map_file_debug_no);
|
||||
// textView.setText(startPosition.getLatitude() + ", "
|
||||
// + startPosition.getLongitude());
|
||||
// }
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate);
|
||||
Date date = new Date(mapFileInfo.mapDate);
|
||||
textView.setText(DateFormat.getDateTimeInstance().format(date));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
|
||||
BoundingBox boundingBox = mapFileInfo.boundingBox;
|
||||
textView.setText(boundingBox.getMinLatitude() + ", "
|
||||
+ boundingBox.getMinLongitude() + " - \n"
|
||||
+ boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
|
||||
GeoPoint startPosition = mapFileInfo.startPosition;
|
||||
if (startPosition == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startPosition.getLatitude() + ", "
|
||||
+ startPosition.getLongitude());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
|
||||
Byte startZoomLevel = mapFileInfo.startZoomLevel;
|
||||
if (startZoomLevel == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startZoomLevel.toString());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog
|
||||
.findViewById(R.id.infoMapFileViewLanguagePreference);
|
||||
textView.setText(mapFileInfo.languagePreference);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
|
||||
textView.setText(mapFileInfo.comment);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
|
||||
textView.setText(mapFileInfo.createdBy);
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
|
||||
// Byte startZoomLevel = mapInfo.startZoomLevel;
|
||||
// if (startZoomLevel == null) {
|
||||
// textView.setText(null);
|
||||
// } else {
|
||||
// textView.setText(startZoomLevel.toString());
|
||||
// }
|
||||
//
|
||||
// textView = (TextView) dialog
|
||||
// .findViewById(R.id.infoMapFileViewLanguagePreference);
|
||||
// textView.setText(mapInfo.languagePreference);
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
|
||||
// textView.setText(mapInfo.comment);
|
||||
//
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
|
||||
// textView.setText(mapInfo.createdBy);
|
||||
} else {
|
||||
super.onPrepareDialog(id, dialog);
|
||||
}
|
||||
@ -595,12 +595,12 @@ public class TileMap extends MapActivity {
|
||||
|
||||
mMapView.setDebugSettings(debugSettings);
|
||||
|
||||
if (mMapDatabase == MapDatabases.MAP_READER) {
|
||||
if (mMapView.getMapFile() == null)
|
||||
startMapFilePicker();
|
||||
} else {
|
||||
mMapView.setMapFile(mMapView.getMapFile());
|
||||
}
|
||||
// if (mMapDatabase == MapDatabases.MAP_READER) {
|
||||
// if (mMapView.getMapFile() == null)
|
||||
// startMapFilePicker();
|
||||
// } else {
|
||||
// mMapView.setMapFile(mMapView.getMapFile());
|
||||
// }
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
VersionHelper.refreshActionBarMenu(this);
|
||||
|
||||
@ -16,7 +16,7 @@ package org.mapsforge.app.filefilter;
|
||||
|
||||
import java.io.FileFilter;
|
||||
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
|
||||
/**
|
||||
* An extension of the {@link FileFilter} interface.
|
||||
@ -25,5 +25,5 @@ public interface ValidFileFilter extends FileFilter {
|
||||
/**
|
||||
* @return the result of the last {@link #accept} call (might be null).
|
||||
*/
|
||||
FileOpenResult getFileOpenResult();
|
||||
OpenResult getFileOpenResult();
|
||||
}
|
||||
|
||||
@ -15,27 +15,32 @@
|
||||
package org.mapsforge.app.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
/**
|
||||
* Accepts all valid map files.
|
||||
*/
|
||||
public final class ValidMapFile implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
private OpenResult openResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
IMapDatabase mapDatabase = new MapDatabase();
|
||||
this.fileOpenResult = mapDatabase.openFile(file);
|
||||
mapDatabase.closeFile();
|
||||
return this.fileOpenResult.isSuccess();
|
||||
HashMap<String, String> options = new HashMap<String, String>();
|
||||
options.put("mapfile", file.getAbsolutePath());
|
||||
|
||||
this.openResult = mapDatabase.open(options);
|
||||
|
||||
mapDatabase.close();
|
||||
return this.openResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
public OpenResult getFileOpenResult() {
|
||||
return this.openResult;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.mapsforge.android.rendertheme.RenderThemeHandler;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
@ -32,7 +32,7 @@ import org.xml.sax.XMLReader;
|
||||
* Accepts all valid render theme XML files.
|
||||
*/
|
||||
public final class ValidRenderTheme implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
private OpenResult openResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
@ -44,28 +44,28 @@ public final class ValidRenderTheme implements ValidFileFilter {
|
||||
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
|
||||
xmlReader.setContentHandler(renderThemeHandler);
|
||||
xmlReader.parse(new InputSource(inputStream));
|
||||
this.fileOpenResult = FileOpenResult.SUCCESS;
|
||||
this.openResult = OpenResult.SUCCESS;
|
||||
} catch (ParserConfigurationException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
this.openResult = new OpenResult(e.getMessage());
|
||||
} catch (SAXException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
this.openResult = new OpenResult(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
this.openResult = new OpenResult(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
this.openResult = new OpenResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return this.fileOpenResult.isSuccess();
|
||||
return this.openResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
public OpenResult getFileOpenResult() {
|
||||
return this.openResult;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,16 @@ public class MapPosition {
|
||||
public final double x;
|
||||
public final double y;
|
||||
|
||||
public MapPosition() {
|
||||
this.zoomLevel = (byte) 1;
|
||||
this.scale = 1;
|
||||
this.lat = 0;
|
||||
this.lon = 0;
|
||||
this.angle = 0;
|
||||
this.x = MercatorProjection.longitudeToPixelX(this.lon, zoomLevel);
|
||||
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param geoPoint
|
||||
* the map position.
|
||||
@ -49,7 +59,6 @@ public class MapPosition {
|
||||
* @param scale
|
||||
* ...
|
||||
*/
|
||||
|
||||
public MapPosition(GeoPoint geoPoint, byte zoomLevel, float scale) {
|
||||
// this.geoPoint = geoPoint;
|
||||
this.zoomLevel = zoomLevel;
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
*/
|
||||
package org.mapsforge.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
|
||||
@ -24,11 +24,6 @@ import org.mapsforge.android.mapgenerator.JobTile;
|
||||
*/
|
||||
public interface IMapDatabase {
|
||||
|
||||
/**
|
||||
* Closes the map file and destroys all internal caches. Has no effect if no map file is currently opened.
|
||||
*/
|
||||
public abstract void closeFile();
|
||||
|
||||
/**
|
||||
* Starts a database query with the given parameters.
|
||||
*
|
||||
@ -46,33 +41,32 @@ public interface IMapDatabase {
|
||||
* @throws IllegalStateException
|
||||
* if no map is currently opened.
|
||||
*/
|
||||
public abstract MapFileInfo getMapFileInfo();
|
||||
public abstract MapInfo getMapInfo();
|
||||
|
||||
/**
|
||||
* @return true if a map file is currently opened, false otherwise.
|
||||
* @return true if a map database is currently opened, false otherwise.
|
||||
*/
|
||||
public abstract boolean hasOpenFile();
|
||||
public abstract boolean isOpen();
|
||||
|
||||
/**
|
||||
* Opens the given map file, reads its header data and validates them.
|
||||
* Opens MapDatabase
|
||||
*
|
||||
* @param mapFile
|
||||
* the map file.
|
||||
* @return a FileOpenResult containing an error message in case of a failure.
|
||||
* @throws IllegalArgumentException
|
||||
* if the given map file is null.
|
||||
* @param options
|
||||
* the options.
|
||||
* @return a OpenResult containing an error message in case of a failure.
|
||||
*/
|
||||
public abstract FileOpenResult openFile(File mapFile);
|
||||
public abstract OpenResult open(Map<String, String> options);
|
||||
|
||||
/**
|
||||
* 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 String getMapProjection();
|
||||
|
||||
/**
|
||||
* @param position
|
||||
* ....
|
||||
* @return ...
|
||||
* Cancel loading
|
||||
*/
|
||||
public abstract String readString(int position);
|
||||
|
||||
public abstract void cancel();
|
||||
|
||||
}
|
||||
|
||||
@ -21,9 +21,9 @@ import org.mapsforge.database.mapfile.MapDatabase;
|
||||
/**
|
||||
* Contains the immutable metadata of a map file.
|
||||
*
|
||||
* @see MapDatabase#getMapFileInfo()
|
||||
* @see MapDatabase#getMapInfo()
|
||||
*/
|
||||
public class MapFileInfo {
|
||||
public class MapInfo {
|
||||
/**
|
||||
* The bounding box of the map file.
|
||||
*/
|
||||
@ -101,7 +101,7 @@ public class MapFileInfo {
|
||||
* @param createdBy
|
||||
* ...
|
||||
*/
|
||||
public MapFileInfo(BoundingBox bbox, Byte zoom, GeoPoint start, String projection,
|
||||
public MapInfo(BoundingBox bbox, Byte zoom, GeoPoint start, String projection,
|
||||
long date, long size, int version, String language, String comment, String createdBy) {
|
||||
|
||||
this.startZoomLevel = zoom;
|
||||
@ -18,11 +18,11 @@ package org.mapsforge.database;
|
||||
/**
|
||||
* A FileOpenResult is a simple DTO which is returned by IMapDatabase#openFile(File).
|
||||
*/
|
||||
public class FileOpenResult {
|
||||
public class OpenResult {
|
||||
/**
|
||||
* Singleton for a FileOpenResult instance with {@code success=true}.
|
||||
*/
|
||||
public static final FileOpenResult SUCCESS = new FileOpenResult();
|
||||
public static final OpenResult SUCCESS = new OpenResult();
|
||||
|
||||
private final String errorMessage;
|
||||
private final boolean success;
|
||||
@ -31,7 +31,7 @@ public class FileOpenResult {
|
||||
* @param errorMessage
|
||||
* a textual message describing the error, must not be null.
|
||||
*/
|
||||
public FileOpenResult(String errorMessage) {
|
||||
public OpenResult(String errorMessage) {
|
||||
if (errorMessage == null) {
|
||||
throw new IllegalArgumentException("error message must not be null");
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class FileOpenResult {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FileOpenResult() {
|
||||
public OpenResult() {
|
||||
this.success = true;
|
||||
this.errorMessage = null;
|
||||
}
|
||||
@ -17,15 +17,16 @@ package org.mapsforge.database.mapfile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.QueryResult;
|
||||
import org.mapsforge.database.mapfile.header.MapFileHeader;
|
||||
import org.mapsforge.database.mapfile.header.MapFileInfo;
|
||||
@ -242,7 +243,7 @@ public class MapDatabase implements IMapDatabase {
|
||||
* @see org.mapsforge.map.reader.IMapDatabase#getMapFileInfo()
|
||||
*/
|
||||
@Override
|
||||
public MapFileInfo getMapFileInfo() {
|
||||
public MapFileInfo getMapInfo() {
|
||||
if (sMapFileHeader == null) {
|
||||
throw new IllegalStateException("no map file is currently opened");
|
||||
}
|
||||
@ -259,7 +260,7 @@ public class MapDatabase implements IMapDatabase {
|
||||
* @see org.mapsforge.map.reader.IMapDatabase#hasOpenFile()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasOpenFile() {
|
||||
public boolean isOpen() {
|
||||
return mInputFile != null;
|
||||
}
|
||||
|
||||
@ -268,54 +269,56 @@ public class MapDatabase implements IMapDatabase {
|
||||
* @see org.mapsforge.map.reader.IMapDatabase#openFile(java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public FileOpenResult openFile(File mapFile) {
|
||||
public OpenResult open(Map<String, String> options) {
|
||||
|
||||
try {
|
||||
if (mapFile == null) {
|
||||
if (options == null || options.get("mapfile") == null) {
|
||||
// throw new IllegalArgumentException("mapFile must not be null");
|
||||
return new FileOpenResult("no file!");
|
||||
return new OpenResult("no file!");
|
||||
}
|
||||
|
||||
// make sure to close any previously opened file first
|
||||
closeFile();
|
||||
close();
|
||||
|
||||
File file = new File(options.get("mapfile"));
|
||||
|
||||
// check if the file exists and is readable
|
||||
if (!mapFile.exists()) {
|
||||
return new FileOpenResult("file does not exist: " + mapFile);
|
||||
} else if (!mapFile.isFile()) {
|
||||
return new FileOpenResult("not a file: " + mapFile);
|
||||
} else if (!mapFile.canRead()) {
|
||||
return new FileOpenResult("cannot read file: " + mapFile);
|
||||
if (!file.exists()) {
|
||||
return new OpenResult("file does not exist: " + file);
|
||||
} else if (!file.isFile()) {
|
||||
return new OpenResult("not a file: " + file);
|
||||
} else if (!file.canRead()) {
|
||||
return new OpenResult("cannot read file: " + file);
|
||||
}
|
||||
|
||||
// open the file in read only mode
|
||||
mInputFile = new RandomAccessFile(mapFile, READ_ONLY_MODE);
|
||||
mInputFile = new RandomAccessFile(file, READ_ONLY_MODE);
|
||||
mFileSize = mInputFile.length();
|
||||
mReadBuffer = new ReadBuffer(mInputFile);
|
||||
|
||||
if (instances > 0) {
|
||||
instances++;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
sMapFileHeader = new MapFileHeader();
|
||||
FileOpenResult fileOpenResult = sMapFileHeader.readHeader(mReadBuffer,
|
||||
OpenResult openResult = sMapFileHeader.readHeader(mReadBuffer,
|
||||
mFileSize);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
closeFile();
|
||||
return fileOpenResult;
|
||||
if (!openResult.isSuccess()) {
|
||||
close();
|
||||
return openResult;
|
||||
}
|
||||
|
||||
prepareExecution();
|
||||
|
||||
instances++;
|
||||
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, null, e);
|
||||
// make sure that the file is closed
|
||||
closeFile();
|
||||
return new FileOpenResult(e.getMessage());
|
||||
close();
|
||||
return new OpenResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,7 +327,7 @@ public class MapDatabase implements IMapDatabase {
|
||||
* @see org.mapsforge.map.reader.IMapDatabase#closeFile()
|
||||
*/
|
||||
@Override
|
||||
public void closeFile() {
|
||||
public void close() {
|
||||
instances--;
|
||||
if (instances > 0) {
|
||||
mReadBuffer = null;
|
||||
@ -627,7 +630,8 @@ public class MapDatabase implements IMapDatabase {
|
||||
// check if the POI has a house number
|
||||
if ((featureByte & POI_FEATURE_HOUSE_NUMBER) != 0) {
|
||||
// mReadBuffer.getPositionAndSkip();
|
||||
String str = mReadBuffer.readUTF8EncodedString();
|
||||
// String str =
|
||||
mReadBuffer.readUTF8EncodedString();
|
||||
}
|
||||
|
||||
// check if the POI has an elevation
|
||||
@ -772,15 +776,6 @@ public class MapDatabase implements IMapDatabase {
|
||||
|
||||
private int stringOffset = -1;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.mapsforge.map.reader.IMapDatabase#readString(int)
|
||||
*/
|
||||
@Override
|
||||
public String readString(int position) {
|
||||
return mReadBuffer.readUTF8EncodedStringAt(stringOffset + position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the given number of ways.
|
||||
*
|
||||
|
||||
@ -16,7 +16,7 @@ package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
/**
|
||||
@ -89,79 +89,79 @@ public class MapFileHeader {
|
||||
* @throws IOException
|
||||
* if an error occurs while reading the file.
|
||||
*/
|
||||
public FileOpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException {
|
||||
FileOpenResult fileOpenResult = RequiredFields.readMagicByte(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
public OpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException {
|
||||
OpenResult openResult = RequiredFields.readMagicByte(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readRemainingHeader(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readRemainingHeader(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder();
|
||||
|
||||
fileOpenResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
this.mapFileInfo = mapFileInfoBuilder.build();
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private FileOpenResult readSubFileParameters(ReadBuffer readBuffer, long fileSize,
|
||||
private OpenResult readSubFileParameters(ReadBuffer readBuffer, long fileSize,
|
||||
MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the number of sub-files (1 byte)
|
||||
byte numberOfSubFiles = readBuffer.readByte();
|
||||
if (numberOfSubFiles < 1) {
|
||||
return new FileOpenResult("invalid number of sub-files: " + numberOfSubFiles);
|
||||
return new OpenResult("invalid number of sub-files: " + numberOfSubFiles);
|
||||
}
|
||||
mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;
|
||||
|
||||
@ -176,33 +176,33 @@ public class MapFileHeader {
|
||||
// get and check the base zoom level (1 byte)
|
||||
byte baseZoomLevel = readBuffer.readByte();
|
||||
if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX) {
|
||||
return new FileOpenResult("invalid base zooom level: " + baseZoomLevel);
|
||||
return new OpenResult("invalid base zooom level: " + baseZoomLevel);
|
||||
}
|
||||
subFileParameterBuilder.baseZoomLevel = baseZoomLevel;
|
||||
|
||||
// get and check the minimum zoom level (1 byte)
|
||||
byte zoomLevelMin = readBuffer.readByte();
|
||||
if (zoomLevelMin < 0 || zoomLevelMin > 22) {
|
||||
return new FileOpenResult("invalid minimum zoom level: " + zoomLevelMin);
|
||||
return new OpenResult("invalid minimum zoom level: " + zoomLevelMin);
|
||||
}
|
||||
subFileParameterBuilder.zoomLevelMin = zoomLevelMin;
|
||||
|
||||
// get and check the maximum zoom level (1 byte)
|
||||
byte zoomLevelMax = readBuffer.readByte();
|
||||
if (zoomLevelMax < 0 || zoomLevelMax > 22) {
|
||||
return new FileOpenResult("invalid maximum zoom level: " + zoomLevelMax);
|
||||
return new OpenResult("invalid maximum zoom level: " + zoomLevelMax);
|
||||
}
|
||||
subFileParameterBuilder.zoomLevelMax = zoomLevelMax;
|
||||
|
||||
// check for valid zoom level range
|
||||
if (zoomLevelMin > zoomLevelMax) {
|
||||
return new FileOpenResult("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax);
|
||||
return new OpenResult("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax);
|
||||
}
|
||||
|
||||
// get and check the start address of the sub-file (8 bytes)
|
||||
long startAddress = readBuffer.readLong();
|
||||
if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) {
|
||||
return new FileOpenResult("invalid start address: " + startAddress);
|
||||
return new OpenResult("invalid start address: " + startAddress);
|
||||
}
|
||||
subFileParameterBuilder.startAddress = startAddress;
|
||||
|
||||
@ -216,7 +216,7 @@ public class MapFileHeader {
|
||||
// get and check the size of the sub-file (8 bytes)
|
||||
long subFileSize = readBuffer.readLong();
|
||||
if (subFileSize < 1) {
|
||||
return new FileOpenResult("invalid sub-file size: " + subFileSize);
|
||||
return new OpenResult("invalid sub-file size: " + subFileSize);
|
||||
}
|
||||
subFileParameterBuilder.subFileSize = subFileSize;
|
||||
|
||||
@ -236,7 +236,7 @@ public class MapFileHeader {
|
||||
this.subFileParameters[zoomLevel] = subFileParameter;
|
||||
}
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private void updateZoomLevelInformation(SubFileParameter subFileParameter) {
|
||||
|
||||
@ -20,9 +20,9 @@ import org.mapsforge.database.mapfile.MapDatabase;
|
||||
/**
|
||||
* Contains the immutable metadata of a map file.
|
||||
*
|
||||
* @see MapDatabase#getMapFileInfo()
|
||||
* @see MapDatabase#getMapInfo()
|
||||
*/
|
||||
public class MapFileInfo extends org.mapsforge.database.MapFileInfo {
|
||||
public class MapFileInfo extends org.mapsforge.database.MapInfo {
|
||||
|
||||
/**
|
||||
* True if the map file includes debug information, false otherwise.
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
final class OptionalFields {
|
||||
@ -59,15 +59,15 @@ final class OptionalFields {
|
||||
*/
|
||||
private static final int START_ZOOM_LEVEL_MAX = 22;
|
||||
|
||||
static FileOpenResult readOptionalFields(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readOptionalFields(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
OptionalFields optionalFields = new OptionalFields(readBuffer.readByte());
|
||||
mapFileInfoBuilder.optionalFields = optionalFields;
|
||||
|
||||
FileOpenResult fileOpenResult = optionalFields.readOptionalFields(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
OpenResult openResult = optionalFields.readOptionalFields(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
String comment;
|
||||
@ -91,63 +91,63 @@ final class OptionalFields {
|
||||
this.hasCreatedBy = (flags & HEADER_BITMASK_CREATED_BY) != 0;
|
||||
}
|
||||
|
||||
private FileOpenResult readLanguagePreference(ReadBuffer readBuffer) {
|
||||
private OpenResult readLanguagePreference(ReadBuffer readBuffer) {
|
||||
if (this.hasLanguagePreference) {
|
||||
String countryCode = readBuffer.readUTF8EncodedString();
|
||||
if (countryCode.length() != LANGUAGE_PREFERENCE_LENGTH) {
|
||||
return new FileOpenResult("invalid language preference: " + countryCode);
|
||||
return new OpenResult("invalid language preference: " + countryCode);
|
||||
}
|
||||
this.languagePreference = countryCode;
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private FileOpenResult readMapStartPosition(ReadBuffer readBuffer) {
|
||||
private OpenResult readMapStartPosition(ReadBuffer readBuffer) {
|
||||
if (this.hasStartPosition) {
|
||||
// get and check the start position latitude (4 byte)
|
||||
int mapStartLatitude = readBuffer.readInt();
|
||||
if (mapStartLatitude < RequiredFields.LATITUDE_MIN || mapStartLatitude > RequiredFields.LATITUDE_MAX) {
|
||||
return new FileOpenResult("invalid map start latitude: " + mapStartLatitude);
|
||||
return new OpenResult("invalid map start latitude: " + mapStartLatitude);
|
||||
}
|
||||
|
||||
// get and check the start position longitude (4 byte)
|
||||
int mapStartLongitude = readBuffer.readInt();
|
||||
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN || mapStartLongitude > RequiredFields.LONGITUDE_MAX) {
|
||||
return new FileOpenResult("invalid map start longitude: " + mapStartLongitude);
|
||||
return new OpenResult("invalid map start longitude: " + mapStartLongitude);
|
||||
}
|
||||
|
||||
this.startPosition = new GeoPoint(mapStartLatitude, mapStartLongitude);
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private FileOpenResult readMapStartZoomLevel(ReadBuffer readBuffer) {
|
||||
private OpenResult readMapStartZoomLevel(ReadBuffer readBuffer) {
|
||||
if (this.hasStartZoomLevel) {
|
||||
// get and check the start zoom level (1 byte)
|
||||
byte mapStartZoomLevel = readBuffer.readByte();
|
||||
if (mapStartZoomLevel < 0 || mapStartZoomLevel > START_ZOOM_LEVEL_MAX) {
|
||||
return new FileOpenResult("invalid map start zoom level: " + mapStartZoomLevel);
|
||||
return new OpenResult("invalid map start zoom level: " + mapStartZoomLevel);
|
||||
}
|
||||
|
||||
this.startZoomLevel = Byte.valueOf(mapStartZoomLevel);
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private FileOpenResult readOptionalFields(ReadBuffer readBuffer) {
|
||||
FileOpenResult fileOpenResult = readMapStartPosition(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
private OpenResult readOptionalFields(ReadBuffer readBuffer) {
|
||||
OpenResult openResult = readMapStartPosition(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = readMapStartZoomLevel(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = readMapStartZoomLevel(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
fileOpenResult = readLanguagePreference(readBuffer);
|
||||
if (!fileOpenResult.isSuccess()) {
|
||||
return fileOpenResult;
|
||||
openResult = readLanguagePreference(readBuffer);
|
||||
if (!openResult.isSuccess()) {
|
||||
return openResult;
|
||||
}
|
||||
|
||||
if (this.hasComment) {
|
||||
@ -158,6 +158,6 @@ final class OptionalFields {
|
||||
this.createdBy = readBuffer.readUTF8EncodedString();
|
||||
}
|
||||
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
final class RequiredFields {
|
||||
@ -72,93 +72,93 @@ final class RequiredFields {
|
||||
*/
|
||||
static final int LONGITUDE_MIN = -180000000;
|
||||
|
||||
static FileOpenResult readBoundingBox(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readBoundingBox(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the minimum latitude (4 bytes)
|
||||
int minLatitude = readBuffer.readInt();
|
||||
if (minLatitude < LATITUDE_MIN || minLatitude > LATITUDE_MAX) {
|
||||
return new FileOpenResult("invalid minimum latitude: " + minLatitude);
|
||||
return new OpenResult("invalid minimum latitude: " + minLatitude);
|
||||
}
|
||||
|
||||
// get and check the minimum longitude (4 bytes)
|
||||
int minLongitude = readBuffer.readInt();
|
||||
if (minLongitude < LONGITUDE_MIN || minLongitude > LONGITUDE_MAX) {
|
||||
return new FileOpenResult("invalid minimum longitude: " + minLongitude);
|
||||
return new OpenResult("invalid minimum longitude: " + minLongitude);
|
||||
}
|
||||
|
||||
// get and check the maximum latitude (4 bytes)
|
||||
int maxLatitude = readBuffer.readInt();
|
||||
if (maxLatitude < LATITUDE_MIN || maxLatitude > LATITUDE_MAX) {
|
||||
return new FileOpenResult("invalid maximum latitude: " + maxLatitude);
|
||||
return new OpenResult("invalid maximum latitude: " + maxLatitude);
|
||||
}
|
||||
|
||||
// get and check the maximum longitude (4 bytes)
|
||||
int maxLongitude = readBuffer.readInt();
|
||||
if (maxLongitude < LONGITUDE_MIN || maxLongitude > LONGITUDE_MAX) {
|
||||
return new FileOpenResult("invalid maximum longitude: " + maxLongitude);
|
||||
return new OpenResult("invalid maximum longitude: " + maxLongitude);
|
||||
}
|
||||
|
||||
// check latitude and longitude range
|
||||
if (minLatitude > maxLatitude) {
|
||||
return new FileOpenResult("invalid latitude range: " + minLatitude + SPACE + maxLatitude);
|
||||
return new OpenResult("invalid latitude range: " + minLatitude + SPACE + maxLatitude);
|
||||
} else if (minLongitude > maxLongitude) {
|
||||
return new FileOpenResult("invalid longitude range: " + minLongitude + SPACE + maxLongitude);
|
||||
return new OpenResult("invalid longitude range: " + minLongitude + SPACE + maxLongitude);
|
||||
}
|
||||
|
||||
mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readFileSize(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readFileSize(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the file size (8 bytes)
|
||||
long headerFileSize = readBuffer.readLong();
|
||||
if (headerFileSize != fileSize) {
|
||||
return new FileOpenResult("invalid file size: " + headerFileSize);
|
||||
return new OpenResult("invalid file size: " + headerFileSize);
|
||||
}
|
||||
mapFileInfoBuilder.fileSize = fileSize;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readFileVersion(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readFileVersion(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the file version (4 bytes)
|
||||
int fileVersion = readBuffer.readInt();
|
||||
if (fileVersion != SUPPORTED_FILE_VERSION) {
|
||||
return new FileOpenResult("unsupported file version: " + fileVersion);
|
||||
return new OpenResult("unsupported file version: " + fileVersion);
|
||||
}
|
||||
mapFileInfoBuilder.fileVersion = fileVersion;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readMagicByte(ReadBuffer readBuffer) throws IOException {
|
||||
static OpenResult readMagicByte(ReadBuffer readBuffer) throws IOException {
|
||||
// read the the magic byte and the file header size into the buffer
|
||||
int magicByteLength = BINARY_OSM_MAGIC_BYTE.length();
|
||||
if (!readBuffer.readFromFile(magicByteLength + 4)) {
|
||||
return new FileOpenResult("reading magic byte has failed");
|
||||
return new OpenResult("reading magic byte has failed");
|
||||
}
|
||||
|
||||
// get and check the magic byte
|
||||
String magicByte = readBuffer.readUTF8EncodedString(magicByteLength);
|
||||
if (!BINARY_OSM_MAGIC_BYTE.equals(magicByte)) {
|
||||
return new FileOpenResult("invalid magic byte: " + magicByte);
|
||||
return new OpenResult("invalid magic byte: " + magicByte);
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readMapDate(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readMapDate(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the the map date (8 bytes)
|
||||
long mapDate = readBuffer.readLong();
|
||||
// is the map date before 2010-01-10 ?
|
||||
if (mapDate < 1200000000000L) {
|
||||
return new FileOpenResult("invalid map date: " + mapDate);
|
||||
return new OpenResult("invalid map date: " + mapDate);
|
||||
}
|
||||
mapFileInfoBuilder.mapDate = mapDate;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readPoiTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readPoiTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the number of POI tags (2 bytes)
|
||||
int numberOfPoiTags = readBuffer.readShort();
|
||||
if (numberOfPoiTags < 0) {
|
||||
return new FileOpenResult("invalid number of POI tags: " + numberOfPoiTags);
|
||||
return new OpenResult("invalid number of POI tags: " + numberOfPoiTags);
|
||||
}
|
||||
|
||||
Tag[] poiTags = new Tag[numberOfPoiTags];
|
||||
@ -166,53 +166,53 @@ final class RequiredFields {
|
||||
// get and check the POI tag
|
||||
String tag = readBuffer.readUTF8EncodedString();
|
||||
if (tag == null) {
|
||||
return new FileOpenResult("POI tag must not be null: " + currentTagId);
|
||||
return new OpenResult("POI tag must not be null: " + currentTagId);
|
||||
}
|
||||
poiTags[currentTagId] = new Tag(tag);
|
||||
}
|
||||
mapFileInfoBuilder.poiTags = poiTags;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readProjectionName(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readProjectionName(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the projection name
|
||||
String projectionName = readBuffer.readUTF8EncodedString();
|
||||
if (!MERCATOR.equals(projectionName)) {
|
||||
return new FileOpenResult("unsupported projection: " + projectionName);
|
||||
return new OpenResult("unsupported projection: " + projectionName);
|
||||
}
|
||||
mapFileInfoBuilder.projectionName = projectionName;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readRemainingHeader(ReadBuffer readBuffer) throws IOException {
|
||||
static OpenResult readRemainingHeader(ReadBuffer readBuffer) throws IOException {
|
||||
// get and check the size of the remaining file header (4 bytes)
|
||||
int remainingHeaderSize = readBuffer.readInt();
|
||||
if (remainingHeaderSize < HEADER_SIZE_MIN || remainingHeaderSize > HEADER_SIZE_MAX) {
|
||||
return new FileOpenResult("invalid remaining header size: " + remainingHeaderSize);
|
||||
return new OpenResult("invalid remaining header size: " + remainingHeaderSize);
|
||||
}
|
||||
|
||||
// read the header data into the buffer
|
||||
if (!readBuffer.readFromFile(remainingHeaderSize)) {
|
||||
return new FileOpenResult("reading header data has failed: " + remainingHeaderSize);
|
||||
return new OpenResult("reading header data has failed: " + remainingHeaderSize);
|
||||
}
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readTilePixelSize(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readTilePixelSize(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the tile pixel size (2 bytes)
|
||||
int tilePixelSize = readBuffer.readShort();
|
||||
// if (tilePixelSize != Tile.TILE_SIZE) {
|
||||
// return new FileOpenResult("unsupported tile pixel size: " + tilePixelSize);
|
||||
// }
|
||||
mapFileInfoBuilder.tilePixelSize = tilePixelSize;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
static FileOpenResult readWayTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
static OpenResult readWayTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
|
||||
// get and check the number of way tags (2 bytes)
|
||||
int numberOfWayTags = readBuffer.readShort();
|
||||
if (numberOfWayTags < 0) {
|
||||
return new FileOpenResult("invalid number of way tags: " + numberOfWayTags);
|
||||
return new OpenResult("invalid number of way tags: " + numberOfWayTags);
|
||||
}
|
||||
|
||||
Tag[] wayTags = new Tag[numberOfWayTags];
|
||||
@ -221,12 +221,12 @@ final class RequiredFields {
|
||||
// get and check the way tag
|
||||
String tag = readBuffer.readUTF8EncodedString();
|
||||
if (tag == null) {
|
||||
return new FileOpenResult("way tag must not be null: " + currentTagId);
|
||||
return new OpenResult("way tag must not be null: " + currentTagId);
|
||||
}
|
||||
wayTags[currentTagId] = new Tag(tag);
|
||||
}
|
||||
mapFileInfoBuilder.wayTags = wayTags;
|
||||
return FileOpenResult.SUCCESS;
|
||||
return OpenResult.SUCCESS;
|
||||
}
|
||||
|
||||
private RequiredFields() {
|
||||
|
||||
@ -58,10 +58,10 @@ import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.database.MapInfo;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.QueryResult;
|
||||
|
||||
import android.os.Environment;
|
||||
@ -75,8 +75,8 @@ import android.util.Log;
|
||||
public class MapDatabase implements IMapDatabase {
|
||||
private static final String TAG = "MapDatabase";
|
||||
|
||||
private static final MapFileInfo mMapInfo =
|
||||
new MapFileInfo(new BoundingBox(-180, -90, 180, 90),
|
||||
private static final MapInfo mMapInfo =
|
||||
new MapInfo(new BoundingBox(-180, -90, 180, 90),
|
||||
new Byte((byte) 4), new GeoPoint(53.11, 8.85),
|
||||
null, 0, 0, 0, "de", "comment", "author");
|
||||
|
||||
@ -268,12 +268,12 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapFileInfo getMapFileInfo() {
|
||||
public MapInfo getMapInfo() {
|
||||
return mMapInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOpenFile() {
|
||||
public boolean isOpen() {
|
||||
return mOpenFile;
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult openFile(File mapFile) {
|
||||
public OpenResult open(Map<String, String> options) {
|
||||
|
||||
if (USE_APACHE_HTTP)
|
||||
createClient();
|
||||
@ -322,11 +322,11 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
return new FileOpenResult();
|
||||
return new OpenResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeFile() {
|
||||
public void close() {
|
||||
mOpenFile = false;
|
||||
if (USE_APACHE_HTTP) {
|
||||
if (mClient != null) {
|
||||
@ -350,11 +350,6 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static File createDirectory(String pathName) {
|
||||
File file = new File(pathName);
|
||||
if (!file.exists() && !file.mkdirs()) {
|
||||
|
||||
@ -14,13 +14,13 @@
|
||||
*/
|
||||
package org.mapsforge.database.postgis;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -29,10 +29,10 @@ import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.WebMercator;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.database.MapInfo;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.QueryResult;
|
||||
import org.postgresql.PGConnection;
|
||||
|
||||
@ -56,8 +56,8 @@ public class MapDatabase implements IMapDatabase {
|
||||
|
||||
private Tag[] mTags;
|
||||
|
||||
private final MapFileInfo mMapInfo =
|
||||
new MapFileInfo(new BoundingBox(-180, -85, 180, 85),
|
||||
private final MapInfo mMapInfo =
|
||||
new MapInfo(new BoundingBox(-180, -85, 180, 85),
|
||||
new Byte((byte) 14), new GeoPoint(53.11, 8.85),
|
||||
WebMercator.NAME,
|
||||
0, 0, 0, "de", "comment", "author");
|
||||
@ -125,12 +125,12 @@ public class MapDatabase implements IMapDatabase {
|
||||
|
||||
byte[] b = null;
|
||||
PGHStore h = null;
|
||||
int cnt = 0;
|
||||
// int cnt = 0;
|
||||
try {
|
||||
while (r != null && r.next()) {
|
||||
mIndexPos = 0;
|
||||
mCoordPos = 0;
|
||||
cnt++;
|
||||
// cnt++;
|
||||
try {
|
||||
Object obj = r.getObject(1);
|
||||
h = null;
|
||||
@ -200,27 +200,27 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapFileInfo getMapFileInfo() {
|
||||
public MapInfo getMapInfo() {
|
||||
return mMapInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOpenFile() {
|
||||
public boolean isOpen() {
|
||||
return mOpenFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult openFile(File mapFile) {
|
||||
public OpenResult open(Map<String, String> options) {
|
||||
mOpenFile = true;
|
||||
if (mCoords == null) {
|
||||
mCoords = new float[100000];
|
||||
mIndex = new short[100000];
|
||||
}
|
||||
return new FileOpenResult();
|
||||
return new OpenResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeFile() {
|
||||
public void close() {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
@ -235,11 +235,6 @@ public class MapDatabase implements IMapDatabase {
|
||||
mOpenFile = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// taken from postgis-java
|
||||
|
||||
private static ValueGetter valueGetterForEndian(byte[] bytes) {
|
||||
@ -258,6 +253,7 @@ public class MapDatabase implements IMapDatabase {
|
||||
*
|
||||
* @param value
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
private boolean parse(byte[] value) {
|
||||
return parseGeometry(valueGetterForEndian(value));
|
||||
|
||||
@ -14,17 +14,17 @@
|
||||
*/
|
||||
package org.mapsforge.database.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.database.MapInfo;
|
||||
import org.mapsforge.database.OpenResult;
|
||||
import org.mapsforge.database.QueryResult;
|
||||
|
||||
/**
|
||||
@ -40,8 +40,8 @@ public class MapDatabase implements IMapDatabase {
|
||||
private Tag[] mTags = { new Tag("natural", "water") };
|
||||
private Tag[] mNameTags;
|
||||
|
||||
private final MapFileInfo mMapInfo =
|
||||
new MapFileInfo(new BoundingBox(-180, -90, 180, 90),
|
||||
private final MapInfo mMapInfo =
|
||||
new MapInfo(new BoundingBox(-180, -90, 180, 90),
|
||||
new Byte((byte) 0), null, PROJECTION, 0, 0, 0, "de", "yo!", "by me");
|
||||
|
||||
private boolean mOpenFile = false;
|
||||
@ -163,31 +163,26 @@ public class MapDatabase implements IMapDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapFileInfo getMapFileInfo() {
|
||||
public MapInfo getMapInfo() {
|
||||
return mMapInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOpenFile() {
|
||||
public boolean isOpen() {
|
||||
return mOpenFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult openFile(File mapFile) {
|
||||
public OpenResult open(Map<String, String> options) {
|
||||
mOpenFile = true;
|
||||
return new FileOpenResult();
|
||||
return new OpenResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeFile() {
|
||||
public void close() {
|
||||
mOpenFile = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user