keep mapfile-writer/db from bit-rotting

This commit is contained in:
Hannes Janetzek
2012-09-19 00:42:49 +02:00
parent 19344e39cf
commit 4a5142fdf6
8 changed files with 203 additions and 103 deletions

View File

@@ -49,24 +49,17 @@ import android.view.MotionEvent;
import android.widget.FrameLayout;
/**
* 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.
* 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.
*/
public class MapView extends FrameLayout {
final static String TAG = "MapView";
/**
* Default render theme of the MapView.
*/
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
// private static final float DEFAULT_TEXT_SCALE = 1;
// private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
public final static boolean debugFrameTime = false;
public final static boolean testRegionZoom = false;
private final boolean mDebugDatabase = false;
RegionLookup mRegionLookup;
public boolean enableRotation = false;
@@ -94,7 +87,8 @@ public class MapView extends FrameLayout {
* @param context
* the enclosing MapActivity instance.
* @throws IllegalArgumentException
* if the context object is not an instance of {@link MapActivity} .
* if the context object is not an instance of
* {@link MapActivity} .
*/
public MapView(Context context) {
this(context, null, MapDatabases.MAP_READER);
@@ -106,14 +100,13 @@ public class MapView extends FrameLayout {
* @param attributeSet
* a set of attributes.
* @throws IllegalArgumentException
* if the context object is not an instance of {@link MapActivity} .
* if the context object is not an instance of
* {@link MapActivity} .
*/
public MapView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, MapDatabaseFactory.getMapDatabase(attributeSet));
}
private boolean mDebugDatabase = false;
private MapView(Context context, AttributeSet attributeSet,
MapDatabases mapDatabaseType) {
@@ -150,8 +143,11 @@ public class MapView extends FrameLayout {
for (int i = 0; i < mNumMapWorkers; i++) {
IMapDatabase mapDatabase;
if (mDebugDatabase) {
// mapDatabase = MapDatabaseFactory
// .createMapDatabase(MapDatabases.TEST_READER);
mapDatabase = MapDatabaseFactory
.createMapDatabase(MapDatabases.TEST_READER);
.createMapDatabase(MapDatabases.MAP_READER);
mNumMapWorkers = 1;
} else {
mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseType);
}
@@ -392,7 +388,8 @@ public class MapView extends FrameLayout {
* @throws IllegalArgumentException
* if the supplied internalRenderTheme is null.
* @throws FileNotFoundException
* if the supplied file does not exist, is a directory or cannot be read.
* if the supplied file does not exist, is a directory or cannot
* be read.
*/
public void setRenderTheme(String renderThemePath) throws FileNotFoundException {
if (renderThemePath == null) {
@@ -505,7 +502,8 @@ public class MapView extends FrameLayout {
}
/**
* @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() {
MapInfo mapInfo;
@@ -639,7 +637,8 @@ public class MapView extends FrameLayout {
// }
// /**
// * Sets the text scale for the map rendering. Has no effect in downloading mode.
// * Sets the text scale for the map rendering. Has no effect in downloading
// mode.
// *
// * @param textScale
// * the new text scale for the map rendering.

View File

@@ -102,7 +102,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// lock to synchronize Main- and GL-Thread
static ReentrantLock tilelock = new ReentrantLock();
// used for passing tiles to be rendered from TileLoader(Main-Thread) to GLThread
// used for passing tiles to be rendered from TileLoader(Main-Thread) to
// GLThread
static class TilesData {
int cnt = 0;
final MapTile[] tiles;
@@ -337,7 +338,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
ShortBuffer sbuf = null;
// use multiple buffers to avoid overwriting buffer while current
// data is uploaded (or rather the blocking which is probably done to avoid this)
// data is uploaded (or rather the blocking which is probably done to
// avoid this)
if (uploadCnt >= rotateBuffers) {
uploadCnt = 0;
GLES20.glFlush();
@@ -453,7 +455,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// on HTC it causes oom exception?!
// glBindBuffer(GL_ARRAY_BUFFER, vbo.id);
// glBufferData(GL_ARRAY_BUFFER, 0, null, GLES20.GL_STATIC_DRAW);
// glBufferData(GL_ARRAY_BUFFER, 0, null,
// GLES20.GL_STATIC_DRAW);
// recreate vbo instead
buf[0] = vbo.id;
@@ -581,7 +584,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
}
}
// proxies are clipped to the region where nothing was drawn to depth buffer
// proxies are clipped to the region where nothing was drawn to depth
// buffer
// TODO draw all parent before grandparent
for (int i = 0; i < tileCnt; i++) {
if (tiles[i].isVisible && !tiles[i].isReady) {
@@ -819,12 +823,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
mMapView.redrawMap();
}
void clearTiles() {
int numTiles = (mWidth / (Tile.TILE_SIZE / 2) + 2)
* (mHeight / (Tile.TILE_SIZE / 2) + 2);
Log.d(TAG, "clearTiles " + numTiles);
void clearTiles(int numTiles) {
drawTiles = new TilesData(numTiles);
curTiles = new TilesData(numTiles);
}

View File

@@ -20,6 +20,7 @@ import java.util.Collections;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import org.oscim.core.Tile;
import org.oscim.database.MapInfo;
import org.oscim.theme.RenderTheme;
import org.oscim.utils.GlConfigChooser;
import org.oscim.view.MapView;
@@ -58,7 +59,11 @@ public class MapRenderer extends GLSurfaceView {
// private static MapPosition mCurPosition, mDrawPosition;
private static int mWidth = 0, mHeight = 0;
private static TilesData newTiles;
private static TilesData mCurrentTiles;
// map zoom-level to available zoom-levels in MapDatabase
// e.g. 16->16, 15->16, 14->13, 13->13, 12->13,....
private static int[] mZoomLevels;
public MapRenderer(Context context, MapView mapView) {
super(context);
@@ -90,8 +95,9 @@ public class MapRenderer extends GLSurfaceView {
* called by MapView when position or map settings changes
*/
/**
* Update list of visible tiles and passes them to MapRenderer, when not available tiles are created and added to
* JobQueue (mapView.addJobs) for loading by TileGenerator class
* Update list of visible tiles and passes them to MapRenderer, when not
* available tiles are created and added to JobQueue (mapView.addJobs) for
* loading by MapGenerator class
*
* @param clear
* ...
@@ -108,33 +114,35 @@ public class MapRenderer extends GLSurfaceView {
MapPosition mapPosition = mMapView.getMapPosition().getMapPosition();
if (mapPosition == null) {
Log.d(TAG, ">>> no map position");
Log.d(TAG, "X no map position");
return;
}
if (clear) {
// remove all tiles references
Log.d(TAG, "CLEAR");
synchronized (GLRenderer.lock) {
for (MapTile t : mTiles)
clearTile(t);
mTiles.clear();
mTilesLoaded.clear();
QuadTree.init();
}
mInitial = true;
// FIXME still needed?
GLRenderer.tilelock.lock();
for (MapTile t : mTiles)
clearTile(t);
mTiles.clear();
mTilesLoaded.clear();
QuadTree.init();
GLRenderer.tilelock.unlock();
}
if (mInitial) {
mRenderer.clearTiles();
// set up TileData arrays that are passed to gl-thread
int numTiles = (mWidth / (Tile.TILE_SIZE / 2) + 2)
* (mHeight / (Tile.TILE_SIZE / 2) + 2);
Log.d(TAG, "newTiles: " + numTiles);
newTiles = new TilesData(numTiles);
mRenderer.clearTiles(numTiles);
mCurrentTiles = new TilesData(numTiles);
MapInfo mapInfo = mMapView.getMapDatabase().getMapInfo();
if (mapInfo != null)
mZoomLevels = mapInfo.zoomLevel;
}
byte zoomLevel = mapPosition.zoomLevel;
@@ -197,7 +205,16 @@ public class MapRenderer extends GLSurfaceView {
}
private static boolean updateVisibleList(MapPosition mapPosition, int zdir) {
/**
* set mCurrentTiles for the visible tiles and pass it to GLRenderer, add
* jobs for not yet loaded tiles
*
* @param mapPosition
* the current MapPosition
* @param zdir
* zoom direction
*/
private static void updateVisibleList(MapPosition mapPosition, int zdir) {
double x = mapPosition.x;
double y = mapPosition.y;
byte zoomLevel = mapPosition.zoomLevel;
@@ -223,12 +240,28 @@ public class MapRenderer extends GLSurfaceView {
mMapView.addJobs(null);
int tiles = 0;
if (newTiles == null)
return false;
int max = mCurrentTiles.tiles.length - 1;
int max = newTiles.tiles.length - 1;
boolean fetchChildren = false;
boolean fetchParent = false;
boolean fetchProxy = false;
if (mZoomLevels != null) {
// check MapDatabase zoom-level-mapping
if (mZoomLevels[zoomLevel] == 0) {
mCurrentTiles.cnt = 0;
mCurrentTiles = GLRenderer.updateTiles(mapPosition, mCurrentTiles);
return;
}
boolean prefetchChildren = true;
if (mZoomLevels[zoomLevel] > zoomLevel) {
fetchChildren = true;
fetchProxy = true;
}
else if (mZoomLevels[zoomLevel] < zoomLevel) {
fetchParent = true;
fetchProxy = true;
}
}
for (int yy = tileTop; yy <= tileBottom; yy++) {
for (int xx = tileLeft; xx <= tileRight; xx++) {
@@ -245,17 +278,34 @@ public class MapRenderer extends GLSurfaceView {
mTiles.add(tile);
}
newTiles.tiles[tiles++] = tile;
mCurrentTiles.tiles[tiles++] = tile;
if (prefetchChildren) {
}
if (!(tile.isLoading || tile.newData || tile.isReady)) {
if (!fetchProxy && !(tile.isLoading || tile.newData || tile.isReady)) {
mJobList.add(tile);
}
if (zdir > 0 && zoomLevel > 0) {
if (fetchChildren) {
byte z = (byte) (zoomLevel + 1);
for (int i = 0; i < 4; i++) {
int cx = (xx << 1) + (i % 2);
int cy = (yy << 1) + (i >> 1);
MapTile c = QuadTree.getTile(cx, cy, z);
if (c == null) {
c = new MapTile(cx, cy, z);
QuadTree.add(c);
mTiles.add(c);
}
if (!(c.isLoading || c.newData || c.isReady)) {
mJobList.add(c);
}
}
}
if (fetchParent || (!fetchProxy && zdir > 0 && zoomLevel > 0)) {
// prefetch parent
MapTile parent = tile.rel.parent.tile;
@@ -275,8 +325,8 @@ public class MapRenderer extends GLSurfaceView {
}
// pass new tile list to glThread
newTiles.cnt = tiles;
newTiles = GLRenderer.updateTiles(mapPosition, newTiles);
mCurrentTiles.cnt = tiles;
mCurrentTiles = GLRenderer.updateTiles(mapPosition, mCurrentTiles);
// note: this sets isLoading == true for all job tiles
if (mJobList.size() > 0) {
@@ -284,8 +334,6 @@ public class MapRenderer extends GLSurfaceView {
Collections.sort(mJobList);
mMapView.addJobs(mJobList);
}
return true;
}
private static void clearTile(MapTile t) {
@@ -311,10 +359,6 @@ public class MapRenderer extends GLSurfaceView {
QuadTree.remove(t);
}
// private static boolean tileInUse(MapTile t) {
// return (t.isActive || t.refs != 0);
// }
private static void updateTileDistances(ArrayList<?> tiles,
MapPosition mapPosition) {
int h = (Tile.TILE_SIZE >> 1);
@@ -335,7 +379,8 @@ public class MapRenderer extends GLSurfaceView {
if (diff == 0) {
dx = (t.pixelX + h) - x;
dy = (t.pixelY + h) - y;
// t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * 0.25f;
// t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) *
// 0.25f;
t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * 0.25f;
} else if (diff > 0) {
// tile zoom level is child of current
@@ -356,7 +401,8 @@ public class MapRenderer extends GLSurfaceView {
dx = ((t.pixelX + h) << -diff) - x;
dy = ((t.pixelY + h) << -diff) - y;
// t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * (-diff * 0.5f);
// t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) *
// (-diff * 0.5f);
t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * (-diff * 0.5f);
}
}
@@ -455,7 +501,8 @@ public class MapRenderer extends GLSurfaceView {
}
if (t.isLocked()) {
// Log.d(TAG, "keep unused tile data: " + t + " " + t.isActive);
// Log.d(TAG, "keep unused tile data: " + t + " " +
// t.isActive);
i++;
continue;
}
@@ -480,7 +527,8 @@ public class MapRenderer extends GLSurfaceView {
MapTile tile = (MapTile) jobTile;
if (!tile.isLoading) {
// no one should be able to use this tile now, mapgenerator passed it,
// no one should be able to use this tile now, mapgenerator passed
// it,
// glthread does nothing until newdata is set.
Log.d(TAG, "passTile: canceled " + tile);
synchronized (mTilesLoaded) {

View File

@@ -246,7 +246,8 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
@Override
public void renderPointOfInterestCaption(Caption caption) {
// Log.d(TAG, "renderPointOfInterestCaption: " + mPoiX + " " + mPoiY + " "
// Log.d(TAG, "renderPointOfInterestCaption: " + mPoiX + " " + mPoiY +
// " "
// + mTagName);
if (mTagName == null)
@@ -266,7 +267,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
if (mTagName == null)
return;
if (pathText.textKey == mTagEmptyName.key) {
if (pathText.textKey == mTagEmptyName.key && mTagName.value != null) {
mLabels = WayDecorator.renderText(mCoords, mTagName.value, pathText, 0,
mIndices[0], mLabels);
@@ -509,7 +510,8 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
* Sets the scale stroke factor for the given zoom level.
*
* @param zoomLevel
* the zoom level for which the scale stroke factor should be set.
* the zoom level for which the scale stroke factor should be
* set.
*/
private void setScaleStrokeWidth(byte zoomLevel) {
int zoomLevelDiff = Math.max(zoomLevel - STROKE_MIN_ZOOM_LEVEL, 0);