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:
Hannes Janetzek 2012-09-11 22:40:10 +02:00
parent ab69675d69
commit 489f07dd5d
28 changed files with 576 additions and 610 deletions

View File

@ -4,7 +4,7 @@
<string-array name="preferences_map_database_keys"> <string-array name="preferences_map_database_keys">
<!-- <item>MAP_READER</item> --> <!-- <item>MAP_READER</item> -->
<!-- <item>POSTGIS_READER</item>--> <!-- <item>POSTGIS_READER</item> -->
<item>PBMAP_READER</item> <item>PBMAP_READER</item>
</string-array> </string-array>

View File

@ -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 * 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
@ -21,12 +21,10 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
public class Compass { public class Compass {
private final SensorEventListener mListener = new SensorEventListener() { private final SensorEventListener mListener = new SensorEventListener() {
@Override @Override
public void onSensorChanged(SensorEvent event) { 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) { if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0]; mAngle = event.values[0];
@ -48,12 +46,11 @@ public class Compass {
private SensorManager mSensorManager; private SensorManager mSensorManager;
private Sensor mSensor; private Sensor mSensor;
// private float[] mValues;
public Compass(MapActivity mapActivity, MapView mapView) { public Compass(MapActivity mapActivity, MapView mapView) {
mMapView = mapView; mMapView = mapView;
mSensorManager = (SensorManager) mapActivity mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE); .getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
} }

View File

@ -48,46 +48,8 @@ public abstract class MapActivity extends Activity {
&& sharedPreferences.contains(KEY_ZOOM_LEVEL); && sharedPreferences.contains(KEY_ZOOM_LEVEL);
} }
/**
* Internal list which contains references to all running MapView objects.
*/
private MapView mMapView; 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 @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -111,10 +73,10 @@ public abstract class MapActivity extends Activity {
editor.putInt(KEY_ZOOM_LEVEL, mapPosition.zoomLevel); editor.putInt(KEY_ZOOM_LEVEL, mapPosition.zoomLevel);
} }
if (mMapView.getMapFile() != null) { // if (mMapView.getMapFile() != null) {
// save the map file // // save the map file
editor.putString(KEY_MAP_FILE, mMapView.getMapFile()); // editor.putString(KEY_MAP_FILE, mMapView.getMapFile());
} // }
editor.putString(KEY_THEME, mMapView.getRenderTheme()); editor.putString(KEY_THEME, mMapView.getRenderTheme());
@ -134,10 +96,40 @@ public abstract class MapActivity extends Activity {
* the calling MapView. * the calling MapView.
*/ */
final void registerMapView(MapView mapView) { final void registerMapView(MapView mapView) {
if (mMapView != null)
return;
mMapView = mapView; 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));
}
} }
} }

View File

