TileMapApp: improve POI overlays

This commit is contained in:
Hannes Janetzek 2012-10-30 11:56:46 +01:00
parent cbceb2c6e9
commit 0eda94864f
6 changed files with 67 additions and 86 deletions

29
AndroidManifest.xml Executable file → Normal file
View File

@ -7,39 +7,10 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk <uses-sdk
android:minSdkVersion="10" android:minSdkVersion="10"
android:targetSdkVersion="10" /> android:targetSdkVersion="10" />
<application
android:name="org.oscim.app.App"
android:icon="@drawable/globe2"
android:label="@string/application_name"
android:theme="@android:style/Theme.NoTitleBar"
android:hardwareAccelerated="false">
<!-- android:theme="@style/Theme.TileMap" -->
<activity
android:name="TileMap"
android:configChanges="orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".preferences.EditPreferences" />
<activity android:name=".filepicker.FilePicker" />
<activity android:name=".InfoView" />
<activity
android:name=".POIActivity"
android:label="@string/application_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
/>
</application>
</manifest> </manifest>

View File

@ -20,7 +20,6 @@ import android.view.MotionEvent;
* {@link android.view.GestureDetector.SimpleOnGestureListener} and * {@link android.view.GestureDetector.SimpleOnGestureListener} and
* GestureDetector.OnGestureListener. The difference is there is an additional * GestureDetector.OnGestureListener. The difference is there is an additional
* argument for the item. * argument for the item.
*
* @author Nicolas Gramlich * @author Nicolas Gramlich
*/ */
public abstract class Overlay implements OverlayConstants { public abstract class Overlay implements OverlayConstants {
@ -79,7 +78,6 @@ public abstract class Overlay implements OverlayConstants {
/** /**
* Sets whether the Overlay is marked to be enabled. This setting does * Sets whether the Overlay is marked to be enabled. This setting does
* nothing by default, but should be checked before calling draw(). * nothing by default, but should be checked before calling draw().
*
* @param pEnabled * @param pEnabled
* ... * ...
*/ */
@ -90,7 +88,6 @@ public abstract class Overlay implements OverlayConstants {
/** /**
* Specifies if the Overlay is marked to be enabled. This should be checked * Specifies if the Overlay is marked to be enabled. This should be checked
* before calling draw(). * before calling draw().
*
* @return true if the Overlay is marked enabled, false otherwise * @return true if the Overlay is marked enabled, false otherwise
*/ */
public boolean isEnabled() { public boolean isEnabled() {
@ -102,7 +99,6 @@ public abstract class Overlay implements OverlayConstants {
* IDs cannot be fixed at compile time. Overlays should use this method to * IDs cannot be fixed at compile time. Overlays should use this method to
* obtain and store a menu id for each menu item at construction time. This * obtain and store a menu id for each menu item at construction time. This
* will ensure that two overlays don't use the same id. * will ensure that two overlays don't use the same id.
*
* @return an integer suitable to be used as a menu identifier * @return an integer suitable to be used as a menu identifier
*/ */
protected final static int getSafeMenuId() { protected final static int getSafeMenuId() {
@ -113,7 +109,6 @@ public abstract class Overlay implements OverlayConstants {
* Similar to <see cref="getSafeMenuId" />, except this reserves a sequence * Similar to <see cref="getSafeMenuId" />, except this reserves a sequence
* of IDs of length <param name="count" />. The returned number is the * of IDs of length <param name="count" />. The returned number is the
* starting index of that sequential list. * starting index of that sequential list.
*
* @param count * @param count
* .... * ....
* @return an integer suitable to be used as a menu identifier * @return an integer suitable to be used as a menu identifier
@ -148,7 +143,6 @@ public abstract class Overlay implements OverlayConstants {
/** /**
* Override to perform clean up of resources before shutdown. By default * Override to perform clean up of resources before shutdown. By default
* does nothing. * does nothing.
*
* @param mapView * @param mapView
* ... * ...
*/ */
@ -160,7 +154,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param keyCode * @param keyCode
* ... * ...
* @param event * @param event
@ -178,7 +171,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param keyCode * @param keyCode
* ... * ...
* @param event * @param event
@ -197,7 +189,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -213,7 +204,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -231,7 +221,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -247,7 +236,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -263,7 +251,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -281,7 +268,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -297,7 +283,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param pEvent1 * @param pEvent1
* ... * ...
* @param pEvent2 * @param pEvent2
@ -320,7 +305,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -336,7 +320,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param pEvent1 * @param pEvent1
* ... * ...
* @param pEvent2 * @param pEvent2
@ -369,7 +352,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link MapView} has the chance to handle this event.
*
* @param e * @param e
* ... * ...
* @param mapView * @param mapView
@ -383,8 +365,9 @@ public abstract class Overlay implements OverlayConstants {
/** /**
* @param mapPosition * @param mapPosition
* current MapPosition * current MapPosition
* @param changed ...
*/ */
public void onUpdate(MapPosition mapPosition) { public void onUpdate(MapPosition mapPosition, boolean changed) {
} }
@ -429,7 +412,6 @@ public abstract class Overlay implements OverlayConstants {
/** /**
* Checks to see if the given x and y are close enough to an item * Checks to see if the given x and y are close enough to an item
* resulting in snapping the current action (e.g. zoom) to the item. * resulting in snapping the current action (e.g. zoom) to the item.
*
* @param x * @param x
* The x in screen coordinates. * The x in screen coordinates.
* @param y * @param y

View File

@ -26,32 +26,36 @@ public class OverlayManager extends AbstractList<Overlay> {
// final TilesOverlay tilesOverlay) { // final TilesOverlay tilesOverlay) {
// setTilesOverlay(tilesOverlay); // setTilesOverlay(tilesOverlay);
mOverlayList = new CopyOnWriteArrayList<Overlay>(); mOverlayList = new CopyOnWriteArrayList<Overlay>();
} }
@Override @Override
public Overlay get(final int pIndex) { public synchronized Overlay get(final int pIndex) {
return mOverlayList.get(pIndex); return mOverlayList.get(pIndex);
} }
@Override @Override
public int size() { public synchronized int size() {
return mOverlayList.size(); return mOverlayList.size();
} }
@Override @Override
public void add(final int pIndex, final Overlay pElement) { public synchronized void add(final int pIndex, final Overlay pElement) {
mOverlayList.add(pIndex, pElement); mOverlayList.add(pIndex, pElement);
mUpdateDrawLayers = true;
mUpdateLayers = true; mUpdateLayers = true;
} }
@Override @Override
public Overlay remove(final int pIndex) { public synchronized Overlay remove(final int pIndex) {
mUpdateDrawLayers = true;
mUpdateLayers = true; mUpdateLayers = true;
return mOverlayList.remove(pIndex); return mOverlayList.remove(pIndex);
} }
@Override @Override
public Overlay set(final int pIndex, final Overlay pElement) { public synchronized Overlay set(final int pIndex, final Overlay pElement) {
mUpdateDrawLayers = true;
mUpdateLayers = true; mUpdateLayers = true;
return mOverlayList.set(pIndex, pElement); return mOverlayList.set(pIndex, pElement);
} }
@ -106,13 +110,14 @@ public class OverlayManager extends AbstractList<Overlay> {
} }
private boolean mUpdateLayers; private boolean mUpdateLayers;
private boolean mUpdateDrawLayers;
private List<RenderOverlay> mDrawLayers = new ArrayList<RenderOverlay>(); private List<RenderOverlay> mDrawLayers = new ArrayList<RenderOverlay>();
public List<RenderOverlay> getRenderLayers() { public List<RenderOverlay> getRenderLayers() {
if (mUpdateLayers) { if (mUpdateDrawLayers) {
synchronized (this) { synchronized (this) {
mUpdateLayers = false; mUpdateDrawLayers = false;
mDrawLayers.clear(); mDrawLayers.clear();
for (Overlay o : mOverlayList) { for (Overlay o : mOverlayList) {
@ -158,12 +163,21 @@ public class OverlayManager extends AbstractList<Overlay> {
} }
} }
Overlay[] mOverlays;
private synchronized void updateOverlays() {
mOverlays = new Overlay[mOverlayList.size()];
mOverlays = mOverlayList.toArray(mOverlays);
mUpdateLayers = false;
}
public boolean onKeyDown(final int keyCode, final KeyEvent event, final MapView pMapView) { public boolean onKeyDown(final int keyCode, final KeyEvent event, final MapView pMapView) {
for (final Overlay overlay : this.overlaysReversed()) { if (mUpdateLayers)
if (overlay.onKeyDown(keyCode, event, pMapView)) { updateOverlays();
for (int i = mOverlays.length - 1; i >= 0; i--)
if (mOverlays[i].onKeyDown(keyCode, event, pMapView))
return true; return true;
}
}
return false; return false;
} }
@ -294,19 +308,32 @@ public class OverlayManager extends AbstractList<Overlay> {
} }
public boolean onSingleTapUp(final MotionEvent pEvent, final MapView pMapView) { public boolean onSingleTapUp(final MotionEvent pEvent, final MapView pMapView) {
for (final Overlay overlay : this.overlaysReversed()) { if (mUpdateLayers)
if (overlay.onSingleTapUp(pEvent, pMapView)) { updateOverlays();
for (int i = mOverlays.length - 1; i >= 0; i--)
if (mOverlays[i].onSingleTapUp(pEvent, pMapView))
return true; return true;
}
} // for (final Overlay overlay : this.overlaysReversed()) {
// if (overlay.onSingleTapUp(pEvent, pMapView)) {
// return true;
// }
// }
return false; return false;
} }
public void onUpdate(MapPosition mapPosition) { public void onUpdate(MapPosition mapPosition, boolean changed) {
for (final Overlay overlay : this.overlaysReversed()) { if (mUpdateLayers)
overlay.onUpdate(mapPosition); updateOverlays();
}
for (int i = mOverlays.length - 1; i >= 0; i--)
mOverlays[i].onUpdate(mapPosition, changed);
// for (final Overlay overlay : this.overlaysReversed()) {
// overlay.onUpdate(mapPosition);
// }
} }
// ** Options Menu **// // ** Options Menu **//

View File

@ -410,10 +410,10 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mLevels = TileGenerator.renderTheme.getLevels(); mLevels = TileGenerator.renderTheme.getLevels();
// limit stroke scale at z=17 // limit stroke scale at z=17
if (tile.zoomLevel < STROKE_MAX_ZOOM_LEVEL) // if (tile.zoomLevel < STROKE_MAX_ZOOM_LEVEL)
setScaleStrokeWidth(tile.zoomLevel); setScaleStrokeWidth(tile.zoomLevel);
else // else
setScaleStrokeWidth(STROKE_MAX_ZOOM_LEVEL); // setScaleStrokeWidth(STROKE_MAX_ZOOM_LEVEL);
// acount for area changes with latitude // acount for area changes with latitude
mProjectionScaleFactor = 0.5f + 0.5f * ( mProjectionScaleFactor = 0.5f + 0.5f * (
@ -466,7 +466,6 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
/** /**
* Sets the scale stroke factor for the given zoom level. * Sets the scale stroke factor for the given zoom level.
*
* @param zoomLevel * @param zoomLevel
* the zoom level for which the scale stroke factor should be * the zoom level for which the scale stroke factor should be
* set. * set.

View File

@ -26,6 +26,7 @@ import org.oscim.renderer.layer.VertexPool;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import org.oscim.view.MapViewPosition; import org.oscim.view.MapViewPosition;
import android.util.FloatMath;
import android.util.Log; import android.util.Log;
public class TileManager { public class TileManager {
@ -155,7 +156,6 @@ public class TileManager {
* Update list of visible tiles and passes them to TileManager, when not * Update list of visible tiles and passes them to TileManager, when not
* available tiles are created and added to JobQueue (mapView.addJobs) for * available tiles are created and added to JobQueue (mapView.addJobs) for
* loading by TileGenerator class * loading by TileGenerator class
*
* @param clear * @param clear
* whether to clear and reload all tiles * whether to clear and reload all tiles
*/ */
@ -292,7 +292,6 @@ public class TileManager {
/** /**
* set mNewTiles for the visible tiles and pass it to GLRenderer, add jobs * set mNewTiles for the visible tiles and pass it to GLRenderer, add jobs
* for not yet loaded tiles * for not yet loaded tiles
*
* @param mapPosition * @param mapPosition
* the current MapPosition * the current MapPosition
* @param zdir * @param zdir
@ -487,8 +486,8 @@ public class TileManager {
dy = (t.pixelY + h) - y; dy = (t.pixelY + h) - y;
dx %= center; dx %= center;
dy %= center; dy %= center;
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; t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * 0.25f;
} else if (diff > 0) { } else if (diff > 0) {
// tile zoom level is child of current // tile zoom level is child of current
@ -502,8 +501,8 @@ public class TileManager {
} }
dx %= center; dx %= center;
dy %= center; dy %= center;
t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)); //t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy));
// t.distance = FloatMath.sqrt((dx * dx + dy * dy)); t.distance = FloatMath.sqrt((dx * dx + dy * dy));
} else { } else {
// tile zoom level is parent of current // tile zoom level is parent of current
@ -511,8 +510,8 @@ public class TileManager {
dy = ((t.pixelY + h) << -diff) - y; dy = ((t.pixelY + h) << -diff) - y;
dx %= center; dx %= center;
dy %= center; dy %= center;
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); t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * (-diff * 0.5f);
} }
} }
} }
@ -609,7 +608,6 @@ public class TileManager {
/** /**
* called from MapWorker Thread when tile is loaded by TileGenerator * called from MapWorker Thread when tile is loaded by TileGenerator
*
* @param jobTile * @param jobTile
* ... * ...
* @return ... * @return ...

View File

@ -75,6 +75,7 @@ public class MapView extends RelativeLayout {
public boolean enableCompass = false; public boolean enableCompass = false;
private final MapViewPosition mMapViewPosition; private final MapViewPosition mMapViewPosition;
private final MapPosition mMapPosition;
private final MapZoomControls mMapZoomControls; private final MapZoomControls mMapZoomControls;
@ -148,6 +149,7 @@ public class MapView extends RelativeLayout {
mMapDatabaseType = mapDatabaseType; mMapDatabaseType = mapDatabaseType;
mMapViewPosition = new MapViewPosition(this); mMapViewPosition = new MapViewPosition(this);
mMapPosition = new MapPosition();
mOverlayManager = new OverlayManager(); mOverlayManager = new OverlayManager();
@ -239,7 +241,7 @@ public class MapView extends RelativeLayout {
// // pathOverlay.addPoint(new GeoPoint(53.067221, 8.78767)); // // pathOverlay.addPoint(new GeoPoint(53.067221, 8.78767));
// mOverlayManager.add(pathOverlay); // mOverlayManager.add(pathOverlay);
mMapViewPosition.animateTo(new GeoPoint(53.067221, 8.78767)); // mMapViewPosition.animateTo(new GeoPoint(53.067221, 8.78767));
} }
public void render() { public void render() {
@ -302,9 +304,11 @@ public class MapView extends RelativeLayout {
if (mPausing || this.getWidth() == 0 || this.getHeight() == 0) if (mPausing || this.getWidth() == 0 || this.getHeight() == 0)
return; return;
if (AndroidUtils.currentThreadIsUiThread()) if (AndroidUtils.currentThreadIsUiThread()) {
mOverlayManager.onUpdate(mMapViewPosition.getMapPosition()); boolean changed = mMapViewPosition.getMapPosition(mMapPosition, null);
mOverlayManager.onUpdate(mMapPosition, changed);
}
mTileManager.updateMap(false); mTileManager.updateMap(false);
} }