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.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="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>

View File

@ -20,7 +20,6 @@ import android.view.MotionEvent;
* {@link android.view.GestureDetector.SimpleOnGestureListener} and
* GestureDetector.OnGestureListener. The difference is there is an additional
* argument for the item.
*
* @author Nicolas Gramlich
*/
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
* nothing by default, but should be checked before calling draw().
*
* @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
* before calling draw().
*
* @return true if the Overlay is marked enabled, false otherwise
*/
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
* 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.
*
* @return an integer suitable to be used as a menu identifier
*/
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
* of IDs of length <param name="count" />. The returned number is the
* starting index of that sequential list.
*
* @param count
* ....
* @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
* does nothing.
*
* @param mapView
* ...
*/
@ -160,7 +154,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param keyCode
* ...
* @param event
@ -178,7 +171,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param keyCode
* ...
* @param event
@ -197,7 +189,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -213,7 +204,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -231,7 +221,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -247,7 +236,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -263,7 +251,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -281,7 +268,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -297,7 +283,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param pEvent1
* ...
* @param pEvent2
@ -320,7 +305,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -336,7 +320,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param pEvent1
* ...
* @param pEvent2
@ -369,7 +352,6 @@ public abstract class Overlay implements OverlayConstants {
* Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event.
*
* @param e
* ...
* @param mapView
@ -383,8 +365,9 @@ public abstract class Overlay implements OverlayConstants {
/**
* @param 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
* resulting in snapping the current action (e.g. zoom) to the item.
*
* @param x
* The x in screen coordinates.
* @param y

View File

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

View File

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

View File

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

View File

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