@ -14,11 +14,11 @@
*/ */
package org.mapsforge.android; package org.mapsforge.android;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -39,10 +39,9 @@ import org.mapsforge.android.utils.GlConfigChooser;
import org.mapsforge.core.GeoPoint; import org.mapsforge.core.GeoPoint;
import org.mapsforge.core.MapPosition; import org.mapsforge.core.MapPosition;
import org.mapsforge.core.Tile; import org.mapsforge.core.Tile;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.MapFileInfo; import org.mapsforge.database.MapInfo;
import org.mapsforge.database.mapfile.MapDatabase; import org.mapsforge.database.OpenResult;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import android.content.Context; 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 * 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. * map.
* <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>
*/ */
public class MapView extends GLSurfaceView { public class MapView extends GLSurfaceView {
@ -74,7 +64,7 @@ public class MapView extends GLSurfaceView {
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER; public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
// private static final float DEFAULT_TEXT_SCALE = 1; // 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; public final static boolean debugFrameTime = false;
@ -95,7 +85,7 @@ public class MapView extends GLSurfaceView {
private MapWorker mMapWorkers[]; private MapWorker mMapWorkers[];
private int mNumMapWorkers = 4; private int mNumMapWorkers = 4;
private DebugSettings debugSettings; private DebugSettings debugSettings;
private String mMapFile; private String mRenderTheme;
/** /**
* @param context * @param context
@ -178,47 +168,26 @@ public class MapView extends GLSurfaceView {
mMapWorkers[i].start(); mMapWorkers[i].start();
} }
setMapFile("default");
initMapStartPosition();
mapActivity.registerMapView(this); mapActivity.registerMapView(this);
// if (!setRenderTheme(DEFAULT_RENDER_THEME)) { if (!mMapDatabase.isOpen()) {
// Log.d(TAG, "X could not parse theme"); Log.d(TAG, "open database with defaults");
// // FIXME show init error dialog setMapOptions(null);
// } }
if (!mMapViewPosition.isValid()) {
Log.d(TAG, "set default start position");
setMapCenter(getStartPosition());
}
setEGLConfigChooser(new GlConfigChooser()); setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2); setEGLContextClientVersion(2);
// setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS); // setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
setRenderer(mMapRenderer); setRenderer(mMapRenderer);
if (!debugFrameTime) if (!debugFrameTime)
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 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 mMapDatabase;
} }
/**
* @return the currently used map file.
*/
public String getMapFile() {
return mMapFile;
}
/** /**
* @return the current position and zoom level of this MapView. * @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. * Calculates all necessary tiles and adds jobs accordingly.
*/ */
public void redrawTiles() { public void redrawTiles() {
if (getWidth() <= 0 || getHeight() <= 0)
return;
mMapRenderer.updateMap(false); 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 * @param debugSettings
* the new DebugSettings for this MapView. * the new DebugSettings for this MapView.
*/ */
public void setDebugSettings(DebugSettings debugSettings) { public void setDebugSettings(DebugSettings debugSettings) {
this.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. * Sets the map file for this MapView.
* *
* @param mapFile * @param mapOptions
* the path to the map file. * ...
* @return true if the map file was set correctly, false otherwise. * @return true if the map file was set correctly, false otherwise.
*/ */
public boolean setMapFile(String mapFile) { public boolean setMapOptions(Map<String, String> mapOptions) {
FileOpenResult fileOpenResult = null; OpenResult openResult = null;
Log.i(TAG, "set mapfile " + mapFile);
if (mapFile != null && mapFile.equals(mMapFile)) {
// same map file as before
return false;
}
boolean initialized = false; boolean initialized = false;
mJobQueue.clear(); mJobQueue.clear();
mapWorkersPause(true); mapWorkersPause(true);
for (MapWorker mapWorker : mMapWorkers) { for (MapWorker mapWorker : mMapWorkers) {
@ -339,59 +275,49 @@ public class MapView extends GLSurfaceView {
IMapGenerator mapGenerator = mapWorker.getMapGenerator(); IMapGenerator mapGenerator = mapWorker.getMapGenerator();
IMapDatabase mapDatabase = mapGenerator.getMapDatabase(); IMapDatabase mapDatabase = mapGenerator.getMapDatabase();
mapDatabase.closeFile(); mapDatabase.close();
openResult = mapDatabase.open(null);
if (mapFile != null) if (openResult != null && openResult.isSuccess()) {
fileOpenResult = mapDatabase.openFile(new File(mapFile)); mMapOptions = mapOptions;
else initialized = true;
fileOpenResult = mapDatabase.openFile(null);
if (fileOpenResult != null && fileOpenResult.isSuccess()) {
mMapFile = mapFile;
if (!initialized)
initialized = true;
} }
} }
mapWorkersProceed(); mapWorkersProceed();
if (initialized) { if (initialized) {
clearAndRedrawMapView(); mMapRenderer.updateMap(true);
Log.i(TAG, "mapfile set"); Log.i(TAG, "MapDatabase ready");
return true; return true;
} }
mMapFile = null; mMapOptions = null;
Log.i(TAG, "loading mapfile failed"); Log.i(TAG, "Opening MapDatabase failed");
return false; return false;
} }
private GeoPoint getStartPoint() { private MapPosition getStartPosition() {
if (mMapDatabase != null && mMapDatabase.hasOpenFile()) { if (mMapDatabase == null)
MapFileInfo mapFileInfo = mMapDatabase.getMapFileInfo(); return new MapPosition();
if (mapFileInfo.startPosition != null) { MapInfo mapInfo = mMapDatabase.getMapInfo();
return mapFileInfo.startPosition; if (mapInfo == null)
} else if (mapFileInfo.mapCenter != null) { return new MapPosition();
return mapFileInfo.mapCenter;
}
}
return null; GeoPoint startPos = mapInfo.startPosition;
}
private Byte getStartZoomLevel() { if (startPos == null)
if (mMapDatabase != null && mMapDatabase.hasOpenFile()) { startPos = mapInfo.mapCenter;
MapFileInfo mapFileInfo = mMapDatabase.getMapFileInfo();
if (mapFileInfo.startZoomLevel != null) { if (startPos == null)
return mapFileInfo.startZoomLevel; 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(); mJobQueue.clear();
String mapFile = mMapFile; // String mapFile = mMapFile;
mMapFile = null; // mMapFile = null;
setMapFile(mapFile); setMapOptions(null);
mapWorkersProceed(); mapWorkersProceed();
} }
private String mRenderTheme;
public String getRenderTheme() { public String getRenderTheme() {
return mRenderTheme; return mRenderTheme;
} }
@ -456,8 +380,7 @@ public class MapView extends GLSurfaceView {
if (ret) { if (ret) {
mRenderTheme = internalRenderTheme.name(); mRenderTheme = internalRenderTheme.name();
} }
mMapRenderer.updateMap(true);
clearAndRedrawMapView();
return ret; return ret;
} }
@ -480,8 +403,7 @@ public class MapView extends GLSurfaceView {
if (ret) { if (ret) {
mRenderTheme = renderThemePath; mRenderTheme = renderThemePath;
} }
mMapRenderer.updateMap(true);
clearAndRedrawMapView();
} }
private boolean setRenderTheme(Theme theme) { private boolean setRenderTheme(Theme theme) {
@ -515,16 +437,51 @@ public class MapView extends GLSurfaceView {
return false; return false;
} }
/** @Override
* Sets the text scale for the map rendering. Has no effect in downloading mode. protected synchronized void onSizeChanged(int width, int height,
* int oldWidth, int oldHeight) {
* @param textScale
* the new text scale for the map rendering. mJobQueue.clear();
*/ mapWorkersPause(true);
// public void setTextScale(float textScale) {
// mJobParameters = new JobParameters(mJobParameters.theme, textScale); super.onSizeChanged(width, height, oldWidth, oldHeight);
// clearAndRedrawMapView();
// } 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. * Zooms in or out by the given amount of zoom levels.
@ -550,42 +507,11 @@ public class MapView extends GLSurfaceView {
} }
mMapViewPosition.setZoomLevel((byte) z); mMapViewPosition.setZoomLevel((byte) z);
redrawTiles(); redrawTiles();
return true; 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. * @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. * @return true if the current center position of this MapView is valid, false otherwise.
*/ */
boolean hasValidCenter() { boolean hasValidCenter() {
if (!mMapViewPosition.isValid()) { MapInfo mapInfo;
if (!mMapViewPosition.isValid())
return false; return false;
} else if (!mMapDatabase.hasOpenFile()
|| !mMapDatabase.getMapFileInfo().boundingBox.contains(getMapPosition() if ((mapInfo = mMapDatabase.getMapInfo()) == null)
.getMapCenter())) { return false;
if (!mapInfo.boundingBox.contains(getMapPosition().getMapCenter()))
return false; return false;
}
return true; return true;
} }
@ -615,38 +544,33 @@ public class MapView extends GLSurfaceView {
mMapZoomControls.getZoomLevelMin()); 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. * Sets the center and zoom level of this MapView and triggers a redraw.
* *
* @param mapPosition * @param mapPosition
* the new map position of this MapView. * the new map position of this MapView.
*/ */
void setCenterAndZoom(MapPosition mapPosition) { public void setMapCenter(MapPosition mapPosition) {
Log.d(TAG, "setCenterAndZoom " Log.d(TAG, "setMapCenter "
+ " lat: " + mapPosition.lat + " lat: " + mapPosition.lat
+ " lon: " + mapPosition.lon); + " lon: " + mapPosition.lon);
mMapViewPosition.setMapCenterAndZoomLevel(mapPosition); mMapViewPosition.setMapCenter(mapPosition);
redrawTiles(); 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 * @return MapPosition
*/ */
@ -696,9 +620,8 @@ public class MapView extends GLSurfaceView {
public void enableRotation(boolean enable) { public void enableRotation(boolean enable) {
enableRotation = enable; enableRotation = enable;
if (enable && this.enableCompass) { if (enable) {
this.enableCompass = false; enableCompass(false);
mCompass.disable();
} }
} }
@ -709,7 +632,7 @@ public class MapView extends GLSurfaceView {
this.enableCompass = enable; this.enableCompass = enable;
if (enable) if (enable)
this.enableRotation = false; enableRotation(false);
if (enable) if (enable)
mCompass.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 final int
// public Handler messageHandler = new Handler() { // public Handler messageHandler = new Handler() {
// //

View File

@ -19,6 +19,7 @@ import org.mapsforge.core.MapPosition;
import org.mapsforge.core.MercatorProjection; import org.mapsforge.core.MercatorProjection;
import android.util.FloatMath; import android.util.FloatMath;
import android.util.Log;
/** /**
* A MapPosition stores the latitude and longitude coordinate of a MapView together with its zoom level. * 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) { public synchronized void rotateMap(float angle, float cx, float cy) {
moveMap(cx, cy); moveMap(cx, cy);
Log.d("MapViewPosition", "rotate:" + angle + " " + (mRotation - angle));
mRotation -= angle; mRotation -= angle;
} }
@ -152,7 +154,7 @@ public class MapViewPosition {
mLongitude = MercatorProjection.limitLongitude(geoPoint.getLongitude()); mLongitude = MercatorProjection.limitLongitude(geoPoint.getLongitude());
} }
synchronized void setMapCenterAndZoomLevel(MapPosition mapPosition) { synchronized void setMapCenter(MapPosition mapPosition) {
mLatitude = MercatorProjection.limitLatitude(mapPosition.lat); mLatitude = MercatorProjection.limitLatitude(mapPosition.lat);
mLongitude = MercatorProjection.limitLongitude(mapPosition.lon); mLongitude = MercatorProjection.limitLongitude(mapPosition.lon);
mZoomLevel = mMapView.limitZoomLevel(mapPosition.zoomLevel); mZoomLevel = mMapView.limitZoomLevel(mapPosition.zoomLevel);

View File

@ -19,6 +19,7 @@ import org.mapsforge.core.Tile;
import android.content.Context; import android.content.Context;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener; import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -41,7 +42,7 @@ public class TouchHandler {
private boolean mRotationStart; private boolean mRotationStart;
private float mPosX; private float mPosX;
private float mPosY; private float mPosY;
private float mAngle; private double mAngle;
private int mActivePointerId; private int mActivePointerId;
@ -125,24 +126,27 @@ public class TouchHandler {
double dy = y1 - y2; double dy = y1 - y2;
double rad = Math.atan2(dy, dx); double rad = Math.atan2(dy, dx);
float angle = (float) Math.toDegrees(rad);
// focus point relative to center // focus point relative to center
double cx = (mMapView.getWidth() >> 1) - (x1 + x2) / 2; double cx = (mMapView.getWidth() >> 1) - (x1 + x2) / 2;
double cy = (mMapView.getHeight() >> 1) - (y1 + y2) / 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); // Log.d("...", "move " + x + " " + y + " " + cx + " " + cy);
if (!mRotationStart) { if (!mRotationStart) {
if (Math.abs(angle - mAngle) > 3.0) if (Math.abs(rad - mAngle) > 0.001)
mRotationStart = true; mRotationStart = true;
} }
else { else {
mMapPosition.rotateMap(angle - mAngle, (float) x, (float) y); mMapPosition.rotateMap((float) Math.toDegrees(rad - mAngle), x, y);
mAngle = angle; mAngle = rad;
mMapView.redrawTiles(); mMapView.redrawTiles();
} }
} }
@ -170,10 +174,8 @@ public class TouchHandler {
if (multi == 1) { if (multi == 1) {
double dx = event.getX(0) - event.getX(1); double dx = event.getX(0) - event.getX(1);
double dy = event.getY(0) - event.getY(1); double dy = event.getY(0) - event.getY(1);
double rad = Math.atan2(dy, dx); mAngle = Math.atan2(dy, dx);
mAngle = (float) Math.toDegrees(rad);
} }
return true; return true;
} }
@ -326,10 +328,57 @@ public class TouchHandler {
private DecelerateInterpolator mBounce = new DecelerateInterpolator(); private DecelerateInterpolator mBounce = new DecelerateInterpolator();
private boolean mZooutOut = true;
@Override @Override
public void onLongPress(MotionEvent e) { 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; private final float mScaleDuration = 300;

View File

@ -131,6 +131,9 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
*/ */
@Override @Override
public void updateMap(boolean clear) { public void updateMap(boolean clear) {
if (mWidth <= 0 || mHeight <= 0)
return;
TileLoader.updateMap(clear); TileLoader.updateMap(clear);
} }

View File

@ -34,7 +34,7 @@ public class TextRenderer {
private final static int TEXTURE_HEIGHT = 256; private final static int TEXTURE_HEIGHT = 256;
private final static float SCALE = 8.0f; private final static float SCALE = 8.0f;
private final static int LBIT_MASK = 0xfffffffe; 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 INDICES_PER_SPRITE = 6;
final static int VERTICES_PER_SPRITE = 4; final static int VERTICES_PER_SPRITE = 4;

View File

@ -14,6 +14,8 @@
*/ */
package org.mapsforge.android.mapgenerator; package org.mapsforge.android.mapgenerator;
//import static org.mapsforge.android.mapgenerator.JobTile.LOADING;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.PriorityQueue; import java.util.PriorityQueue;
@ -40,6 +42,7 @@ public class JobQueue {
// mPriorityQueue.addAll(tiles); // mPriorityQueue.addAll(tiles);
for (int i = 0, n = tiles.size(); i < n; i++) { for (int i = 0, n = tiles.size(); i < n; i++) {
JobTile tile = tiles.get(i); JobTile tile = tiles.get(i);
// tile.state = LOADING;
tile.isLoading = true; tile.isLoading = true;
mPriorityQueue.offer(tile); mPriorityQueue.offer(tile);
} }
@ -51,6 +54,7 @@ public class JobQueue {
public synchronized void clear() { public synchronized void clear() {
for (int i = 0, n = mPriorityQueue.size(); i < n; i++) { for (int i = 0, n = mPriorityQueue.size(); i < n; i++) {
JobTile tile = mPriorityQueue.poll(); JobTile tile = mPriorityQueue.poll();
// tile.state = 0;
tile.isLoading = false; tile.isLoading = false;
} }
mPriorityQueue.clear(); mPriorityQueue.clear();

View File

@ -172,8 +172,8 @@ public class RenderTheme {
} }
private int missCnt = 0; // private int missCnt = 0;
private int hitCnt = 0; // private int hitCnt = 0;
private MatchingCacheKey mCacheKey = new MatchingCacheKey(); private MatchingCacheKey mCacheKey = new MatchingCacheKey();
/** /**

View File

@ -458,10 +458,6 @@ public class MapGenerator implements IMapGenerator, IRenderCallback,
// WayDecorator.renderText(this, paint, outline, mCoords, mWayDataContainer, mWayNames); // WayDecorator.renderText(this, paint, outline, mCoords, mWayDataContainer, mWayNames);
} }
String getWayName() {
return mMapDatabase.readString(mWayDataContainer.textPos[0]);
}
@Override @Override
public void setMapDatabase(IMapDatabase mapDatabase) { public void setMapDatabase(IMapDatabase mapDatabase) {
mMapDatabase = mapDatabase; mMapDatabase = mapDatabase;

View File

@ -189,9 +189,9 @@ final class WayDecorator {
if (wayNameWidth < 0) { if (wayNameWidth < 0) {
if (text == null) { if (text == null) {
text = mapGenerator.getWayName(); // text = mapGenerator.getWayName();
if (text == null) // if (text == null)
text = "blub"; text = "blub";
} }
wayNameWidth = (paint.measureText(text) + 10); wayNameWidth = (paint.measureText(text) + 10);

View File

@ -2,8 +2,6 @@ package org.mapsforge.app;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.text.DateFormat;
import java.util.Date;
import org.mapsforge.android.DebugSettings; import org.mapsforge.android.DebugSettings;
import org.mapsforge.android.MapActivity; 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.filefilter.ValidRenderTheme;
import org.mapsforge.app.filepicker.FilePicker; import org.mapsforge.app.filepicker.FilePicker;
import org.mapsforge.app.preferences.EditPreferences; import org.mapsforge.app.preferences.EditPreferences;
import org.mapsforge.core.BoundingBox;
import org.mapsforge.core.GeoPoint; import org.mapsforge.core.GeoPoint;
import org.mapsforge.database.MapFileInfo; import org.mapsforge.core.MapPosition;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.ActionBar; import android.app.ActionBar;
@ -56,7 +53,7 @@ import android.widget.Toast;
*/ */
public class TileMap extends MapActivity { public class TileMap extends MapActivity {
// implements ActionBar.OnNavigationListener { // 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_SHOW_MY_LOCATION = "showMyLocation";
private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation"; private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation";
private static final int DIALOG_ENTER_COORDINATES = 0; private static final int DIALOG_ENTER_COORDINATES = 0;
@ -156,7 +153,7 @@ public class TileMap extends MapActivity {
mLocation.disableSnapToLocation(true); mLocation.disableSnapToLocation(true);
mMapView.setCenter(mMapView.getMapDatabase() mMapView.setCenter(mMapView.getMapDatabase()
.getMapFileInfo().mapCenter); .getMapInfo().mapCenter);
return true; return true;
case R.id.menu_preferences: case R.id.menu_preferences:
@ -282,21 +279,22 @@ public class TileMap extends MapActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SELECT_MAP_FILE) { // if (requestCode == SELECT_MAP_FILE) {
if (resultCode == RESULT_OK) { // if (resultCode == RESULT_OK) {
//
mLocation.disableSnapToLocation(true); // mLocation.disableSnapToLocation(true);
//
if (intent != null) { // if (intent != null) {
if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) { // if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
mMapView.setMapFile(intent // mMapView.setMapFile(intent
.getStringExtra(FilePicker.SELECTED_FILE)); // .getStringExtra(FilePicker.SELECTED_FILE));
} // }
} // }
} else if (resultCode == RESULT_CANCELED) { // } else if (resultCode == RESULT_CANCELED) {
startActivity(new Intent(this, EditPreferences.class)); // startActivity(new Intent(this, EditPreferences.class));
} // }
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK // } else
if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
&& intent != null && intent != null
&& intent.getStringExtra(FilePicker.SELECTED_FILE) != null) { && intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
try { try {
@ -380,14 +378,16 @@ public class TileMap extends MapActivity {
.toString()); .toString());
double longitude = Double.parseDouble(longitudeView.getText() double longitude = Double.parseDouble(longitudeView.getText()
.toString()); .toString());
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
TileMap.this.mMapView.setCenter(geoPoint);
SeekBar zoomLevelView = (SeekBar) view SeekBar zoomLevelView = (SeekBar) view
.findViewById(R.id.zoomLevel); .findViewById(R.id.zoomLevel);
TileMap.this.mMapView.zoom((byte) (zoomLevelView byte zoom = (byte) (zoomLevelView.getProgress());
.getProgress() - mMapView.getMapPosition()
.getZoomLevel())); MapPosition mapPosition = new MapPosition(latitude,
longitude, zoom, 1, 0);
TileMap.this.mMapView.setMapCenter(mapPosition);
} }
}); });
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
@ -443,62 +443,62 @@ public class TileMap extends MapActivity {
final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue); final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue);
textView.setText(String.valueOf(zoomlevel.getProgress())); textView.setText(String.valueOf(zoomlevel.getProgress()));
zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView)); zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView));
} else if (id == DIALOG_INFO_MAP_FILE) { // } else if (id == DIALOG_INFO_MAP_FILE) {
MapFileInfo mapFileInfo = mMapView.getMapDatabase().getMapFileInfo(); // MapInfo mapInfo = mMapView.getMapDatabase().getMapInfo();
//
TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName); // TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
textView.setText(mMapView.getMapFile()); // textView.setText(mMapView.getMapFile());
//
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize); // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize, // textView.setText(FileUtils.formatFileSize(mapInfo.fileSize,
getResources())); // getResources()));
//
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion); // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
textView.setText(String.valueOf(mapFileInfo.fileVersion)); // textView.setText(String.valueOf(mapInfo.fileVersion));
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug); // // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
// if (mapFileInfo.debugFile) { // // if (mapFileInfo.debugFile) {
// textView.setText(R.string.info_map_file_debug_yes); // // 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 { // } else {
// textView.setText(R.string.info_map_file_debug_no); // textView.setText(startPosition.getLatitude() + ", "
// + startPosition.getLongitude());
// } // }
//
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate); // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
Date date = new Date(mapFileInfo.mapDate); // Byte startZoomLevel = mapInfo.startZoomLevel;
textView.setText(DateFormat.getDateTimeInstance().format(date)); // if (startZoomLevel == null) {
// textView.setText(null);
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea); // } else {
BoundingBox boundingBox = mapFileInfo.boundingBox; // textView.setText(startZoomLevel.toString());
textView.setText(boundingBox.getMinLatitude() + ", " // }
+ boundingBox.getMinLongitude() + " - \n" //
+ boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude()); // textView = (TextView) dialog
// .findViewById(R.id.infoMapFileViewLanguagePreference);
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition); // textView.setText(mapInfo.languagePreference);
GeoPoint startPosition = mapFileInfo.startPosition; //
if (startPosition == null) { // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
textView.setText(null); // textView.setText(mapInfo.comment);
} else { //
textView.setText(startPosition.getLatitude() + ", " // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
+ startPosition.getLongitude()); // textView.setText(mapInfo.createdBy);
}
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);
} else { } else {
super.onPrepareDialog(id, dialog); super.onPrepareDialog(id, dialog);
} }
@ -595,12 +595,12 @@ public class TileMap extends MapActivity {
mMapView.setDebugSettings(debugSettings); mMapView.setDebugSettings(debugSettings);
if (mMapDatabase == MapDatabases.MAP_READER) { // if (mMapDatabase == MapDatabases.MAP_READER) {
if (mMapView.getMapFile() == null) // if (mMapView.getMapFile() == null)
startMapFilePicker(); // startMapFilePicker();
} else { // } else {
mMapView.setMapFile(mMapView.getMapFile()); // mMapView.setMapFile(mMapView.getMapFile());
} // }
if (Build.VERSION.SDK_INT >= 11) { if (Build.VERSION.SDK_INT >= 11) {
VersionHelper.refreshActionBarMenu(this); VersionHelper.refreshActionBarMenu(this);

View File

@ -16,7 +16,7 @@ package org.mapsforge.app.filefilter;
import java.io.FileFilter; import java.io.FileFilter;
import org.mapsforge.database.FileOpenResult; import org.mapsforge.database.OpenResult;
/** /**
* An extension of the {@link FileFilter} interface. * 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). * @return the result of the last {@link #accept} call (might be null).
*/ */
FileOpenResult getFileOpenResult(); OpenResult getFileOpenResult();
} }

View File

@ -15,27 +15,32 @@
package org.mapsforge.app.filefilter; package org.mapsforge.app.filefilter;
import java.io.File; import java.io.File;
import java.util.HashMap;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.OpenResult;
import org.mapsforge.database.mapfile.MapDatabase; import org.mapsforge.database.mapfile.MapDatabase;
/** /**
* Accepts all valid map files. * Accepts all valid map files.
*/ */
public final class ValidMapFile implements ValidFileFilter { public final class ValidMapFile implements ValidFileFilter {
private FileOpenResult fileOpenResult; private OpenResult openResult;
@Override @Override
public boolean accept(File file) { public boolean accept(File file) {
IMapDatabase mapDatabase = new MapDatabase(); IMapDatabase mapDatabase = new MapDatabase();
this.fileOpenResult = mapDatabase.openFile(file); HashMap<String, String> options = new HashMap<String, String>();
mapDatabase.closeFile(); options.put("mapfile", file.getAbsolutePath());
return this.fileOpenResult.isSuccess();
this.openResult = mapDatabase.open(options);
mapDatabase.close();
return this.openResult.isSuccess();
} }
@Override @Override
public FileOpenResult getFileOpenResult() { public OpenResult getFileOpenResult() {
return this.fileOpenResult; return this.openResult;
} }
} }

View File

@ -23,7 +23,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import org.mapsforge.android.rendertheme.RenderThemeHandler; 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.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@ -32,7 +32,7 @@ import org.xml.sax.XMLReader;
* Accepts all valid render theme XML files. * Accepts all valid render theme XML files.
*/ */
public final class ValidRenderTheme implements ValidFileFilter { public final class ValidRenderTheme implements ValidFileFilter {
private FileOpenResult fileOpenResult; private OpenResult openResult;
@Override @Override
public boolean accept(File file) { public boolean accept(File file) {
@ -44,28 +44,28 @@ public final class ValidRenderTheme implements ValidFileFilter {
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
xmlReader.setContentHandler(renderThemeHandler); xmlReader.setContentHandler(renderThemeHandler);
xmlReader.parse(new InputSource(inputStream)); xmlReader.parse(new InputSource(inputStream));
this.fileOpenResult = FileOpenResult.SUCCESS; this.openResult = OpenResult.SUCCESS;
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
this.fileOpenResult = new FileOpenResult(e.getMessage()); this.openResult = new OpenResult(e.getMessage());
} catch (SAXException e) { } catch (SAXException e) {
this.fileOpenResult = new FileOpenResult(e.getMessage()); this.openResult = new OpenResult(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
this.fileOpenResult = new FileOpenResult(e.getMessage()); this.openResult = new OpenResult(e.getMessage());
} finally { } finally {
try { try {
if (inputStream != null) { if (inputStream != null) {
inputStream.close(); inputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
this.fileOpenResult = new FileOpenResult(e.getMessage()); this.openResult = new OpenResult(e.getMessage());
} }
} }
return this.fileOpenResult.isSuccess(); return this.openResult.isSuccess();
} }
@Override @Override
public FileOpenResult getFileOpenResult() { public OpenResult getFileOpenResult() {
return this.fileOpenResult; return this.openResult;
} }
} }

View File

@ -41,6 +41,16 @@ public class MapPosition {
public final double x; public final double x;
public final double y; 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 * @param geoPoint
* the map position. * the map position.
@ -49,7 +59,6 @@ public class MapPosition {
* @param scale * @param scale
* ... * ...
*/ */
public MapPosition(GeoPoint geoPoint, byte zoomLevel, float scale) { public MapPosition(GeoPoint geoPoint, byte zoomLevel, float scale) {
// this.geoPoint = geoPoint; // this.geoPoint = geoPoint;
this.zoomLevel = zoomLevel; this.zoomLevel = zoomLevel;

View File

@ -14,7 +14,7 @@
*/ */
package org.mapsforge.database; package org.mapsforge.database;
import java.io.File; import java.util.Map;
import org.mapsforge.android.mapgenerator.JobTile; import org.mapsforge.android.mapgenerator.JobTile;
@ -24,11 +24,6 @@ import org.mapsforge.android.mapgenerator.JobTile;
*/ */
public interface IMapDatabase { 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. * Starts a database query with the given parameters.
* *
@ -46,33 +41,32 @@ public interface IMapDatabase {
* @throws IllegalStateException * @throws IllegalStateException
* if no map is currently opened. * 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 * @param options
* the map file. * the options.
* @return a FileOpenResult containing an error message in case of a failure. * @return a OpenResult containing an error message in case of a failure.
* @throws IllegalArgumentException
* if the given map file is null.
*/ */
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(); public abstract String getMapProjection();
/** /**
* @param position * Cancel loading
* ....
* @return ...
*/ */
public abstract String readString(int position);
public abstract void cancel(); public abstract void cancel();
} }

View File

@ -21,9 +21,9 @@ import org.mapsforge.database.mapfile.MapDatabase;
/** /**
* Contains the immutable metadata of a map file. * 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. * The bounding box of the map file.
*/ */
@ -101,7 +101,7 @@ public class MapFileInfo {
* @param createdBy * @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) { long date, long size, int version, String language, String comment, String createdBy) {
this.startZoomLevel = zoom; this.startZoomLevel = zoom;

View File

@ -18,11 +18,11 @@ package org.mapsforge.database;
/** /**
* A FileOpenResult is a simple DTO which is returned by IMapDatabase#openFile(File). * 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}. * 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 String errorMessage;
private final boolean success; private final boolean success;
@ -31,7 +31,7 @@ public class FileOpenResult {
* @param errorMessage * @param errorMessage
* a textual message describing the error, must not be null. * a textual message describing the error, must not be null.
*/ */
public FileOpenResult(String errorMessage) { public OpenResult(String errorMessage) {
if (errorMessage == null) { if (errorMessage == null) {
throw new IllegalArgumentException("error message must not be 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.success = true;
this.errorMessage = null; this.errorMessage = null;
} }

View File

@ -17,15 +17,16 @@ package org.mapsforge.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;
import org.mapsforge.android.mapgenerator.JobTile; import org.mapsforge.android.mapgenerator.JobTile;
import org.mapsforge.core.MercatorProjection; import org.mapsforge.core.MercatorProjection;
import org.mapsforge.core.Tag; import org.mapsforge.core.Tag;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.IMapDatabaseCallback; import org.mapsforge.database.IMapDatabaseCallback;
import org.mapsforge.database.OpenResult;
import org.mapsforge.database.QueryResult; import org.mapsforge.database.QueryResult;
import org.mapsforge.database.mapfile.header.MapFileHeader; import org.mapsforge.database.mapfile.header.MapFileHeader;
import org.mapsforge.database.mapfile.header.MapFileInfo; import org.mapsforge.database.mapfile.header.MapFileInfo;
@ -242,7 +243,7 @@ public class MapDatabase implements IMapDatabase {
* @see org.mapsforge.map.reader.IMapDatabase#getMapFileInfo() * @see org.mapsforge.map.reader.IMapDatabase#getMapFileInfo()
*/ */
@Override @Override
public MapFileInfo getMapFileInfo() { public MapFileInfo getMapInfo() {
if (sMapFileHeader == null) { if (sMapFileHeader == null) {
throw new IllegalStateException("no map file is currently opened"); 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() * @see org.mapsforge.map.reader.IMapDatabase#hasOpenFile()
*/ */
@Override @Override
public boolean hasOpenFile() { public boolean isOpen() {
return mInputFile != null; return mInputFile != null;
} }
@ -268,54 +269,56 @@ public class MapDatabase implements IMapDatabase {
* @see org.mapsforge.map.reader.IMapDatabase#openFile(java.io.File) * @see org.mapsforge.map.reader.IMapDatabase#openFile(java.io.File)
*/ */
@Override @Override
public FileOpenResult openFile(File mapFile) { public OpenResult open(Map<String, String> options) {
try { try {
if (mapFile == null) { if (options == null || options.get("mapfile") == null) {
// throw new IllegalArgumentException("mapFile must not be 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 // 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 // check if the file exists and is readable
if (!mapFile.exists()) { if (!file.exists()) {
return new FileOpenResult("file does not exist: " + mapFile); return new OpenResult("file does not exist: " + file);
} else if (!mapFile.isFile()) { } else if (!file.isFile()) {
return new FileOpenResult("not a file: " + mapFile); return new OpenResult("not a file: " + file);
} else if (!mapFile.canRead()) { } else if (!file.canRead()) {
return new FileOpenResult("cannot read file: " + mapFile); return new OpenResult("cannot read file: " + file);
} }
// open the file in read only mode // open the file in read only mode
mInputFile = new RandomAccessFile(mapFile, READ_ONLY_MODE); mInputFile = new RandomAccessFile(file, READ_ONLY_MODE);
mFileSize = mInputFile.length(); mFileSize = mInputFile.length();
mReadBuffer = new ReadBuffer(mInputFile); mReadBuffer = new ReadBuffer(mInputFile);
if (instances > 0) { if (instances > 0) {
instances++; instances++;
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
sMapFileHeader = new MapFileHeader(); sMapFileHeader = new MapFileHeader();
FileOpenResult fileOpenResult = sMapFileHeader.readHeader(mReadBuffer, OpenResult openResult = sMapFileHeader.readHeader(mReadBuffer,
mFileSize); mFileSize);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
closeFile(); close();
return fileOpenResult; return openResult;
} }
prepareExecution(); prepareExecution();
instances++; instances++;
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.SEVERE, null, e); LOG.log(Level.SEVERE, null, e);
// make sure that the file is closed // make sure that the file is closed
closeFile(); close();
return new FileOpenResult(e.getMessage()); return new OpenResult(e.getMessage());
} }
} }
@ -324,7 +327,7 @@ public class MapDatabase implements IMapDatabase {
* @see org.mapsforge.map.reader.IMapDatabase#closeFile() * @see org.mapsforge.map.reader.IMapDatabase#closeFile()
*/ */
@Override @Override
public void closeFile() { public void close() {
instances--; instances--;
if (instances > 0) { if (instances > 0) {
mReadBuffer = null; mReadBuffer = null;
@ -627,7 +630,8 @@ public class MapDatabase implements IMapDatabase {
// check if the POI has a house number // check if the POI has a house number
if ((featureByte & POI_FEATURE_HOUSE_NUMBER) != 0) { if ((featureByte & POI_FEATURE_HOUSE_NUMBER) != 0) {
// mReadBuffer.getPositionAndSkip(); // mReadBuffer.getPositionAndSkip();
String str = mReadBuffer.readUTF8EncodedString(); // String str =
mReadBuffer.readUTF8EncodedString();
} }
// check if the POI has an elevation // check if the POI has an elevation
@ -772,15 +776,6 @@ public class MapDatabase implements IMapDatabase {
private int stringOffset = -1; 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. * Processes the given number of ways.
* *

View File

@ -16,7 +16,7 @@ package org.mapsforge.database.mapfile.header;
import java.io.IOException; import java.io.IOException;
import org.mapsforge.database.FileOpenResult; import org.mapsforge.database.OpenResult;
import org.mapsforge.database.mapfile.ReadBuffer; import org.mapsforge.database.mapfile.ReadBuffer;
/** /**
@ -89,79 +89,79 @@ public class MapFileHeader {
* @throws IOException * @throws IOException
* if an error occurs while reading the file. * if an error occurs while reading the file.
*/ */
public FileOpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException { public OpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException {
FileOpenResult fileOpenResult = RequiredFields.readMagicByte(readBuffer); OpenResult openResult = RequiredFields.readMagicByte(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readRemainingHeader(readBuffer); openResult = RequiredFields.readRemainingHeader(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder(); MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder();
fileOpenResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder); openResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder); openResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder); openResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder); openResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
this.mapFileInfo = mapFileInfoBuilder.build(); 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) { MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of sub-files (1 byte) // get and check the number of sub-files (1 byte)
byte numberOfSubFiles = readBuffer.readByte(); byte numberOfSubFiles = readBuffer.readByte();
if (numberOfSubFiles < 1) { if (numberOfSubFiles < 1) {
return new FileOpenResult("invalid number of sub-files: " + numberOfSubFiles); return new OpenResult("invalid number of sub-files: " + numberOfSubFiles);
} }
mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles; mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;
@ -176,33 +176,33 @@ public class MapFileHeader {
// get and check the base zoom level (1 byte) // get and check the base zoom level (1 byte)
byte baseZoomLevel = readBuffer.readByte(); byte baseZoomLevel = readBuffer.readByte();
if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX) { 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; subFileParameterBuilder.baseZoomLevel = baseZoomLevel;
// get and check the minimum zoom level (1 byte) // get and check the minimum zoom level (1 byte)
byte zoomLevelMin = readBuffer.readByte(); byte zoomLevelMin = readBuffer.readByte();
if (zoomLevelMin < 0 || zoomLevelMin > 22) { if (zoomLevelMin < 0 || zoomLevelMin > 22) {
return new FileOpenResult("invalid minimum zoom level: " + zoomLevelMin); return new OpenResult("invalid minimum zoom level: " + zoomLevelMin);
} }
subFileParameterBuilder.zoomLevelMin = zoomLevelMin; subFileParameterBuilder.zoomLevelMin = zoomLevelMin;
// get and check the maximum zoom level (1 byte) // get and check the maximum zoom level (1 byte)
byte zoomLevelMax = readBuffer.readByte(); byte zoomLevelMax = readBuffer.readByte();
if (zoomLevelMax < 0 || zoomLevelMax > 22) { if (zoomLevelMax < 0 || zoomLevelMax > 22) {
return new FileOpenResult("invalid maximum zoom level: " + zoomLevelMax); return new OpenResult("invalid maximum zoom level: " + zoomLevelMax);
} }
subFileParameterBuilder.zoomLevelMax = zoomLevelMax; subFileParameterBuilder.zoomLevelMax = zoomLevelMax;
// check for valid zoom level range // check for valid zoom level range
if (zoomLevelMin > zoomLevelMax) { 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) // get and check the start address of the sub-file (8 bytes)
long startAddress = readBuffer.readLong(); long startAddress = readBuffer.readLong();
if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) { if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) {
return new FileOpenResult("invalid start address: " + startAddress); return new OpenResult("invalid start address: " + startAddress);
} }
subFileParameterBuilder.startAddress = startAddress; subFileParameterBuilder.startAddress = startAddress;
@ -216,7 +216,7 @@ public class MapFileHeader {
// get and check the size of the sub-file (8 bytes) // get and check the size of the sub-file (8 bytes)
long subFileSize = readBuffer.readLong(); long subFileSize = readBuffer.readLong();
if (subFileSize < 1) { if (subFileSize < 1) {
return new FileOpenResult("invalid sub-file size: " + subFileSize); return new OpenResult("invalid sub-file size: " + subFileSize);
} }
subFileParameterBuilder.subFileSize = subFileSize; subFileParameterBuilder.subFileSize = subFileSize;
@ -236,7 +236,7 @@ public class MapFileHeader {
this.subFileParameters[zoomLevel] = subFileParameter; this.subFileParameters[zoomLevel] = subFileParameter;
} }
} }
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
private void updateZoomLevelInformation(SubFileParameter subFileParameter) { private void updateZoomLevelInformation(SubFileParameter subFileParameter) {

View File

@ -20,9 +20,9 @@ import org.mapsforge.database.mapfile.MapDatabase;
/** /**
* Contains the immutable metadata of a map file. * 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. * True if the map file includes debug information, false otherwise.

View File

@ -15,7 +15,7 @@
package org.mapsforge.database.mapfile.header; package org.mapsforge.database.mapfile.header;
import org.mapsforge.core.GeoPoint; import org.mapsforge.core.GeoPoint;
import org.mapsforge.database.FileOpenResult; import org.mapsforge.database.OpenResult;
import org.mapsforge.database.mapfile.ReadBuffer; import org.mapsforge.database.mapfile.ReadBuffer;
final class OptionalFields { final class OptionalFields {
@ -59,15 +59,15 @@ final class OptionalFields {
*/ */
private static final int START_ZOOM_LEVEL_MAX = 22; 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()); OptionalFields optionalFields = new OptionalFields(readBuffer.readByte());
mapFileInfoBuilder.optionalFields = optionalFields; mapFileInfoBuilder.optionalFields = optionalFields;
FileOpenResult fileOpenResult = optionalFields.readOptionalFields(readBuffer); OpenResult openResult = optionalFields.readOptionalFields(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
String comment; String comment;
@ -91,63 +91,63 @@ final class OptionalFields {
this.hasCreatedBy = (flags & HEADER_BITMASK_CREATED_BY) != 0; this.hasCreatedBy = (flags & HEADER_BITMASK_CREATED_BY) != 0;
} }
private FileOpenResult readLanguagePreference(ReadBuffer readBuffer) { private OpenResult readLanguagePreference(ReadBuffer readBuffer) {
if (this.hasLanguagePreference) { if (this.hasLanguagePreference) {
String countryCode = readBuffer.readUTF8EncodedString(); String countryCode = readBuffer.readUTF8EncodedString();
if (countryCode.length() != LANGUAGE_PREFERENCE_LENGTH) { if (countryCode.length() != LANGUAGE_PREFERENCE_LENGTH) {
return new FileOpenResult("invalid language preference: " + countryCode); return new OpenResult("invalid language preference: " + countryCode);
} }
this.languagePreference = countryCode; this.languagePreference = countryCode;
} }
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
private FileOpenResult readMapStartPosition(ReadBuffer readBuffer) { private OpenResult readMapStartPosition(ReadBuffer readBuffer) {
if (this.hasStartPosition) { if (this.hasStartPosition) {
// get and check the start position latitude (4 byte) // get and check the start position latitude (4 byte)
int mapStartLatitude = readBuffer.readInt(); int mapStartLatitude = readBuffer.readInt();
if (mapStartLatitude < RequiredFields.LATITUDE_MIN || mapStartLatitude > RequiredFields.LATITUDE_MAX) { 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) // get and check the start position longitude (4 byte)
int mapStartLongitude = readBuffer.readInt(); int mapStartLongitude = readBuffer.readInt();
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN || mapStartLongitude > RequiredFields.LONGITUDE_MAX) { 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); 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) { if (this.hasStartZoomLevel) {
// get and check the start zoom level (1 byte) // get and check the start zoom level (1 byte)
byte mapStartZoomLevel = readBuffer.readByte(); byte mapStartZoomLevel = readBuffer.readByte();
if (mapStartZoomLevel < 0 || mapStartZoomLevel > START_ZOOM_LEVEL_MAX) { 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); this.startZoomLevel = Byte.valueOf(mapStartZoomLevel);
} }
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
private FileOpenResult readOptionalFields(ReadBuffer readBuffer) { private OpenResult readOptionalFields(ReadBuffer readBuffer) {
FileOpenResult fileOpenResult = readMapStartPosition(readBuffer); OpenResult openResult = readMapStartPosition(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = readMapStartZoomLevel(readBuffer); openResult = readMapStartZoomLevel(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
fileOpenResult = readLanguagePreference(readBuffer); openResult = readLanguagePreference(readBuffer);
if (!fileOpenResult.isSuccess()) { if (!openResult.isSuccess()) {
return fileOpenResult; return openResult;
} }
if (this.hasComment) { if (this.hasComment) {
@ -158,6 +158,6 @@ final class OptionalFields {
this.createdBy = readBuffer.readUTF8EncodedString(); this.createdBy = readBuffer.readUTF8EncodedString();
} }
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
} }

View File

@ -18,7 +18,7 @@ import java.io.IOException;
import org.mapsforge.core.BoundingBox; import org.mapsforge.core.BoundingBox;
import org.mapsforge.core.Tag; import org.mapsforge.core.Tag;
import org.mapsforge.database.FileOpenResult; import org.mapsforge.database.OpenResult;
import org.mapsforge.database.mapfile.ReadBuffer; import org.mapsforge.database.mapfile.ReadBuffer;
final class RequiredFields { final class RequiredFields {
@ -72,93 +72,93 @@ final class RequiredFields {
*/ */
static final int LONGITUDE_MIN = -180000000; 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) // get and check the minimum latitude (4 bytes)
int minLatitude = readBuffer.readInt(); int minLatitude = readBuffer.readInt();
if (minLatitude < LATITUDE_MIN || minLatitude > LATITUDE_MAX) { 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) // get and check the minimum longitude (4 bytes)
int minLongitude = readBuffer.readInt(); int minLongitude = readBuffer.readInt();
if (minLongitude < LONGITUDE_MIN || minLongitude > LONGITUDE_MAX) { 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) // get and check the maximum latitude (4 bytes)
int maxLatitude = readBuffer.readInt(); int maxLatitude = readBuffer.readInt();
if (maxLatitude < LATITUDE_MIN || maxLatitude > LATITUDE_MAX) { 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) // get and check the maximum longitude (4 bytes)
int maxLongitude = readBuffer.readInt(); int maxLongitude = readBuffer.readInt();
if (maxLongitude < LONGITUDE_MIN || maxLongitude > LONGITUDE_MAX) { 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 // check latitude and longitude range
if (minLatitude > maxLatitude) { 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) { } 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); 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) // get and check the file size (8 bytes)
long headerFileSize = readBuffer.readLong(); long headerFileSize = readBuffer.readLong();
if (headerFileSize != fileSize) { if (headerFileSize != fileSize) {
return new FileOpenResult("invalid file size: " + headerFileSize); return new OpenResult("invalid file size: " + headerFileSize);
} }
mapFileInfoBuilder.fileSize = fileSize; 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) // get and check the file version (4 bytes)
int fileVersion = readBuffer.readInt(); int fileVersion = readBuffer.readInt();
if (fileVersion != SUPPORTED_FILE_VERSION) { if (fileVersion != SUPPORTED_FILE_VERSION) {
return new FileOpenResult("unsupported file version: " + fileVersion); return new OpenResult("unsupported file version: " + fileVersion);
} }
mapFileInfoBuilder.fileVersion = 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 // read the the magic byte and the file header size into the buffer
int magicByteLength = BINARY_OSM_MAGIC_BYTE.length(); int magicByteLength = BINARY_OSM_MAGIC_BYTE.length();
if (!readBuffer.readFromFile(magicByteLength + 4)) { 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 // get and check the magic byte
String magicByte = readBuffer.readUTF8EncodedString(magicByteLength); String magicByte = readBuffer.readUTF8EncodedString(magicByteLength);
if (!BINARY_OSM_MAGIC_BYTE.equals(magicByte)) { 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) // get and check the the map date (8 bytes)
long mapDate = readBuffer.readLong(); long mapDate = readBuffer.readLong();
// is the map date before 2010-01-10 ? // is the map date before 2010-01-10 ?
if (mapDate < 1200000000000L) { if (mapDate < 1200000000000L) {
return new FileOpenResult("invalid map date: " + mapDate); return new OpenResult("invalid map date: " + mapDate);
} }
mapFileInfoBuilder.mapDate = 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) // get and check the number of POI tags (2 bytes)
int numberOfPoiTags = readBuffer.readShort(); int numberOfPoiTags = readBuffer.readShort();
if (numberOfPoiTags < 0) { 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]; Tag[] poiTags = new Tag[numberOfPoiTags];
@ -166,53 +166,53 @@ final class RequiredFields {
// get and check the POI tag // get and check the POI tag
String tag = readBuffer.readUTF8EncodedString(); String tag = readBuffer.readUTF8EncodedString();
if (tag == null) { 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); poiTags[currentTagId] = new Tag(tag);
} }
mapFileInfoBuilder.poiTags = poiTags; 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 // get and check the projection name
String projectionName = readBuffer.readUTF8EncodedString(); String projectionName = readBuffer.readUTF8EncodedString();
if (!MERCATOR.equals(projectionName)) { if (!MERCATOR.equals(projectionName)) {
return new FileOpenResult("unsupported projection: " + projectionName); return new OpenResult("unsupported projection: " + projectionName);
} }
mapFileInfoBuilder.projectionName = 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) // get and check the size of the remaining file header (4 bytes)
int remainingHeaderSize = readBuffer.readInt(); int remainingHeaderSize = readBuffer.readInt();
if (remainingHeaderSize < HEADER_SIZE_MIN || remainingHeaderSize > HEADER_SIZE_MAX) { 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 // read the header data into the buffer
if (!readBuffer.readFromFile(remainingHeaderSize)) { 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) // get and check the tile pixel size (2 bytes)
int tilePixelSize = readBuffer.readShort(); int tilePixelSize = readBuffer.readShort();
// if (tilePixelSize != Tile.TILE_SIZE) { // if (tilePixelSize != Tile.TILE_SIZE) {
// return new FileOpenResult("unsupported tile pixel size: " + tilePixelSize); // return new FileOpenResult("unsupported tile pixel size: " + tilePixelSize);
// } // }
mapFileInfoBuilder.tilePixelSize = 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) // get and check the number of way tags (2 bytes)
int numberOfWayTags = readBuffer.readShort(); int numberOfWayTags = readBuffer.readShort();
if (numberOfWayTags < 0) { 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]; Tag[] wayTags = new Tag[numberOfWayTags];
@ -221,12 +221,12 @@ final class RequiredFields {
// get and check the way tag // get and check the way tag
String tag = readBuffer.readUTF8EncodedString(); String tag = readBuffer.readUTF8EncodedString();
if (tag == null) { 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); wayTags[currentTagId] = new Tag(tag);
} }
mapFileInfoBuilder.wayTags = wayTags; mapFileInfoBuilder.wayTags = wayTags;
return FileOpenResult.SUCCESS; return OpenResult.SUCCESS;
} }
private RequiredFields() { private RequiredFields() {

View File

@ -58,10 +58,10 @@ import org.mapsforge.core.BoundingBox;
import org.mapsforge.core.GeoPoint; import org.mapsforge.core.GeoPoint;
import org.mapsforge.core.Tag; import org.mapsforge.core.Tag;
import org.mapsforge.core.Tile; import org.mapsforge.core.Tile;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.IMapDatabaseCallback; 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.mapsforge.database.QueryResult;
import android.os.Environment; import android.os.Environment;
@ -75,8 +75,8 @@ import android.util.Log;
public class MapDatabase implements IMapDatabase { public class MapDatabase implements IMapDatabase {
private static final String TAG = "MapDatabase"; private static final String TAG = "MapDatabase";
private static final MapFileInfo mMapInfo = private static final MapInfo mMapInfo =
new MapFileInfo(new BoundingBox(-180, -90, 180, 90), new MapInfo(new BoundingBox(-180, -90, 180, 90),
new Byte((byte) 4), new GeoPoint(53.11, 8.85), new Byte((byte) 4), new GeoPoint(53.11, 8.85),
null, 0, 0, 0, "de", "comment", "author"); null, 0, 0, 0, "de", "comment", "author");
@ -268,12 +268,12 @@ public class MapDatabase implements IMapDatabase {
} }
@Override @Override
public MapFileInfo getMapFileInfo() { public MapInfo getMapInfo() {
return mMapInfo; return mMapInfo;
} }
@Override @Override
public boolean hasOpenFile() { public boolean isOpen() {
return mOpenFile; return mOpenFile;
} }
@ -303,7 +303,7 @@ public class MapDatabase implements IMapDatabase {
} }
@Override @Override
public FileOpenResult openFile(File mapFile) { public OpenResult open(Map<String, String> options) {
if (USE_APACHE_HTTP) if (USE_APACHE_HTTP)
createClient(); createClient();
@ -322,11 +322,11 @@ public class MapDatabase implements IMapDatabase {
} }
} }
return new FileOpenResult(); return new OpenResult();
} }
@Override @Override
public void closeFile() { public void close() {
mOpenFile = false; mOpenFile = false;
if (USE_APACHE_HTTP) { if (USE_APACHE_HTTP) {
if (mClient != null) { 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) { private static File createDirectory(String pathName) {
File file = new File(pathName); File file = new File(pathName);
if (!file.exists() && !file.mkdirs()) { if (!file.exists() && !file.mkdirs()) {

View File

@ -14,13 +14,13 @@
*/ */
package org.mapsforge.database.postgis; package org.mapsforge.database.postgis;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; 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;
@ -29,10 +29,10 @@ import org.mapsforge.core.BoundingBox;
import org.mapsforge.core.GeoPoint; import org.mapsforge.core.GeoPoint;
import org.mapsforge.core.Tag; import org.mapsforge.core.Tag;
import org.mapsforge.core.WebMercator; import org.mapsforge.core.WebMercator;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.IMapDatabaseCallback; 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.mapsforge.database.QueryResult;
import org.postgresql.PGConnection; import org.postgresql.PGConnection;
@ -56,8 +56,8 @@ public class MapDatabase implements IMapDatabase {
private Tag[] mTags; private Tag[] mTags;
private final MapFileInfo mMapInfo = private final MapInfo mMapInfo =
new MapFileInfo(new BoundingBox(-180, -85, 180, 85), new MapInfo(new BoundingBox(-180, -85, 180, 85),
new Byte((byte) 14), new GeoPoint(53.11, 8.85), new Byte((byte) 14), new GeoPoint(53.11, 8.85),
WebMercator.NAME, WebMercator.NAME,
0, 0, 0, "de", "comment", "author"); 0, 0, 0, "de", "comment", "author");
@ -125,12 +125,12 @@ public class MapDatabase implements IMapDatabase {
byte[] b = null; byte[] b = null;
PGHStore h = null; PGHStore h = null;
int cnt = 0; // int cnt = 0;
try { try {
while (r != null && r.next()) { while (r != null && r.next()) {
mIndexPos = 0; mIndexPos = 0;
mCoordPos = 0; mCoordPos = 0;
cnt++; // cnt++;
try { try {
Object obj = r.getObject(1); Object obj = r.getObject(1);
h = null; h = null;
@ -200,27 +200,27 @@ public class MapDatabase implements IMapDatabase {
} }
@Override @Override
public MapFileInfo getMapFileInfo() { public MapInfo getMapInfo() {
return mMapInfo; return mMapInfo;
} }
@Override @Override
public boolean hasOpenFile() { public boolean isOpen() {
return mOpenFile; return mOpenFile;
} }
@Override @Override
public FileOpenResult openFile(File mapFile) { public OpenResult open(Map<String, String> options) {
mOpenFile = true; mOpenFile = true;
if (mCoords == null) { if (mCoords == null) {
mCoords = new float[100000]; mCoords = new float[100000];
mIndex = new short[100000]; mIndex = new short[100000];
} }
return new FileOpenResult(); return new OpenResult();
} }
@Override @Override
public void closeFile() { public void close() {
if (connection != null) { if (connection != null) {
try { try {
connection.close(); connection.close();
@ -235,11 +235,6 @@ public class MapDatabase implements IMapDatabase {
mOpenFile = false; mOpenFile = false;
} }
@Override
public String readString(int position) {
return null;
}
// taken from postgis-java // taken from postgis-java
private static ValueGetter valueGetterForEndian(byte[] bytes) { private static ValueGetter valueGetterForEndian(byte[] bytes) {
@ -258,6 +253,7 @@ public class MapDatabase implements IMapDatabase {
* *
* @param value * @param value
* ... * ...
* @return ...
*/ */
private boolean parse(byte[] value) { private boolean parse(byte[] value) {
return parseGeometry(valueGetterForEndian(value)); return parseGeometry(valueGetterForEndian(value));

View File

@ -14,17 +14,17 @@
*/ */
package org.mapsforge.database.test; package org.mapsforge.database.test;
import java.io.File; import java.util.Map;
import org.mapsforge.android.mapgenerator.JobTile; import org.mapsforge.android.mapgenerator.JobTile;
import org.mapsforge.core.BoundingBox; import org.mapsforge.core.BoundingBox;
import org.mapsforge.core.MercatorProjection; import org.mapsforge.core.MercatorProjection;
import org.mapsforge.core.Tag; import org.mapsforge.core.Tag;
import org.mapsforge.core.Tile; import org.mapsforge.core.Tile;
import org.mapsforge.database.FileOpenResult;
import org.mapsforge.database.IMapDatabase; import org.mapsforge.database.IMapDatabase;
import org.mapsforge.database.IMapDatabaseCallback; 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.mapsforge.database.QueryResult;
/** /**
@ -40,8 +40,8 @@ public class MapDatabase implements IMapDatabase {
private Tag[] mTags = { new Tag("natural", "water") }; private Tag[] mTags = { new Tag("natural", "water") };
private Tag[] mNameTags; private Tag[] mNameTags;
private final MapFileInfo mMapInfo = private final MapInfo mMapInfo =
new MapFileInfo(new BoundingBox(-180, -90, 180, 90), new MapInfo(new BoundingBox(-180, -90, 180, 90),
new Byte((byte) 0), null, PROJECTION, 0, 0, 0, "de", "yo!", "by me"); new Byte((byte) 0), null, PROJECTION, 0, 0, 0, "de", "yo!", "by me");
private boolean mOpenFile = false; private boolean mOpenFile = false;
@ -163,31 +163,26 @@ public class MapDatabase implements IMapDatabase {
} }
@Override @Override
public MapFileInfo getMapFileInfo() { public MapInfo getMapInfo() {
return mMapInfo; return mMapInfo;
} }
@Override @Override
public boolean hasOpenFile() { public boolean isOpen() {
return mOpenFile; return mOpenFile;
} }
@Override @Override
public FileOpenResult openFile(File mapFile) { public OpenResult open(Map<String, String> options) {
mOpenFile = true; mOpenFile = true;
return new FileOpenResult(); return new OpenResult();
} }
@Override @Override
public void closeFile() { public void close() {
mOpenFile = false; mOpenFile = false;
} }
@Override
public String readString(int position) {
return null;
}
@Override @Override
public void cancel() { public void cancel() {
// TODO Auto-generated method stub // TODO Auto-generated method stub