diff --git a/vtm-android-example/res/layout/activity_map.xml b/vtm-android-example/res/layout/activity_map.xml index 9be443dc..ea4c4470 100644 --- a/vtm-android-example/res/layout/activity_map.xml +++ b/vtm-android-example/res/layout/activity_map.xml @@ -3,7 +3,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - diff --git a/vtm-android-example/src/org/oscim/android/test/MapActivity.java b/vtm-android-example/src/org/oscim/android/test/MapActivity.java index c3f3ba05..fead12a1 100644 --- a/vtm-android-example/src/org/oscim/android/test/MapActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/MapActivity.java @@ -1,6 +1,6 @@ package org.oscim.android.test; -import org.oscim.android.AndroidMapView; +import org.oscim.android.MapView; import org.oscim.layers.labeling.LabelLayer; import org.oscim.layers.overlay.BuildingOverlay; import org.oscim.layers.tile.vector.MapTileLayer; @@ -13,38 +13,38 @@ import android.view.Menu; public class MapActivity extends org.oscim.android.MapActivity { - private AndroidMapView mAndroidMapView; + private MapView mMapView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); - mAndroidMapView = (AndroidMapView) findViewById(R.id.mapView); + mMapView = (MapView) findViewById(R.id.mapView); - //mMap = mMapView.getMap(); + //mMap = mMap.getMap(); //TileSource tileSource = new OSciMap2TileSource(); //tileSource.setOption("url", "http://city.informatik.uni-bremen.de/osci/map-live"); TileSource tileSource = new OSciMap4TileSource(); tileSource.setOption("url", "http://city.informatik.uni-bremen.de/tiles/vtm"); - MapTileLayer l = mMapView.setBaseMap(tileSource); - //mMapView.setDebugSettings(new DebugSettings(false, false, true, false, false)); + MapTileLayer l = mMap.setBaseMap(tileSource); + //mMap.setDebugSettings(new DebugSettings(false, false, true, false, false)); - mMapView.getLayerManager().add(new BuildingOverlay(mMapView, l.getTileLayer())); - mMapView.getLayerManager().add(new LabelLayer(mMapView, l.getTileLayer())); + mMap.getLayerManager().add(new BuildingOverlay(mMap, l.getTileLayer())); + mMap.getLayerManager().add(new LabelLayer(mMap, l.getTileLayer())); - mMapView.setTheme(InternalRenderTheme.DEFAULT); - //mMapView.setTheme(InternalRenderTheme.TRONRENDER); + mMap.setTheme(InternalRenderTheme.DEFAULT); + //mMap.setTheme(InternalRenderTheme.TRONRENDER); - //mMapView.getLayerManager().add(new BitmapTileLayer(mMapView, HillShadeTiles.INSTANCE)); + //mMap.getLayerManager().add(new BitmapTileLayer(mMap, HillShadeTiles.INSTANCE)); - //mMapView.setBackgroundMap(new BitmapTileLayer(mMapView, StamenWaterTiles.INSTANCE)); + //mMap.setBackgroundMap(new BitmapTileLayer(mMap, StamenWaterTiles.INSTANCE)); //mMap.setBackgroundMap(new BitmapTileLayer(mMap, MapQuestAerial.INSTANCE)); - //mMapView.getLayerManager().add(new GenericOverlay(mMapView, new GridRenderLayer(mMapView))); + //mMap.getLayerManager().add(new GenericOverlay(mMap, new GridRenderLayer(mMap))); - mAndroidMapView.setClickable(true); - mAndroidMapView.setFocusable(true); + mMapView.setClickable(true); + mMapView.setFocusable(true); } @Override diff --git a/vtm-android/src/org/oscim/android/AndroidGLRenderer.java b/vtm-android/src/org/oscim/android/AndroidGLRenderer.java index 5e160dde..719aada1 100644 --- a/vtm-android/src/org/oscim/android/AndroidGLRenderer.java +++ b/vtm-android/src/org/oscim/android/AndroidGLRenderer.java @@ -18,14 +18,14 @@ import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import org.oscim.renderer.GLRenderer; -import org.oscim.view.MapView; +import org.oscim.view.Map; import android.opengl.GLSurfaceView; public class AndroidGLRenderer extends GLRenderer implements GLSurfaceView.Renderer{ - public AndroidGLRenderer(MapView mapView) { - super(mapView); + public AndroidGLRenderer(Map map) { + super(map); } @Override diff --git a/vtm-android/src/org/oscim/android/Compass.java b/vtm-android/src/org/oscim/android/Compass.java index 5fd29db9..f89158ba 100644 --- a/vtm-android/src/org/oscim/android/Compass.java +++ b/vtm-android/src/org/oscim/android/Compass.java @@ -14,7 +14,7 @@ */ package org.oscim.android; -import org.oscim.view.MapView; +import org.oscim.view.Map; import android.content.Context; import android.hardware.Sensor; @@ -30,9 +30,9 @@ public class Compass { if (Math.abs(event.values[0] - mAngle) > 0.25) { mAngle = event.values[0]; - if (mMapView != null) { - mMapView.getMapViewPosition().setRotation(-mAngle); - mMapView.updateMap(true); + if (mMap != null) { + mMap.getViewport().setRotation(-mAngle); + mMap.updateMap(true); } } } @@ -43,13 +43,13 @@ public class Compass { }; /* package */float mAngle = 0; - /* package */MapView mMapView; + /* package */Map mMap; private final SensorManager mSensorManager; private final Sensor mSensor; - public Compass(MapActivity mapActivity, MapView mapView) { - mMapView = mapView; + public Compass(MapActivity mapActivity, Map map) { + mMap = map; mSensorManager = (SensorManager) mapActivity .getSystemService(Context.SENSOR_SERVICE); @@ -63,6 +63,6 @@ public class Compass { public void disable() { mSensorManager.unregisterListener(mListener); - mMapView.getMapViewPosition().setRotation(0); + mMap.getViewport().setRotation(0); } } diff --git a/vtm-android/src/org/oscim/android/GLView.java b/vtm-android/src/org/oscim/android/GLView.java index 8ca4f449..e035b96a 100644 --- a/vtm-android/src/org/oscim/android/GLView.java +++ b/vtm-android/src/org/oscim/android/GLView.java @@ -14,25 +14,25 @@ */ package org.oscim.android; -import org.oscim.view.MapView; +import org.oscim.view.Map; import android.content.Context; import android.opengl.GLSurfaceView; public class GLView extends GLSurfaceView { - MapView mMapView; + Map mMap; private final AndroidGLRenderer mRenderer; - public GLView(Context context, MapView mapView) { + public GLView(Context context, Map map) { super(context); - mMapView = mapView; + mMap = map; // Log.d(TAG, "init GLSurfaceLayer"); setEGLConfigChooser(new GlConfigChooser()); setEGLContextClientVersion(2); setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS); - mRenderer = new AndroidGLRenderer(mMapView); + mRenderer = new AndroidGLRenderer(mMap); setRenderer(mRenderer); //if (!MapView.debugFrameTime) diff --git a/vtm-android/src/org/oscim/android/MapActivity.java b/vtm-android/src/org/oscim/android/MapActivity.java index f68ddafc..ef93fd83 100644 --- a/vtm-android/src/org/oscim/android/MapActivity.java +++ b/vtm-android/src/org/oscim/android/MapActivity.java @@ -16,7 +16,7 @@ package org.oscim.android; import org.oscim.core.GeoPoint; import org.oscim.core.MapPosition; -import org.oscim.view.MapView; +import org.oscim.view.Map; import android.app.Activity; import android.content.SharedPreferences; @@ -24,7 +24,7 @@ import android.content.SharedPreferences.Editor; /** * MapActivity is the abstract base class which must be extended in order to use - * a {@link MapView}. There are no abstract methods in this implementation which + * a {@link Map}. There are no abstract methods in this implementation which * subclasses need to override and no API key or registration is required. *

* A subclass may create a MapView either via one of the MapView constructors or @@ -43,18 +43,18 @@ public abstract class MapActivity extends Activity { private static final String PREFERENCES_FILE = "MapActivity"; //private static final String KEY_THEME = "Theme"; - private static boolean containsMapViewPosition(SharedPreferences sharedPreferences) { + private static boolean containsViewport(SharedPreferences sharedPreferences) { return sharedPreferences.contains(KEY_LATITUDE) && sharedPreferences.contains(KEY_LONGITUDE) && sharedPreferences.contains(KEY_MAP_SCALE); } - protected MapView mMapView; + protected Map mMap; @Override protected void onDestroy() { super.onDestroy(); - mMapView.destroy(); + mMap.destroy(); } @Override @@ -67,7 +67,7 @@ public abstract class MapActivity extends Activity { // save the map position MapPosition mapPosition = new MapPosition(); - mMapView.getMapViewPosition().getMapPosition(mapPosition); + mMap.getViewport().getMapPosition(mapPosition); GeoPoint geoPoint = mapPosition.getGeoPoint(); @@ -75,7 +75,7 @@ public abstract class MapActivity extends Activity { editor.putInt(KEY_LONGITUDE, geoPoint.longitudeE6); editor.putFloat(KEY_MAP_SCALE, (float)mapPosition.scale); - //editor.putString(KEY_THEME, mMapView.getRenderTheme()); + //editor.putString(KEY_THEME, mMap.getRenderTheme()); editor.commit(); } @@ -93,16 +93,16 @@ public abstract class MapActivity extends Activity { /** * This method is called once by each MapView during its setup process. * - * @param mapView + * @param map * the calling MapView. */ - public final void registerMapView(MapView mapView) { - mMapView = mapView; + public final void registerMapView(Map map) { + mMap = map; SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE); - if (containsMapViewPosition(sharedPreferences)) { + if (containsViewport(sharedPreferences)) { // get and set the map position and zoom level int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0); int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0); @@ -113,7 +113,7 @@ public abstract class MapActivity extends Activity { mapPosition.setPosition(latitudeE6 / 1E6, longitudeE6 / 1E6); mapPosition.setScale(scale); - mMapView.setMapPosition(mapPosition); + mMap.setMapPosition(mapPosition); } //String theme = sharedPreferences.getString(KEY_THEME, @@ -121,15 +121,15 @@ public abstract class MapActivity extends Activity { // if (theme.startsWith("/")) { // try { -// mapView.setRenderTheme(theme); +// map.setRenderTheme(theme); // } catch (FileNotFoundException e) { -// mapView.setRenderTheme(InternalRenderTheme.DEFAULT); +// map.setRenderTheme(InternalRenderTheme.DEFAULT); // } // } else { // try { -// mapView.setRenderTheme(InternalRenderTheme.valueOf(theme)); +// map.setRenderTheme(InternalRenderTheme.valueOf(theme)); // } catch (IllegalArgumentException e) { -// mapView.setRenderTheme(InternalRenderTheme.DEFAULT); +// map.setRenderTheme(InternalRenderTheme.DEFAULT); // } // } } diff --git a/vtm-android/src/org/oscim/android/MapScaleBar.java b/vtm-android/src/org/oscim/android/MapScaleBar.java index 3187b222..93ec0478 100644 --- a/vtm-android/src/org/oscim/android/MapScaleBar.java +++ b/vtm-android/src/org/oscim/android/MapScaleBar.java @@ -75,8 +75,8 @@ package org.oscim.android; // private final Bitmap mMapScaleBitmap; // private final BitmapRenderLayer mBitmapLayer; // -// public MapScaleBar(MapView mapView) { -// super(mapView); +// public MapScaleBar(MapView map) { +// super(map); // // mMapScaleBitmap = Bitmap.createBitmap( // BITMAP_WIDTH, BITMAP_HEIGHT, @@ -89,7 +89,7 @@ package org.oscim.android; // configurePaints(); // // mRedrawNeeded = true; -// mLayer = mBitmapLayer = new BitmapRenderLayer(mapView); +// mLayer = mBitmapLayer = new BitmapRenderLayer(map); // mBitmapLayer.setBitmap(mMapScaleBitmap, 0, 0, // (int)(BITMAP_WIDTH * 1.2f), // (int)(BITMAP_HEIGHT * 1.2f)); diff --git a/vtm-android/src/org/oscim/android/AndroidMapView.java b/vtm-android/src/org/oscim/android/MapView.java similarity index 88% rename from vtm-android/src/org/oscim/android/AndroidMapView.java rename to vtm-android/src/org/oscim/android/MapView.java index e2032de3..eca789ba 100644 --- a/vtm-android/src/org/oscim/android/AndroidMapView.java +++ b/vtm-android/src/org/oscim/android/MapView.java @@ -23,7 +23,7 @@ import org.oscim.backend.CanvasAdapter; import org.oscim.backend.GLAdapter; import org.oscim.backend.Log; import org.oscim.core.Tile; -import org.oscim.view.MapView; +import org.oscim.view.Map; import android.content.Context; import android.util.AttributeSet; @@ -35,9 +35,9 @@ import android.widget.RelativeLayout; * 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 AndroidMapView extends RelativeLayout { +public class MapView extends RelativeLayout { - final static String TAG = AndroidMapView.class.getName(); + final static String TAG = MapView.class.getName(); public static final boolean debugFrameTime = false; public static final boolean testRegionZoom = false; @@ -52,7 +52,7 @@ public class AndroidMapView extends RelativeLayout { private int mHeight; - private final MapView mMapView; + private final Map mMap; final GLView mGLView; boolean mPausing = false; @@ -61,10 +61,6 @@ public class AndroidMapView extends RelativeLayout { static { System.loadLibrary("vtm-jni"); //System.loadLibrary("tessellate"); - - CanvasAdapter.g = AndroidGraphics.INSTANCE; - GLAdapter.g = new AndroidGL(); - Log.logger = new AndroidLog(); } /** @@ -74,7 +70,7 @@ public class AndroidMapView extends RelativeLayout { * if the context object is not an instance of * {@link MapActivity} . */ - public AndroidMapView(Context context) { + public MapView(Context context) { this(context, null); } @@ -88,7 +84,7 @@ public class AndroidMapView extends RelativeLayout { * {@link MapActivity} . */ - public AndroidMapView(Context context, AttributeSet attributeSet) { + public MapView(Context context, AttributeSet attributeSet) { super(context, attributeSet); if (!(context instanceof MapActivity)) { @@ -96,7 +92,10 @@ public class AndroidMapView extends RelativeLayout { "context is not an instance of MapActivity"); } + Log.logger = new AndroidLog(); + CanvasAdapter.g = AndroidGraphics.INSTANCE; AssetAdapter.g = new AndroidAssetAdapter(context); + GLAdapter.g = new AndroidGL(); this.setWillNotDraw(true); @@ -108,9 +107,9 @@ public class AndroidMapView extends RelativeLayout { MapActivity mapActivity = (MapActivity) context; - final AndroidMapView m = this; + final MapView m = this; - mMapView = new MapView(){ + mMap = new Map(){ boolean mWaitRedraw; @@ -176,10 +175,10 @@ public class AndroidMapView extends RelativeLayout { } }; - mGLView = new GLView(context, mMapView); - mCompass = new Compass(mapActivity, mMapView); + mGLView = new GLView(context, mMap); + mCompass = new Compass(mapActivity, mMap); - mapActivity.registerMapView(mMapView); + mapActivity.registerMapView(mMap); LayoutParams params = new LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, @@ -187,21 +186,21 @@ public class AndroidMapView extends RelativeLayout { addView(mGLView, params); - mMapView.clearMap(); - mMapView.updateMap(false); + mMap.clearMap(); + mMap.updateMap(false); } View getView(){ return this; } - public MapView getMap() { - return mMapView; + public Map getMap() { + return mMap; } public void onStop() { Log.d(TAG, "onStop"); - //mLayerManager.destroy(); + //mMap.destroy(); } @@ -230,7 +229,7 @@ public class AndroidMapView extends RelativeLayout { mMotionEvent.wrap(motionEvent); - return mMapView.getLayerManager().handleMotionEvent(mMotionEvent); + return mMap.getLayers().handleMotionEvent(mMotionEvent); } // synchronized ??? @@ -247,7 +246,7 @@ public class AndroidMapView extends RelativeLayout { mInitialized = (mWidth > 0 && mHeight > 0); if (mInitialized) - mMapView.getMapViewPosition().setViewport(width, height); + mMap.getViewport().setViewport(width, height); } diff --git a/vtm-android/src/org/oscim/android/MapZoomControls.java b/vtm-android/src/org/oscim/android/MapZoomControls.java index c37c1247..a74c4dd0 100644 --- a/vtm-android/src/org/oscim/android/MapZoomControls.java +++ b/vtm-android/src/org/oscim/android/MapZoomControls.java @@ -55,7 +55,7 @@ package org.oscim.android; // @Override // public void onClick(View view) { // // if (MapView.testRegionZoom) -// // mMapView.mRegionLookup.updateRegion(1, null); +// // mMap.mRegionLookup.updateRegion(1, null); // // else // // MapZoomControls.this.zoom((byte) 1); // mMapZoomControls.zoom((byte) 1); @@ -72,7 +72,7 @@ package org.oscim.android; // @Override // public void onClick(View view) { // // if (MapView.testRegionZoom) -// // mMapView.mRegionLookup.updateRegion(-1, null); +// // mMap.mRegionLookup.updateRegion(-1, null); // // else // mMapZoomControls.zoom((byte) -1); // } @@ -117,10 +117,10 @@ package org.oscim.android; // private final Handler mZoomControlsHideHandler; // private byte mZoomLevelMax; // private byte mZoomLevelMin; -// private final MapView mMapView; +// private final MapView mMap; // -// MapZoomControls(Context context, final MapView mapView) { -// mMapView = mapView; +// MapZoomControls(Context context, final MapView map) { +// mMap = map; // mZoomControls = new ZoomControls(context); // mShowMapZoomControls = true; // mZoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX; @@ -135,7 +135,7 @@ package org.oscim.android; // // int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; // LayoutParams layoutParams = new LayoutParams(wrapContent, wrapContent); -// mapView.addView(mZoomControls, layoutParams); +// map.addView(mZoomControls, layoutParams); // } // // /** @@ -146,8 +146,8 @@ package org.oscim.android; // * @return true if the zoom level was changed, false otherwise. // */ // boolean zoom(byte zoomLevelDiff) { -// MapViewPosition mapViewPosition = mMapView.getMapViewPosition(); -// int z = mapViewPosition.getZoomLevel() + zoomLevelDiff; +// Viewport mapPosition = mMap.getViewport(); +// int z = mapPosition.getZoomLevel() + zoomLevelDiff; // if (zoomLevelDiff > 0) { // // check if zoom in is possible // if (z > mZoomLevelMax) { @@ -161,8 +161,8 @@ package org.oscim.android; // } // } // -// mapViewPosition.setZoomLevel((byte) z); -// mMapView.redrawMap(true); +// mapPosition.setZoomLevel((byte) z); +// mMap.redrawMap(true); // // return true; // } diff --git a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java index 02bb3daf..5dc5a08e 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java +++ b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java @@ -81,10 +81,10 @@ class GwtGdxMap extends GdxMap { p.angle = rotation; p.tilt = tilt; - mMapView.setMapPosition(p); + mMap.setMapPosition(p); - //mMapView.getMapViewPosition().setTilt(tilt); - //mMapView.getMapViewPosition().setRotation(rotation); + //mMap.getViewport().setTilt(tilt); + //mMap.getViewport().setRotation(rotation); String url = c.getTileUrl(); String sourceName = c.getTileSource(); @@ -101,9 +101,9 @@ class GwtGdxMap extends GdxMap { initDefaultMap(tileSource, false, true, true); if ("naturalearth".equals(c.getBackgroundLayer())) - mMapView.setBackgroundMap(new BitmapTileLayer(mMapView, NaturalEarth.INSTANCE)); + mMap.setBackgroundMap(new BitmapTileLayer(mMap, NaturalEarth.INSTANCE)); - mSearchBox = new SearchBox(mMapView); + mSearchBox = new SearchBox(mMap); // update URL hash to current position, every 5 seconds Timer timer = new Timer() { @@ -111,7 +111,7 @@ class GwtGdxMap extends GdxMap { private MapPosition pos = new MapPosition(); public void run() { - mMapView.getMapViewPosition().getMapPosition(pos); + mMap.getViewport().getMapPosition(pos); int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000); int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000); int rot = (int) (pos.angle); diff --git a/vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java b/vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java index 35925b41..5792c293 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java +++ b/vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java @@ -8,7 +8,7 @@ import org.oscim.core.BoundingBox; import org.oscim.core.GeometryBuffer; import org.oscim.core.MapPosition; import org.oscim.layers.overlay.PathOverlay; -import org.oscim.view.MapView; +import org.oscim.view.Map; import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.core.client.JavaScriptObject; @@ -181,12 +181,12 @@ public class SearchBox { } } - public SearchBox(final MapView mapView) { + public SearchBox(final Map map) { final Button searchButton = new Button("Search"); final TextBox searchField = new TextBox(); //searchField.setText("Bremen"); - final PathOverlay mOverlay = new PathOverlay(mapView, 0xCC0000FF); - mapView.getLayerManager().add(mOverlay); + final PathOverlay mOverlay = new PathOverlay(map, 0xCC0000FF); + map.getLayerManager().add(mOverlay); // We can add style names to widgets searchButton.addStyleName("sendButton"); @@ -237,9 +237,9 @@ public class SearchBox { if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 && b.maxLongitudeE6 - b.minLongitudeE6 < 100) // for small bbox use zoom=16 to get an overview - mapView.getMapViewPosition().animateTo(500, b.getCenterPoint(), 1 << 16, false); + map.getViewport().animateTo(500, b.getCenterPoint(), 1 << 16, false); else - mapView.getMapViewPosition().animateTo(b); + map.getViewport().animateTo(b); if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) { String wkt = ((NominatimData) d).getWkt(); @@ -261,7 +261,7 @@ public class SearchBox { mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); } // hide overlay after 5 seconds - mapView.postDelayed(new Runnable() { + map.postDelayed(new Runnable() { @Override public void run() { mOverlay.clearPath(); @@ -270,13 +270,13 @@ public class SearchBox { } else { MapPosition pos = new MapPosition(); - mapView.getMapViewPosition().setTilt(0); - mapView.getMapViewPosition().setRotation(0); + map.getViewport().setTilt(0); + map.getViewport().setRotation(0); pos.setZoomLevel(13); pos.setPosition(d.getLatitude(), d.getLongitude()); - mapView.setMapPosition(pos); - mapView.updateMap(true); + map.setMapPosition(pos); + map.updateMap(true); } scroller.setVisible(false); diff --git a/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java b/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java index fd336499..fcb802b5 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java +++ b/vtm-gdx-html/src/org/oscim/gdx/emu/org/oscim/layers/tile/bitmap/BitmapTileLayer.java @@ -28,7 +28,7 @@ import org.oscim.layers.tile.bitmap.TileSource.FadeStep; import org.oscim.renderer.sublayers.BitmapLayer; import org.oscim.renderer.sublayers.Layers; import org.oscim.utils.FastMath; -import org.oscim.view.MapView; +import org.oscim.view.Map; import com.google.gwt.event.dom.client.ErrorEvent; import com.google.gwt.event.dom.client.ErrorHandler; @@ -42,8 +42,8 @@ public class BitmapTileLayer extends TileLayer { final TileSource mTileSource; private final FadeStep[] mFade; - public BitmapTileLayer(MapView mapView, TileSource tileSource) { - super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); + public BitmapTileLayer(Map map, TileSource tileSource) { + super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); mTileSource = tileSource; mFade = mTileSource.getFadeSteps(); } diff --git a/vtm-gdx/src/org/oscim/gdx/GdxMap.java b/vtm-gdx/src/org/oscim/gdx/GdxMap.java index 026f4a71..f4ec53cc 100644 --- a/vtm-gdx/src/org/oscim/gdx/GdxMap.java +++ b/vtm-gdx/src/org/oscim/gdx/GdxMap.java @@ -13,8 +13,8 @@ import org.oscim.renderer.GLState; import org.oscim.renderer.layers.GridRenderLayer; import org.oscim.theme.InternalRenderTheme; import org.oscim.tilesource.TileSource; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; import com.badlogic.gdx.Application; import com.badlogic.gdx.ApplicationListener; @@ -31,7 +31,7 @@ import com.badlogic.gdx.utils.Timer.Task; public class GdxMap implements ApplicationListener { - protected final MapView mMapView; + protected final Map mMap; private final GLRenderer mMapRenderer; boolean mRenderRequest; @@ -39,7 +39,7 @@ public class GdxMap implements ApplicationListener { public GdxMap() { AssetAdapter.g = new GdxAssetAdapter(); - mMapView = new MapView() { + mMap = new Map() { @Override public int getWidth() { return mWidth; @@ -85,7 +85,7 @@ public class GdxMap implements ApplicationListener { } }; - mMapRenderer = new GLRenderer(mMapView); + mMapRenderer = new GLRenderer(mMap); } @@ -93,20 +93,20 @@ public class GdxMap implements ApplicationListener { boolean buildings) { if (tileSource != null) { - mMapLayer = mMapView.setBaseMap(tileSource); - mMapView.setTheme(InternalRenderTheme.DEFAULT); + mMapLayer = mMap.setBaseMap(tileSource); + mMap.setTheme(InternalRenderTheme.DEFAULT); if (buildings) - mMapView.getLayerManager().add( - new BuildingOverlay(mMapView, mMapLayer.getTileLayer())); + mMap.getLayerManager().add( + new BuildingOverlay(mMap, mMapLayer.getTileLayer())); if (labels) - mMapView.getLayerManager().add(new LabelLayer(mMapView, + mMap.getLayerManager().add(new LabelLayer(mMap, mMapLayer.getTileLayer())); } if (tileGrid) - mMapView.getLayerManager().add(new GenericOverlay(mMapView, + mMap.getLayerManager().add(new GenericOverlay(mMap, new GridRenderLayer())); } @@ -132,12 +132,12 @@ public class GdxMap implements ApplicationListener { mWidth = w; mHeight = h; - mMapView.getMapViewPosition().setViewport(w, h); + mMap.getViewport().setViewport(w, h); MapPosition p = new MapPosition(); p.setZoomLevel(14); p.setPosition(53.08, 8.83); //p.setPosition(0.0, 0.0); - mMapView.setMapPosition(p); + mMap.setMapPosition(p); mMapRenderer.onSurfaceCreated(); mMapRenderer.onSurfaceChanged(w, h); @@ -183,9 +183,9 @@ public class GdxMap implements ApplicationListener { mWidth = w; mHeight = h; - mMapView.getMapViewPosition().setViewport(w, h); + mMap.getViewport().setViewport(w, h); mMapRenderer.onSurfaceChanged(w, h); - mMapView.render(); + mMap.render(); } @Override @@ -206,7 +206,7 @@ public class GdxMap implements ApplicationListener { GLState.blend(false); GLState.test(false, false); - mMapView.updateLayers(); + mMap.updateLayers(); mRenderRequest = true; Gdx.graphics.requestRendering(); @@ -223,10 +223,10 @@ public class GdxMap implements ApplicationListener { class TouchHandler implements InputProcessor { - private MapViewPosition mMapPosition; + private Viewport mMapPosition; public TouchHandler() { - mMapPosition = mMapView.getMapViewPosition(); + mMapPosition = mMap.getViewport(); } private boolean mActiveScale; @@ -241,54 +241,54 @@ public class GdxMap implements ApplicationListener { case Input.Keys.UP: mMapPosition.moveMap(0, -50); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.DOWN: mMapPosition.moveMap(0, 50); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.LEFT: mMapPosition.moveMap(-50, 0); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.RIGHT: mMapPosition.moveMap(50, 0); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.M: mMapPosition.scaleMap(1.05f, 0, 0); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.N: mMapPosition.scaleMap(0.95f, 0, 0); - mMapView.updateMap(true); + mMap.updateMap(true); break; case Input.Keys.D: - mMapView.setTheme(InternalRenderTheme.DEFAULT); - mMapView.updateMap(false); + mMap.setTheme(InternalRenderTheme.DEFAULT); + mMap.updateMap(false); break; case Input.Keys.T: - mMapView.setTheme(InternalRenderTheme.TRONRENDER); - mMapView.updateMap(false); + mMap.setTheme(InternalRenderTheme.TRONRENDER); + mMap.updateMap(false); break; case Input.Keys.G: if (mGridLayer == null) { - mGridLayer = new GenericOverlay(mMapView, new GridRenderLayer()); + mGridLayer = new GenericOverlay(mMap, new GridRenderLayer()); mGridLayer.setEnabled(true); - mMapView.getLayerManager().add(mGridLayer); + mMap.getLayerManager().add(mGridLayer); } else { if (mGridLayer.isEnabled()) { mGridLayer.setEnabled(false); - mMapView.getLayerManager().remove(mGridLayer); + mMap.getLayerManager().remove(mGridLayer); } else { mGridLayer.setEnabled(true); - mMapView.getLayerManager().add(mGridLayer); + mMap.getLayerManager().add(mGridLayer); } } - mMapView.render(); + mMap.render(); break; } return false; @@ -348,7 +348,7 @@ public class GdxMap implements ApplicationListener { } if (changed) { - mMapView.updateMap(true); + mMap.updateMap(true); } return true; } @@ -367,12 +367,12 @@ public class GdxMap implements ApplicationListener { mMapPosition.animateZoom(150, 0.8f, 0, 0); } else { - float fx = mPosX - mMapView.getWidth() / 2; - float fy = mPosY - mMapView.getHeight() / 2; + float fx = mPosX - mMap.getWidth() / 2; + float fy = mPosY - mMap.getHeight() / 2; mMapPosition.animateZoom(150, 1.25f, fx, fy); } - mMapView.updateMap(false); + mMap.updateMap(false); return true; } @@ -408,10 +408,10 @@ public class GdxMap implements ApplicationListener { protected static final double PINCH_ROTATE_THRESHOLD = 0.02; protected static final float PINCH_TILT_THRESHOLD = 1f; - private MapViewPosition mMapPosition; + private Viewport mMapPosition; public ViewController() { - mMapPosition = mMapView.getMapViewPosition(); + mMapPosition = mMap.getViewport(); } @Override @@ -450,7 +450,7 @@ public class GdxMap implements ApplicationListener { return true; mMapPosition.moveMap(deltaX, deltaY); - mMapView.updateMap(true); + mMap.updateMap(true); return false; } @@ -583,7 +583,7 @@ public class GdxMap implements ApplicationListener { } if (changed) { - mMapView.updateMap(true); + mMap.updateMap(true); mPrevPinchWidth = pinchWidth; mPrevY2 = y2; diff --git a/vtm/src/org/oscim/view/MapAnimator.java b/vtm/src/org/oscim/core/Box.java similarity index 57% rename from vtm/src/org/oscim/view/MapAnimator.java rename to vtm/src/org/oscim/core/Box.java index 94cdecd7..822db4a6 100644 --- a/vtm/src/org/oscim/view/MapAnimator.java +++ b/vtm/src/org/oscim/core/Box.java @@ -12,8 +12,29 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.view; +package org.oscim.core; -public class MapAnimator { +public class Box { + public double minX; + public double maxX; + public double minY; + public double maxY; + public Box(){ + + } + public Box(double minX, double minY, double maxX, double maxY) { + this.minX = minX; + this.minY = minY; + this.maxX = maxX; + this.maxY = maxY; + } + + public boolean contains(double x, double y){ + return (x >= minX && x <= maxY && y >= minY && y <= maxY); + } + + public boolean contains(PointD p){ + return (p.x >= minX && p.x <= maxY && p.y >= minY && p.y <= maxY); + } } diff --git a/vtm/src/org/oscim/layers/InputLayer.java b/vtm/src/org/oscim/layers/InputLayer.java index eb1aa01b..b66415b7 100644 --- a/vtm/src/org/oscim/layers/InputLayer.java +++ b/vtm/src/org/oscim/layers/InputLayer.java @@ -17,12 +17,12 @@ package org.oscim.layers; import org.oscim.backend.input.KeyEvent; import org.oscim.backend.input.MotionEvent; -import org.oscim.view.MapView; +import org.oscim.view.Map; public abstract class InputLayer extends Layer { - public InputLayer(MapView mapView) { - super(mapView); + public InputLayer(Map map) { + super(map); } @@ -30,7 +30,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param keyCode * ... @@ -46,7 +46,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param keyCode * ... @@ -63,7 +63,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param event * ... @@ -77,7 +77,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -93,7 +93,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -107,7 +107,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -121,7 +121,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -137,7 +137,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -172,7 +172,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... @@ -186,7 +186,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param pEvent1 * ... @@ -215,7 +215,7 @@ public abstract class InputLayer extends Layer { * By default does nothing (return false). If you handled the * Event, return true, otherwise return false. If * you returned true none of the following Overlays or the - * underlying {@link MapView} has the chance to handle this event. + * underlying {@link Map} has the chance to handle this event. * * @param e * ... diff --git a/vtm/src/org/oscim/layers/Layer.java b/vtm/src/org/oscim/layers/Layer.java index 3bfef686..f0f76379 100644 --- a/vtm/src/org/oscim/layers/Layer.java +++ b/vtm/src/org/oscim/layers/Layer.java @@ -14,17 +14,17 @@ */ package org.oscim.layers; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.core.MapPosition; import org.oscim.renderer.RenderLayer; public abstract class Layer { - public Layer(MapView mapView) { - mMapView = mapView; + public Layer(Map map) { + mMap = map; } private boolean mEnabled = true; - protected final MapView mMapView; + protected final Map mMap; /** RenderLayer used to draw this layer. To be implemented by sub-classes */ protected RenderLayer mLayer; diff --git a/vtm/src/org/oscim/layers/MapEventLayer.java b/vtm/src/org/oscim/layers/MapEventLayer.java index 06540dbd..24b4510d 100644 --- a/vtm/src/org/oscim/layers/MapEventLayer.java +++ b/vtm/src/org/oscim/layers/MapEventLayer.java @@ -18,11 +18,11 @@ import org.oscim.backend.CanvasAdapter; import org.oscim.backend.Log; import org.oscim.backend.input.MotionEvent; import org.oscim.core.Tile; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; /** - * Changes MapViewPosition for scroll, fling, scale, rotation and tilt gestures + * Changes Viewport for scroll, fling, scale, rotation and tilt gestures * * @TODO: * - better recognition of tilt/rotate/scale state @@ -61,16 +61,41 @@ public class MapEventLayer extends InputLayer { protected static final double PINCH_ROTATE_THRESHOLD = 0.02; protected static final float PINCH_TILT_THRESHOLD = 1f; - private final MapViewPosition mMapPosition; + private final Viewport mMapPosition; private final VelocityTracker mTracker; - public MapEventLayer(MapView mapView) { - super(mapView); - mMapPosition = mapView.getMapViewPosition(); + public MapEventLayer(Map map) { + super(map); + mMapPosition = map.getViewport(); mTracker = new VelocityTracker(); } private long mPrevTime; + private boolean mEnableRotation = true; + private boolean mEnableTilt = true; + private boolean mEnableMove = true; + private boolean mEnableZoom = true; + + public void enableRotation(boolean enable) { + mEnableRotation = enable; + } + + public boolean rotationEnabled() { + return mEnableRotation; + } + + public void enableTilt(boolean enable) { + mEnableTilt = enable; + } + + public void enableMove(boolean enable) { + mEnableMove = enable; + } + + public void enableZoom(boolean enable) { + mEnableZoom = enable; + } + @Override public boolean onTouchEvent(MotionEvent e) { @@ -121,8 +146,8 @@ public class MapEventLayer extends InputLayer { float mx = x1 - mPrevX; float my = y1 - mPrevY; - float width = mMapView.getWidth(); - float height = mMapView.getHeight(); + float width = mMap.getWidth(); + float height = mMap.getHeight(); mTracker.update(x1, y1, e.getTime()); @@ -135,7 +160,7 @@ public class MapEventLayer extends InputLayer { if (debug) Log.d(TAG, "tap scale: " + mx + " " + my); mMapPosition.scaleMap(1 - my / (height / 8), 0, 0); - mMapView.updateMap(true); + mMap.updateMap(true); mPrevX = x1; mPrevY = y1; @@ -146,7 +171,7 @@ public class MapEventLayer extends InputLayer { if (mx > 1 || mx < -1 || my > 1 || my < -1) { mMapPosition.moveMap(mx, my); - mMapView.updateMap(true); + mMap.updateMap(true); mPrevX = x1; mPrevY = y1; @@ -233,7 +258,7 @@ public class MapEventLayer extends InputLayer { } if (changed) { - mMapView.updateMap(true); + mMap.updateMap(true); mPrevPinchWidth = pinchWidth; mPrevX2 = x2; @@ -274,7 +299,7 @@ public class MapEventLayer extends InputLayer { printState("onDoubleTap"); // avoid onLongPress - mMapView.getLayerManager().cancelGesture(); + mMap.getLayerManager().cancelGesture(); return true; } @@ -285,7 +310,7 @@ public class MapEventLayer extends InputLayer { if (e2.getPointerCount() == 1) { mMapPosition.moveMap(-distanceX, -distanceY); - mMapView.updateMap(true); + mMap.updateMap(true); return true; } @@ -300,7 +325,7 @@ public class MapEventLayer extends InputLayer { int w = Tile.SIZE * 3; int h = Tile.SIZE * 3; - //if (mMapView.enablePagedFling) { + //if (mMap.enablePagedFling) { // double a = Math.sqrt(velocityX * velocityX + velocityY * velocityY); // // float vx = (float) (velocityX / a); @@ -309,7 +334,7 @@ public class MapEventLayer extends InputLayer { // if (a < 400) // return true; // - // float move = Math.min(mMapView.getWidth(), mMapView.getHeight()) * 2 / 3; + // float move = Math.min(mMap.getWidth(), mMap.getHeight()) * 2 / 3; // mMapPosition.animateTo(vx * move, vy * move, 250); //} else { float s = 1; //(200 / CanvasAdapter.dpi); diff --git a/vtm/src/org/oscim/layers/labeling/LabelLayer.java b/vtm/src/org/oscim/layers/labeling/LabelLayer.java index 05f3d183..db4fc7a4 100644 --- a/vtm/src/org/oscim/layers/labeling/LabelLayer.java +++ b/vtm/src/org/oscim/layers/labeling/LabelLayer.java @@ -18,7 +18,7 @@ import org.oscim.backend.input.MotionEvent; import org.oscim.core.MapPosition; import org.oscim.layers.InputLayer; import org.oscim.layers.tile.TileRenderLayer; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.backend.Log; @@ -26,11 +26,11 @@ public class LabelLayer extends InputLayer { private final static String TAG = LabelLayer.class.getName(); final TextRenderLayer mTextLayer; - public LabelLayer(MapView mapView, TileRenderLayer tileRenderLayer) { - super(mapView); + public LabelLayer(Map map, TileRenderLayer tileRenderLayer) { + super(map); - //mTextLayer = new org.oscim.renderer.layers.TextRenderLayer(mapView, tileRenderLayer); - mTextLayer = new TextRenderLayer(mapView, tileRenderLayer); + //mTextLayer = new org.oscim.renderer.layers.TextRenderLayer(map, tileRenderLayer); + mTextLayer = new TextRenderLayer(map, tileRenderLayer); mLayer = mTextLayer; } diff --git a/vtm/src/org/oscim/layers/labeling/TextRenderLayer.java b/vtm/src/org/oscim/layers/labeling/TextRenderLayer.java index 62096bd8..941869a5 100644 --- a/vtm/src/org/oscim/layers/labeling/TextRenderLayer.java +++ b/vtm/src/org/oscim/layers/labeling/TextRenderLayer.java @@ -50,8 +50,8 @@ import org.oscim.utils.FastMath; import org.oscim.utils.OBB2D; import org.oscim.utils.pool.LList; import org.oscim.utils.pool.Pool; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; class TextRenderLayer extends BasicRenderLayer { private final static String TAG = TextRenderLayer.class.getName(); @@ -61,7 +61,7 @@ class TextRenderLayer extends BasicRenderLayer { private final static long MAX_RELABEL_DELAY = 200; - private final MapViewPosition mMapViewPosition; + private final Viewport mViewport; private final TileSet mTileSet; class TextureLayers { @@ -131,11 +131,11 @@ class TextRenderLayer extends BasicRenderLayer { private float mSquareRadius; private int mRelabelCnt; private final TileRenderLayer mTileLayer; - private final MapView mMapView; + private final Map mMap; - public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) { - mMapView = mapView; - mMapViewPosition = mapView.getMapViewPosition(); + public TextRenderLayer(Map map, TileRenderLayer baseLayer) { + mMap = map; + mViewport = map.getViewport(); mTileLayer = baseLayer; mTileSet = new TileSet(); @@ -294,9 +294,9 @@ class TextRenderLayer extends BasicRenderLayer { MapPosition pos = mNextLayer.pos; - synchronized (mMapViewPosition) { - changedPos = mMapViewPosition.getMapPosition(pos); - //mMapViewPosition.getMapViewProjection(coords); + synchronized (mViewport) { + changedPos = mViewport.getMapPosition(pos); + //mViewport.getMapViewProjection(coords); } if (!changedTiles && !changedPos) { @@ -305,11 +305,11 @@ class TextRenderLayer extends BasicRenderLayer { } Layers dbg = null; - if (mMapView.getDebugSettings().debugLabels) + if (mMap.getDebugSettings().debugLabels) dbg = new Layers(); - int mw = (mMapView.getWidth() + Tile.SIZE) / 2; - int mh = (mMapView.getHeight() + Tile.SIZE) / 2; + int mw = (mMap.getWidth() + Tile.SIZE) / 2; + int mh = (mMap.getHeight() + Tile.SIZE) / 2; mSquareRadius = mw * mw + mh * mh; MapTile[] tiles = mTileSet.tiles; @@ -650,7 +650,7 @@ class TextRenderLayer extends BasicRenderLayer { labelsChanged = updateLabels(); if (!isCancelled && labelsChanged) - mMapView.render(); + mMap.render(); mLabelTask = null; mRequestRun = false; @@ -674,7 +674,7 @@ class TextRenderLayer extends BasicRenderLayer { public void run() { if (mLabelTask == null) { mLabelTask = new LabelTask(); - mMapView.addTask(mLabelTask); + mMap.addTask(mLabelTask); } } }; @@ -687,7 +687,7 @@ class TextRenderLayer extends BasicRenderLayer { mRequestRun = true; long delay = (mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis(); //Log.d(TAG, "relabel in: " + delay); - mMapView.postDelayed(mLabelUpdate, Math.max(delay, 0)); + mMap.postDelayed(mLabelUpdate, Math.max(delay, 0)); } } } diff --git a/vtm/src/org/oscim/layers/overlay/BuildingOverlay.java b/vtm/src/org/oscim/layers/overlay/BuildingOverlay.java index a2092852..b76b6be0 100644 --- a/vtm/src/org/oscim/layers/overlay/BuildingOverlay.java +++ b/vtm/src/org/oscim/layers/overlay/BuildingOverlay.java @@ -19,7 +19,7 @@ import org.oscim.core.MapPosition; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.layers.ExtrusionRenderLayer; import org.oscim.utils.FastMath; -import org.oscim.view.MapView; +import org.oscim.view.Map; /** * @author Hannes Janetzek @@ -29,8 +29,8 @@ public class BuildingOverlay extends Overlay { final ExtrusionRenderLayer mExtLayer; - public BuildingOverlay(MapView mapView, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { - super(mapView); + public BuildingOverlay(Map map, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { + super(map); mExtLayer = new ExtrusionRenderLayer(tileRenderLayer) { private long mStartTime; @@ -48,7 +48,7 @@ public class BuildingOverlay extends Overlay { } float a = (now - mStartTime) / mFadeTime; mAlpha = FastMath.clamp(a, 0, 1); - mMapView.render(); + mMap.render(); } else mStartTime = 0; } else { @@ -62,7 +62,7 @@ public class BuildingOverlay extends Overlay { float a = 1 - diff / mFadeTime; mAlpha = FastMath.clamp(a, 0, 1); } - mMapView.render(); + mMap.render(); } else mStartTime = 0; } diff --git a/vtm/src/org/oscim/layers/overlay/GenericOverlay.java b/vtm/src/org/oscim/layers/overlay/GenericOverlay.java index c9c29539..3efe3029 100644 --- a/vtm/src/org/oscim/layers/overlay/GenericOverlay.java +++ b/vtm/src/org/oscim/layers/overlay/GenericOverlay.java @@ -14,18 +14,18 @@ */ package org.oscim.layers.overlay; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.renderer.RenderLayer; public class GenericOverlay extends Overlay { /** - * @param mapView + * @param map * ... * @param renderer * ... */ - public GenericOverlay(MapView mapView, RenderLayer renderer) { - super(mapView); + public GenericOverlay(Map map, RenderLayer renderer) { + super(map); mLayer = renderer; } } diff --git a/vtm/src/org/oscim/layers/overlay/ItemizedIconOverlay.java b/vtm/src/org/oscim/layers/overlay/ItemizedIconOverlay.java index 7a251a6a..67f13101 100644 --- a/vtm/src/org/oscim/layers/overlay/ItemizedIconOverlay.java +++ b/vtm/src/org/oscim/layers/overlay/ItemizedIconOverlay.java @@ -19,9 +19,10 @@ import java.util.List; import org.oscim.backend.input.MotionEvent; import org.oscim.core.BoundingBox; +import org.oscim.core.PointD; import org.oscim.core.PointF; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; public class ItemizedIconOverlay extends ItemizedOverlay { //private static final String TAG = ItemizedIconOverlay.class.getName(); @@ -30,30 +31,30 @@ public class ItemizedIconOverlay extends ItemizedOverl protected OnItemGestureListener mOnItemGestureListener; private int mDrawnItemsLimit = Integer.MAX_VALUE; - private final PointF mTmpPoint = new PointF(); + private final PointD mTmpPoint = new PointD(); public ItemizedIconOverlay( - final MapView mapView, + final Map map, final List pList, final OverlayMarker pDefaultMarker, final ItemizedIconOverlay.OnItemGestureListener pOnItemGestureListener) { - super(mapView, pDefaultMarker); + super(map, pDefaultMarker); this.mItemList = pList; this.mOnItemGestureListener = pOnItemGestureListener; populate(); } -// public ItemizedIconOverlay( -// final MapView mapView, -// final Context pContext, -// final List pList, -// final ItemizedIconOverlay.OnItemGestureListener pOnItemGestureListener) { -// this(mapView, pList, -// null, //pContext.getResources().getDrawable(R.drawable.marker_default), -// pOnItemGestureListener); -// } + // public ItemizedIconOverlay( + // final MapView map, + // final Context pContext, + // final List pList, + // final ItemizedIconOverlay.OnItemGestureListener pOnItemGestureListener) { + // this(map, pList, + // null, //pContext.getResources().getDrawable(R.drawable.marker_default), + // pOnItemGestureListener); + // } @Override public boolean onSnapToItem(final int pX, final int pY, final PointF pSnapPoint) { @@ -136,6 +137,7 @@ public class ItemizedIconOverlay extends ItemizedOverl return onSingleTapUpHelper(index, that.mItemList.get(index)); } }; + @Override public boolean onLongPress(final MotionEvent event) { return activateSelectedItems(event, mActiveItemLongPress) || super.onLongPress(event); @@ -172,11 +174,11 @@ public class ItemizedIconOverlay extends ItemizedOverl if (size == 0) return false; - int eventX = (int) event.getX() - mMapView.getWidth() / 2; - int eventY = (int) event.getY() - mMapView.getHeight() / 2; - MapViewPosition mapViewPosition = mMapView.getMapViewPosition(); + int eventX = (int) event.getX() - mMap.getWidth() / 2; + int eventY = (int) event.getY() - mMap.getHeight() / 2; + Viewport mapPosition = mMap.getViewport(); - BoundingBox bbox = mapViewPosition.getViewBox(); + BoundingBox bbox = mapPosition.getViewBox(); int nearest = -1; double dist = Double.MAX_VALUE; @@ -188,10 +190,10 @@ public class ItemizedIconOverlay extends ItemizedOverl continue; // TODO use intermediate projection - mapViewPosition.project(item.getPoint(), mTmpPoint); + mapPosition.project(item.getPoint(), mTmpPoint); - float dx = mTmpPoint.x - eventX; - float dy = mTmpPoint.y - eventY; + float dx = (float) (mTmpPoint.x - eventX); + float dy = (float) (mTmpPoint.y - eventY); double d = dx * dx + dy * dy; // squared dist: 50*50 pixel diff --git a/vtm/src/org/oscim/layers/overlay/ItemizedOverlay.java b/vtm/src/org/oscim/layers/overlay/ItemizedOverlay.java index 9eb2a762..556cf082 100644 --- a/vtm/src/org/oscim/layers/overlay/ItemizedOverlay.java +++ b/vtm/src/org/oscim/layers/overlay/ItemizedOverlay.java @@ -30,7 +30,7 @@ import org.oscim.renderer.layers.BasicRenderLayer; import org.oscim.renderer.sublayers.SymbolItem; import org.oscim.renderer.sublayers.SymbolLayer; import org.oscim.utils.GeometryUtils; -import org.oscim.view.MapView; +import org.oscim.view.Map; /* @author Marc Kurtz * @author Nicolas Gramlich @@ -98,7 +98,7 @@ public abstract class ItemizedOverlay extends Overlay int changedVisible = 0; int numVisible = 0; - mMapView.getMapViewPosition().getMapViewProjection(mBox); + mMap.getViewport().getMapViewProjection(mBox); synchronized (lock) { if (mItems == null) { @@ -209,11 +209,11 @@ public abstract class ItemizedOverlay extends Overlay */ public abstract int size(); - public ItemizedOverlay(MapView mapView, OverlayMarker defaultMarker) { - super(mapView); + public ItemizedOverlay(Map map, OverlayMarker defaultMarker) { + super(map); // if (defaultMarker == null) { - // defaultMarker = AndroidGraphics.makeMarker(mapView.getContext().getResources() + // defaultMarker = AndroidGraphics.makeMarker(map.getContext().getResources() // .getDrawable(R.drawable.marker_default), null); // //throw new IllegalArgumentException("You must pass a default marker to ItemizedOverlay."); // } diff --git a/vtm/src/org/oscim/layers/overlay/Overlay.java b/vtm/src/org/oscim/layers/overlay/Overlay.java index 675f1aa1..638a37a7 100644 --- a/vtm/src/org/oscim/layers/overlay/Overlay.java +++ b/vtm/src/org/oscim/layers/overlay/Overlay.java @@ -16,14 +16,14 @@ package org.oscim.layers.overlay; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.core.PointF; import org.oscim.layers.InputLayer; /** * Base class representing an overlay which may be displayed on top of a - * {@link MapView}. To add an overlay, subclass this class, create an instance, - * and add via addOverlay() of {@link MapView}. + * {@link Map}. To add an overlay, subclass this class, create an instance, + * and add via addOverlay() of {@link Map}. * This class implements a form of Gesture Handling similar to * {@link android.view.GestureDetector.SimpleOnGestureListener} and * GestureDetector.OnGestureListener. @@ -32,8 +32,8 @@ import org.oscim.layers.InputLayer; */ public abstract class Overlay extends InputLayer { - public Overlay(MapView mapView) { - super(mapView); + public Overlay(Map map) { + super(map); } /** diff --git a/vtm/src/org/oscim/layers/overlay/PathOverlay.java b/vtm/src/org/oscim/layers/overlay/PathOverlay.java index a2772cc8..66bd5b95 100644 --- a/vtm/src/org/oscim/layers/overlay/PathOverlay.java +++ b/vtm/src/org/oscim/layers/overlay/PathOverlay.java @@ -32,7 +32,7 @@ import org.oscim.renderer.sublayers.LineLayer; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; import org.oscim.utils.LineClipper; -import org.oscim.view.MapView; +import org.oscim.view.Map; /** This class draws a path line in given color. */ public class PathOverlay extends Layer { @@ -234,8 +234,8 @@ public class PathOverlay extends Layer { } } - public PathOverlay(MapView mapView, int lineColor, float lineWidth) { - super(mapView); + public PathOverlay(Map map, int lineColor, float lineWidth) { + super(map); mLineStyle = new Line(lineColor, lineWidth, Cap.BUTT); @@ -244,8 +244,8 @@ public class PathOverlay extends Layer { mLayer = new RenderPath(); } - public PathOverlay(MapView mapView, int lineColor) { - this(mapView, lineColor, 2); + public PathOverlay(Map map, int lineColor) { + this(map, lineColor, 2); } /** diff --git a/vtm/src/org/oscim/layers/tile/TileLayer.java b/vtm/src/org/oscim/layers/tile/TileLayer.java index 6482d664..546e7a95 100644 --- a/vtm/src/org/oscim/layers/tile/TileLayer.java +++ b/vtm/src/org/oscim/layers/tile/TileLayer.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import org.oscim.core.MapPosition; import org.oscim.layers.Layer; -import org.oscim.view.MapView; +import org.oscim.view.Map; public abstract class TileLayer extends Layer { //private final static String TAG = TileLayer.class.getName(); @@ -34,16 +34,16 @@ public abstract class TileLayer extends Layer { protected boolean mInitial = true; - public TileLayer(MapView mapView) { - this(mapView, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT); + public TileLayer(Map map) { + this(map, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT); } - public TileLayer(MapView mapView, int minZoom, int maxZoom, int cacheLimit) { - super(mapView); + public TileLayer(Map map, int minZoom, int maxZoom, int cacheLimit) { + super(map); // TileManager responsible for adding visible tiles // to load queue and managing in-memory tile cache. - mTileManager = new TileManager(mapView, this, minZoom, maxZoom, cacheLimit); + mTileManager = new TileManager(map, this, minZoom, maxZoom, cacheLimit); // Instantiate TileLoader threads mTileLoader = new ArrayList(); diff --git a/vtm/src/org/oscim/layers/tile/TileManager.java b/vtm/src/org/oscim/layers/tile/TileManager.java index f58bc646..6f1f9b31 100644 --- a/vtm/src/org/oscim/layers/tile/TileManager.java +++ b/vtm/src/org/oscim/layers/tile/TileManager.java @@ -30,8 +30,8 @@ import org.oscim.utils.FastMath; import org.oscim.utils.ScanBox; import org.oscim.utils.quadtree.QuadTree; import org.oscim.utils.quadtree.QuadTreeIndex; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; /** * @TODO - prefetching to cache file - this class should probably not be in @@ -50,8 +50,8 @@ public class TileManager { // cache limit threshold private static final int CACHE_THRESHOLD = 30; - private final MapView mMapView; - private final MapViewPosition mMapViewPosition; + private final Map mMap; + private final Viewport mViewport; // cache for all tiles private MapTile[] mTiles; @@ -112,14 +112,14 @@ public class TileManager { private final float[] mMapPlane = new float[8]; private final TileLayer mTileLayer; - public TileManager(MapView mapView, TileLayer tileLayer, int minZoom, int maxZoom, int cacheLimit) { - mMapView = mapView; + public TileManager(Map map, TileLayer tileLayer, int minZoom, int maxZoom, int cacheLimit) { + mMap = map; mTileLayer = tileLayer; mMaxZoom = maxZoom; mMinZoom = minZoom; mCacheLimit = cacheLimit; - mMapViewPosition = mapView.getMapViewPosition(); + mViewport = map.getViewport(); jobQueue = new JobQueue(); mJobs = new ArrayList(); @@ -168,7 +168,7 @@ public class TileManager { mTilesCount = 0; // set up TileSet large enough to hold current tiles - int num = Math.max(mMapView.getWidth(), mMapView.getHeight()); + int num = Math.max(mMap.getWidth(), mMap.getHeight()); int size = Tile.SIZE >> 1; int numTiles = (num * num) / (size * size) * 4; @@ -212,7 +212,7 @@ public class TileManager { tileZoom = match; } - mMapViewPosition.getMapViewProjection(mMapPlane); + mViewport.getMapViewProjection(mMapPlane); // scan visible tiles. callback function calls 'addTile' // which updates mNewTiles @@ -260,7 +260,7 @@ public class TileManager { } //Log.d(TAG, newCnt + " << " + Arrays.deepToString(mCurrentTiles.tiles)); // request rendering as tiles changed - mMapView.render(); + mMap.render(); } /* Add tile jobs to queue */ @@ -590,7 +590,7 @@ public class TileManager { // locked means the tile is visible or referenced by // a tile that might be visible. if (tile.isLocked()) - mMapView.render(); + mMap.render(); return true; } diff --git a/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java b/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java index e6988b6a..3cd0cdca 100644 --- a/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java +++ b/vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java @@ -32,7 +32,7 @@ import org.oscim.layers.tile.bitmap.TileSource.FadeStep; import org.oscim.renderer.sublayers.BitmapLayer; import org.oscim.renderer.sublayers.Layers; import org.oscim.utils.FastMath; -import org.oscim.view.MapView; +import org.oscim.view.Map; public class BitmapTileLayer extends TileLayer { @@ -43,8 +43,8 @@ public class BitmapTileLayer extends TileLayer { final TileSource mTileSource; private final FadeStep[] mFade; - public BitmapTileLayer(MapView mapView, TileSource tileSource) { - super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); + public BitmapTileLayer(Map map, TileSource tileSource) { + super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); mTileSource = tileSource; mFade = mTileSource.getFadeSteps(); diff --git a/vtm/src/org/oscim/layers/tile/geojson/GeoJsonTileLayer.java b/vtm/src/org/oscim/layers/tile/geojson/GeoJsonTileLayer.java index 4946f7f2..a7c4706b 100644 --- a/vtm/src/org/oscim/layers/tile/geojson/GeoJsonTileLayer.java +++ b/vtm/src/org/oscim/layers/tile/geojson/GeoJsonTileLayer.java @@ -14,7 +14,7 @@ */ package org.oscim.layers.tile.geojson; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.TileLayer; import org.oscim.layers.tile.TileLoader; @@ -22,8 +22,8 @@ import org.oscim.layers.tile.TileManager; public class GeoJsonTileLayer extends TileLayer { - public GeoJsonTileLayer(MapView mapView) { - super(mapView); + public GeoJsonTileLayer(Map map) { + super(map); } @Override diff --git a/vtm/src/org/oscim/layers/tile/test/TestTileLayer.java b/vtm/src/org/oscim/layers/tile/test/TestTileLayer.java index 0c67ec0b..2cc261f4 100644 --- a/vtm/src/org/oscim/layers/tile/test/TestTileLayer.java +++ b/vtm/src/org/oscim/layers/tile/test/TestTileLayer.java @@ -14,7 +14,7 @@ */ package org.oscim.layers.tile.test; -import org.oscim.view.MapView; +import org.oscim.view.Map; import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Paint.Cap; import org.oscim.core.GeometryBuffer; @@ -33,8 +33,8 @@ import org.oscim.backend.Log; public class TestTileLayer extends TileLayer { final static String TAG = TestTileLayer.class.getName(); - public TestTileLayer(MapView mapView) { - super(mapView); + public TestTileLayer(Map map) { + super(map); } @Override diff --git a/vtm/src/org/oscim/layers/tile/vector/MapTileLayer.java b/vtm/src/org/oscim/layers/tile/vector/MapTileLayer.java index 44d663c4..c579ac70 100644 --- a/vtm/src/org/oscim/layers/tile/vector/MapTileLayer.java +++ b/vtm/src/org/oscim/layers/tile/vector/MapTileLayer.java @@ -25,7 +25,7 @@ import org.oscim.tilesource.ITileDataSource; import org.oscim.tilesource.MapInfo; import org.oscim.tilesource.TileSource; import org.oscim.tilesource.TileSource.OpenResult; -import org.oscim.view.MapView; +import org.oscim.view.Map; /** * The vector-tile-map layer. This class manages instances of @@ -37,8 +37,8 @@ public class MapTileLayer extends TileLayer { private TileSource mTileSource; - public MapTileLayer(MapView mapView) { - super(mapView); + public MapTileLayer(Map map) { + super(map); } @Override @@ -78,7 +78,7 @@ public class MapTileLayer extends TileLayer { mTileManager.setZoomTable(mTileSource.getMapInfo().zoomLevel); - mMapView.clearMap(); + mMap.clearMap(); resumeLoaders(); diff --git a/vtm/src/org/oscim/renderer/GLRenderer.java b/vtm/src/org/oscim/renderer/GLRenderer.java index 483c0177..9b819945 100644 --- a/vtm/src/org/oscim/renderer/GLRenderer.java +++ b/vtm/src/org/oscim/renderer/GLRenderer.java @@ -31,8 +31,8 @@ import org.oscim.utils.GlUtils; import org.oscim.utils.Matrix4; import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.Pool; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; public class GLRenderer { private static final String TAG = GLRenderer.class.getName(); @@ -46,10 +46,10 @@ public class GLRenderer { static int CACHE_TILES = CACHE_TILES_MAX; - private static MapView mMapView; + private static Map mMap; public static int screenWidth, screenHeight; - private static MapViewPosition mMapViewPosition; + private static Viewport mViewport; private static MapPosition mMapPosition; private static short[] mFillCoords; @@ -79,9 +79,9 @@ public class GLRenderer { mvp.setScale(ratio, ratio, ratio); else mvp.setTransScale( - (-screenWidth / 2) * ratio * scale, - (-screenHeight / 2) * ratio * scale, - ratio); + (-screenWidth / 2) * ratio * scale, + (-screenHeight / 2) * ratio * scale, + ratio); mvp.multiplyLhs(proj); } @@ -93,6 +93,7 @@ public class GLRenderer { static float[] mClearColor = null; public static int mQuadIndicesID; + private static int mQuadVerticesID; public final static int maxQuads = 64; private static boolean mUpdateColor = false; @@ -101,14 +102,16 @@ public class GLRenderer { // static ReentrantLock tilelock = new ReentrantLock(); public static Object drawlock = new Object(); + public static long frametime; + /** - * @param mapView + * @param map * the MapView */ - public GLRenderer(MapView mapView) { + public GLRenderer(Map map) { - mMapView = mapView; - mMapViewPosition = mapView.getMapViewPosition(); + mMap = map; + mViewport = map.getViewport(); mMapPosition = new MapPosition(); mMatrices = new Matrices(); @@ -127,7 +130,7 @@ public class GLRenderer { mFillCoords[7] = min; } - public static void setBackgroundColor(int color){ + public static void setBackgroundColor(int color) { mClearColor = GlUtils.colorToFloat(color); mUpdateColor = true; } @@ -146,8 +149,8 @@ public class GLRenderer { size = (1 << 15); ByteBuffer buf = ByteBuffer - .allocateDirect(size) - .order(ByteOrder.nativeOrder()); + .allocateDirect(size) + .order(ByteOrder.nativeOrder()); this.floatBuffer = buf.asFloatBuffer(); this.shortBuffer = buf.asShortBuffer(); @@ -155,19 +158,20 @@ public class GLRenderer { this.tmpBufferSize = size; } } - static class BufferPool extends Pool{ + + static class BufferPool extends Pool { private BufferItem mUsedBuffers; @Override - protected BufferItem createItem() { + protected BufferItem createItem() { // unused; return null; - } + } - public BufferItem get(int size){ + public BufferItem get(int size) { BufferItem b = pool; - if (b == null){ + if (b == null) { b = new BufferItem(); } else { pool = b.next; @@ -181,12 +185,13 @@ public class GLRenderer { return b; } - public void releaseBuffers(){ + public void releaseBuffers() { mBufferPool.releaseAll(mUsedBuffers); mUsedBuffers = null; } } + // Do not use the same buffer to upload data within a frame twice // - Contrary to what the OpenGL doc says data seems *not* to be // *always* copied after glBufferData returns... @@ -194,7 +199,6 @@ public class GLRenderer { // but not when using libgdx bindings (LWJGL or AndroidGL20) private static BufferPool mBufferPool = new BufferPool(); - /** * Only use on GL Thread! Get a native ShortBuffer for temporary use. */ @@ -223,7 +227,7 @@ public class GLRenderer { } public static boolean uploadLayers(Layers layers, int newSize, - boolean addFill) { + boolean addFill) { // add fill coordinates if (addFill) newSize += 8; @@ -238,10 +242,10 @@ public class GLRenderer { if (newSize != sbuf.remaining()) { Log.d(TAG, "wrong size: " - + " new size: " + newSize - + " buffer pos: " + sbuf.position() - + " buffer limit: " + sbuf.limit() - + " buffer fill: " + sbuf.remaining()); + + " new size: " + newSize + + " buffer pos: " + sbuf.position() + + " buffer limit: " + sbuf.limit() + + " buffer fill: " + sbuf.remaining()); return false; } newSize *= SHORT_BYTES; @@ -254,7 +258,8 @@ public class GLRenderer { // prevent main thread recreating all tiles (updateMap) // while rendering is going on. - synchronized(drawlock){ + synchronized (drawlock) { + frametime = System.currentTimeMillis(); draw(); } @@ -272,8 +277,8 @@ public class GLRenderer { GL.glDepthMask(true); GL.glStencilMask(0xFF); GL.glClear(GL20.GL_COLOR_BUFFER_BIT - | GL20.GL_DEPTH_BUFFER_BIT - | GL20.GL_STENCIL_BUFFER_BIT); + | GL20.GL_DEPTH_BUFFER_BIT + | GL20.GL_STENCIL_BUFFER_BIT); GLState.blend(false); GL.glDisable(GL20.GL_BLEND); @@ -282,17 +287,17 @@ public class GLRenderer { MapPosition pos = mMapPosition; - synchronized (mMapViewPosition) { + synchronized (mViewport) { // update MapPosition - mMapViewPosition.updateAnimation(); + mViewport.updateAnimation(); // get current MapPosition - changed = mMapViewPosition.getMapPosition(pos); + changed = mViewport.getMapPosition(pos); if (changed) - mMapViewPosition.getMapViewProjection(mMatrices.mapPlane); + mViewport.getMapViewProjection(mMatrices.mapPlane); - mMapViewPosition.getMatrix(mMatrices.view, mMatrices.proj, mMatrices.viewproj); + mViewport.getMatrix(mMatrices.view, mMatrices.proj, mMatrices.viewproj); if (debugView) { mMatrices.mvp.setScale(0.5f, 0.5f, 1); @@ -305,7 +310,7 @@ public class GLRenderer { //GL.glBindTexture(GL20.GL_TEXTURE_2D, 0); /* update layers */ - RenderLayer[] layers = mMapView.getLayerManager().getRenderLayers(); + RenderLayer[] layers = mMap.getLayerManager().getRenderLayers(); for (int i = 0, n = layers.length; i < n; i++) layers[i].update(pos, changed, mMatrices); @@ -346,7 +351,7 @@ public class GLRenderer { screenWidth = width; screenHeight = height; - mMapViewPosition.getMatrix(null, mMatrices.proj, null); + mViewport.getMatrix(null, mMatrices.proj, null); if (debugView) { // modify this to scale only the view, to see better which tiles @@ -365,14 +370,14 @@ public class GLRenderer { GL.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); if (!mNewSurface) { - mMapView.updateMap(false); + mMap.updateMap(false); return; } mNewSurface = false; // upload quad indices used by Texture- and LineTexRenderer - int[] vboIds = GlUtils.glGenBuffers(1); + int[] vboIds = GlUtils.glGenBuffers(2); mQuadIndicesID = vboIds[0]; int maxIndices = maxQuads * 6; @@ -391,17 +396,30 @@ public class GLRenderer { buf.flip(); GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, - mQuadIndicesID); + mQuadIndicesID); GL.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, - indices.length * 2, buf, GL20.GL_STATIC_DRAW); + indices.length * 2, buf, GL20.GL_STATIC_DRAW); GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0); + // initialize default quad + FloatBuffer floatBuffer = GLRenderer.getFloatBuffer(indices.length); + + float[] quad = new float[] { -1, -1, -1, 1, 1, -1, 1, 1 }; + floatBuffer.put(quad); + floatBuffer.flip(); + mQuadVerticesID = vboIds[1]; + + GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mQuadVerticesID); + GL.glBufferData(GL20.GL_ARRAY_BUFFER, + quad.length * 4, floatBuffer, GL20.GL_STATIC_DRAW); + GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0); + if (mClearColor != null) mUpdateColor = true; GLState.init(); - mMapView.updateMap(true); + mMap.updateMap(true); } public void onSurfaceCreated() { @@ -422,4 +440,13 @@ public class GLRenderer { private boolean mNewSurface; public static final boolean debugView = false; + + public static int getQuadIndicesVBO() { + return mQuadIndicesID; + } + + public static int getQuadVertexVBO() { + return mQuadVerticesID; + } + } diff --git a/vtm/src/org/oscim/renderer/layers/CustomRenderLayer.java b/vtm/src/org/oscim/renderer/layers/CustomRenderLayer.java index f00d18d5..1254110d 100644 --- a/vtm/src/org/oscim/renderer/layers/CustomRenderLayer.java +++ b/vtm/src/org/oscim/renderer/layers/CustomRenderLayer.java @@ -25,7 +25,7 @@ import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLState; import org.oscim.renderer.RenderLayer; import org.oscim.utils.GlUtils; -import org.oscim.view.MapView; +import org.oscim.view.Map; /* @@ -39,7 +39,7 @@ public class CustomRenderLayer extends RenderLayer { private static final GL20 GL = GLAdapter.get(); - private final MapView mMapView; + private final Map mMap; private int mProgramObject; private int hVertexPosition; @@ -54,8 +54,8 @@ public class CustomRenderLayer extends RenderLayer { }; private boolean mInitialized; - public CustomRenderLayer(MapView mapView) { - mMapView = mapView; + public CustomRenderLayer(Map map) { + mMap = map; } // ---------- everything below runs in GLRender Thread ---------- @@ -113,7 +113,7 @@ public class CustomRenderLayer extends RenderLayer { // set mvp (tmp) matrix relative to mMapPosition // i.e. fixed on the map - float ratio = 1f / mMapView.getWidth(); + float ratio = 1f / mMap.getWidth(); m.mvp.setScale(ratio, ratio, 1); m.mvp.multiplyLhs(m.proj); diff --git a/vtm/src/org/oscim/renderer/layers/TextRenderLayer.java b/vtm/src/org/oscim/renderer/layers/TextRenderLayer.java index a35f44e8..1df55544 100644 --- a/vtm/src/org/oscim/renderer/layers/TextRenderLayer.java +++ b/vtm/src/org/oscim/renderer/layers/TextRenderLayer.java @@ -49,8 +49,8 @@ import org.oscim.utils.FastMath; import org.oscim.utils.OBB2D; import org.oscim.utils.pool.LList; import org.oscim.utils.pool.Pool; -import org.oscim.view.MapView; -import org.oscim.view.MapViewPosition; +import org.oscim.view.Map; +import org.oscim.view.Viewport; public class TextRenderLayer extends BasicRenderLayer { @@ -62,7 +62,7 @@ public class TextRenderLayer extends BasicRenderLayer { //private final static long MAX_RELABEL_DELAY = 200; - private final MapViewPosition mMapViewPosition; + private final Viewport mViewport; private final TileSet mTileSet; private MapPosition mTmpPos; @@ -157,11 +157,11 @@ public class TextRenderLayer extends BasicRenderLayer { private float mSquareRadius; private int mRelabelCnt; private final TileRenderLayer mTileLayer; - private final MapView mMapView; + private final Map mMap; - public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) { - mMapView = mapView; - mMapViewPosition = mapView.getMapViewPosition(); + public TextRenderLayer(Map map, TileRenderLayer baseLayer) { + mMap = map; + mViewport = map.getViewport(); mTileLayer = baseLayer; mTileSet = new TileSet(); layers.textureLayers = new TextLayer(); @@ -318,9 +318,9 @@ public class TextRenderLayer extends BasicRenderLayer { //float[] coords = mTmpCoords; MapPosition pos = mTmpPos; - synchronized (mMapViewPosition) { - changedPos = mMapViewPosition.getMapPosition(pos); - //mMapViewPosition.getMapViewProjection(coords); + synchronized (mViewport) { + changedPos = mViewport.getMapPosition(pos); + //mViewport.getMapViewProjection(coords); } if (!changedTiles && !changedPos) { @@ -329,11 +329,11 @@ public class TextRenderLayer extends BasicRenderLayer { } Layers dbg = null; - if (mMapView.getDebugSettings().debugLabels) + if (mMap.getDebugSettings().debugLabels) dbg = new Layers(); - int mw = (mMapView.getWidth() + Tile.SIZE) / 2; - int mh = (mMapView.getHeight() + Tile.SIZE) / 2; + int mw = (mMap.getWidth() + Tile.SIZE) / 2; + int mh = (mMap.getHeight() + Tile.SIZE) / 2; mSquareRadius = mw * mw + mh * mh; MapTile[] tiles = mTileSet.tiles; @@ -680,7 +680,7 @@ public class TextRenderLayer extends BasicRenderLayer { // labelsChanged = updateLabels(); // // if (!isCancelled() && labelsChanged) -// mMapView.render(); +// mMap.render(); // // //Log.d(TAG, "relabel " + labelsChanged); // diff --git a/vtm/src/org/oscim/utils/GlUtils.java b/vtm/src/org/oscim/utils/GlUtils.java index d199e446..88cad027 100644 --- a/vtm/src/org/oscim/utils/GlUtils.java +++ b/vtm/src/org/oscim/utils/GlUtils.java @@ -448,8 +448,8 @@ public class GlUtils { // // public static void addOffsetM(float[] matrix, int delta) { // // from http://www.mathfor3dgameprogramming.com/code/Listing9.1.cpp - // // float n = MapViewPosition.VIEW_NEAR; - // // float f = MapViewPosition.VIEW_FAR; + // // float n = Viewport.VIEW_NEAR; + // // float f = Viewport.VIEW_FAR; // // float pz = 1; // // float epsilon = -2.0f * f * n * delta / ((f + n) * pz * (pz + delta)); // float epsilon = 1.0f / (1 << 11); diff --git a/vtm/src/org/oscim/utils/ScanBox.java b/vtm/src/org/oscim/utils/ScanBox.java index d4a5cf72..5fe7483e 100644 --- a/vtm/src/org/oscim/utils/ScanBox.java +++ b/vtm/src/org/oscim/utils/ScanBox.java @@ -25,7 +25,7 @@ import org.oscim.core.Tile; * bounds to the map. * * use: - * MapViewPosition.getMapViewProjection(box) + * Viewport.getMapViewProjection(box) * yourScanBox.scan(pos.x, pos.y, pos.scale, zoomLevel, coords); * * where zoomLevel is the zoom-level for which tile coordinates diff --git a/vtm/src/org/oscim/view/LayerManager.java b/vtm/src/org/oscim/view/LayerManager.java index 52d8c8e4..a8079eb5 100644 --- a/vtm/src/org/oscim/view/LayerManager.java +++ b/vtm/src/org/oscim/view/LayerManager.java @@ -428,14 +428,14 @@ public class LayerManager extends AbstractList { // // public boolean onCreateOptionsMenu(final Menu pMenu, final int // menuIdOffset, - // final MapView mapView) { + // final MapView map) { // boolean result = true; // for (final Layer overlay : this.overlaysReversed()) { // if ((overlay instanceof ILayerMenuProvider) // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) { // result &= ((ILayerMenuProvider) overlay).onCreateOptionsMenu(pMenu, // menuIdOffset, - // mapView); + // map); // } // } // @@ -443,7 +443,7 @@ public class LayerManager extends AbstractList { // ILayerMenuProvider) // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) { // result &= mTilesLayer.onCreateOptionsMenu(pMenu, menuIdOffset, - // mapView); + // map); // } // // return result; @@ -451,19 +451,19 @@ public class LayerManager extends AbstractList { // // public boolean onPrepareOptionsMenu(final Menu pMenu, final int // menuIdOffset, - // final MapView mapView) { + // final MapView map) { // for (final Layer overlay : this.overlaysReversed()) { // if ((overlay instanceof ILayerMenuProvider) // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) { // ((ILayerMenuProvider) overlay).onPrepareOptionsMenu(pMenu, - // menuIdOffset, mapView); + // menuIdOffset, map); // } // } // // if ((mTilesLayer != null) && (mTilesLayer instanceof // ILayerMenuProvider) // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) { - // mTilesLayer.onPrepareOptionsMenu(pMenu, menuIdOffset, mapView); + // mTilesLayer.onPrepareOptionsMenu(pMenu, menuIdOffset, map); // } // // return true; @@ -471,13 +471,13 @@ public class LayerManager extends AbstractList { // // public boolean onOptionsItemSelected(final MenuItem item, final int // menuIdOffset, - // final MapView mapView) { + // final MapView map) { // for (final Layer overlay : this.overlaysReversed()) { // if ((overlay instanceof ILayerMenuProvider) // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled() // && ((ILayerMenuProvider) overlay).onOptionsItemSelected(item, // menuIdOffset, - // mapView)) { + // map)) { // return true; // } // } @@ -487,7 +487,7 @@ public class LayerManager extends AbstractList { // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled() // && ((ILayerMenuProvider) mTilesLayer).onOptionsItemSelected(item, // menuIdOffset, - // mapView)) { + // map)) { // return true; // } // diff --git a/vtm/src/org/oscim/view/MapView.java b/vtm/src/org/oscim/view/Map.java similarity index 85% rename from vtm/src/org/oscim/view/MapView.java rename to vtm/src/org/oscim/view/Map.java index c1d05369..b702d673 100644 --- a/vtm/src/org/oscim/view/MapView.java +++ b/vtm/src/org/oscim/view/Map.java @@ -33,23 +33,27 @@ import org.oscim.theme.ThemeLoader; import org.oscim.tilesource.TileSource; import org.oscim.utils.async.AsyncExecutor; -public abstract class MapView { +public abstract class Map { - private static final String TAG = MapView.class.getName(); + private static final String TAG = Map.class.getName(); //public static boolean enableClosePolygons; private final LayerManager mLayerManager; - private final MapViewPosition mMapViewPosition; + private final Viewport mViewport; private final MapPosition mMapPosition; private final AsyncExecutor mAsyncExecutor; private DebugSettings mDebugSettings; protected boolean mClearMap; + protected final MapEventLayer mEventLayer; - public MapView() { + private MapTileLayer mBaseLayer; + //private BitmapTileLayer mBackgroundLayer; - mMapViewPosition = new MapViewPosition(this); + public Map() { + + mViewport = new Viewport(this); mMapPosition = new MapPosition(); mLayerManager = new LayerManager(); mAsyncExecutor = new AsyncExecutor(2); @@ -58,11 +62,13 @@ public abstract class MapView { mDebugSettings = new DebugSettings(); MapTileLoader.setDebugSettings(mDebugSettings); - mLayerManager.add(0, new MapEventLayer(this)); + mEventLayer = new MapEventLayer(this); + mLayerManager.add(0, mEventLayer); } - private MapTileLayer mBaseLayer; - //private BitmapTileLayer mBackgroundLayer; + public MapEventLayer getEventLayer() { + return mEventLayer; + } public MapTileLayer setBaseMap(TileSource tileSource) { mBaseLayer = new MapTileLayer(this); @@ -82,17 +88,25 @@ public abstract class MapView { return null; } + private InternalRenderTheme mCurrentTheme; + public void setTheme(InternalRenderTheme theme) { if (mBaseLayer == null) { Log.e(TAG, "No base layer set"); throw new IllegalStateException(); } + if (mCurrentTheme == theme){ + Log.d(TAG, "same theme: " + theme); + return; + } IRenderTheme t = ThemeLoader.load(theme); if (t == null) { Log.e(TAG, "Invalid theme"); throw new IllegalStateException(); } + + mCurrentTheme = theme; mBaseLayer.setRenderTheme(t); GLRenderer.setBackgroundColor(t.getMapBackground()); @@ -158,7 +172,7 @@ public abstract class MapView { boolean changed = false; // get the current MapPosition - changed |= mMapViewPosition.getMapPosition(mMapPosition); + changed |= mViewport.getMapPosition(mMapPosition); mLayerManager.onUpdate(mMapPosition, changed, mClearMap); mClearMap = false; @@ -174,7 +188,11 @@ public abstract class MapView { } public void setMapPosition(MapPosition mapPosition) { - mMapViewPosition.setMapPosition(mapPosition); + mViewport.setMapPosition(mapPosition); + } + + public void getMapPosition(MapPosition mapPosition) { + mViewport.getMapPosition(mapPosition); } /** @@ -185,15 +203,15 @@ public abstract class MapView { */ public void setCenter(GeoPoint geoPoint) { - mMapViewPosition.setMapCenter(geoPoint); + mViewport.setMapCenter(geoPoint); updateMap(true); } /** - * @return MapViewPosition + * @return Viewport */ - public MapViewPosition getMapViewPosition() { - return mMapViewPosition; + public Viewport getViewport() { + return mViewport; } /** @@ -215,7 +233,6 @@ public abstract class MapView { * @return estimated visible axis aligned bounding box */ public BoundingBox getBoundingBox() { - return mMapViewPosition.getViewBox(); + return mViewport.getViewBox(); } - } diff --git a/vtm/src/org/oscim/view/MapViewPosition.java b/vtm/src/org/oscim/view/Viewport.java similarity index 84% rename from vtm/src/org/oscim/view/MapViewPosition.java rename to vtm/src/org/oscim/view/Viewport.java index ead0a3f6..98c03125 100644 --- a/vtm/src/org/oscim/view/MapViewPosition.java +++ b/vtm/src/org/oscim/view/Viewport.java @@ -16,6 +16,7 @@ package org.oscim.view; import org.oscim.core.BoundingBox; +import org.oscim.core.Box; import org.oscim.core.GeoPoint; import org.oscim.core.MapPosition; import org.oscim.core.MercatorProjection; @@ -25,8 +26,8 @@ import org.oscim.core.Tile; import org.oscim.utils.FastMath; import org.oscim.utils.Matrix4; -public class MapViewPosition { - private static final String TAG = MapViewPosition.class.getName(); +public class Viewport { + //private static final String TAG = Viewport.class.getName(); // needs to fit for int: 2 * 20 * Tile.SIZE public final static int MAX_ZOOMLEVEL = 20; @@ -35,9 +36,9 @@ public class MapViewPosition { public final static double MAX_SCALE = (1 << MAX_ZOOMLEVEL); public final static double MIN_SCALE = (1 << MIN_ZOOMLEVEL); - private final static float MAX_ANGLE = 65; + private final static float MAX_TILT = 65; - private final MapView mMapView; + private final Map mMap; private double mAbsScale; private double mAbsX; @@ -68,7 +69,9 @@ public class MapViewPosition { private final PointD mMovePoint = new PointD(); private final float[] mv = new float[4]; private final float[] mu = new float[4]; - private final float[] mBBoxCoords = new float[8]; + private final float[] mViewCoords = new float[8]; + + private final Box mMapBBox = new Box(); private float mHeight, mWidth; @@ -78,8 +81,8 @@ public class MapViewPosition { // scale map plane at VIEW_DISTANCE to near plane public final static float VIEW_SCALE = (VIEW_NEAR / VIEW_DISTANCE) * 0.5f; - MapViewPosition(MapView map) { - mMapView = map; + Viewport(Map map) { + mMap = map; mAbsScale = 4; mAbsX = 0.5; @@ -196,17 +199,25 @@ public class MapViewPosition { * and the map plane */ private float getZ(float y) { + if (y == 0) + return 0; + // origin is moved by VIEW_DISTANCE double cx = VIEW_DISTANCE; // 'height' of the ray double ry = y * (mHeight / mWidth) * 0.5f; - // tilt of the plane (center is kept on x = 0) - double t = Math.toRadians(mTilt); - double px = y * Math.sin(t); - double py = y * Math.cos(t); + double ua; - double ua = 1 + (px * ry) / (py * cx); + if (y == 0) + ua = 1; + else { + // tilt of the plane (center is kept on x = 0) + double t = Math.toRadians(mTilt); + double px = y * Math.sin(t); + double py = y * Math.cos(t); + ua = 1 + (px * ry) / (py * cx); + } mv[0] = 0; mv[1] = (float) (ry / ua); @@ -241,46 +252,46 @@ public class MapViewPosition { * @return BoundingBox containing view */ public synchronized BoundingBox getViewBox() { + getViewBox(mMapBBox); - float[] coords = mBBoxCoords; - // get depth at bottom and top - float t = getZ(1); - float t2 = getZ(-1); - - // project screen corners onto map - unproject(1, -1, t, coords, 0); - unproject(-1, -1, t, coords, 2); - unproject(-1, 1, t2, coords, 4); - unproject(1, 1, t2, coords, 6); - - double minX = Double.MAX_VALUE; - double minY = Double.MAX_VALUE; - double maxX = Double.MIN_VALUE; - double maxY = Double.MIN_VALUE; - - // get axis-aligned bbox coordinates enclosing - // enclosing the map trapezoid - for (int i = 0; i < 8; i += 2) { - double dx = mCurX - coords[i + 0]; - double dy = mCurY - coords[i + 1]; - - minX = Math.min(minX, dx); - maxX = Math.max(maxX, dx); - minY = Math.min(minY, dy); - maxY = Math.max(maxY, dy); - } - - // scale map-pixel coordinates at current scale - // to absolute coordinates and apply mercator - // projection. - double minLon = MercatorProjection.toLongitude(minX / mCurScale); - double maxLon = MercatorProjection.toLongitude(maxX / mCurScale); - double minLat = MercatorProjection.toLatitude(maxY / mCurScale); - double maxLat = MercatorProjection.toLatitude(minY / mCurScale); + // scale map-pixel coordinates at current scale to + // absolute coordinates and apply mercator projection. + double minLon = MercatorProjection.toLongitude(mMapBBox.minX); + double maxLon = MercatorProjection.toLongitude(mMapBBox.maxX); + // sic(k) + double minLat = MercatorProjection.toLatitude(mMapBBox.maxY); + double maxLat = MercatorProjection.toLatitude(mMapBBox.minY); return new BoundingBox(minLat, minLon, maxLat, maxLon); } + /** + * Get the minimal axis-aligned BoundingBox that encloses + * the visible part of the map. Sets box to map coordinates: + * minX,minY,maxY,maxY + */ + public synchronized void getViewBox(Box box) { + float[] coords = mViewCoords; + getMapViewProjection(coords); + + box.minX = coords[0]; + box.maxX = coords[0]; + box.minY = coords[1]; + box.maxY = coords[1]; + + for (int i = 2; i < 8; i += 2) { + box.minX = Math.min(box.minX, coords[i]); + box.maxX = Math.max(box.maxX, coords[i]); + box.minY = Math.min(box.minY, coords[i + 1]); + box.maxY = Math.max(box.maxY, coords[i + 1]); + } + + box.minX = (mCurX + box.minX) / mCurScale; + box.maxX = (mCurX + box.maxX) / mCurScale; + box.minY = (mCurY + box.minY) / mCurScale; + box.maxY = (mCurY + box.maxY) / mCurScale; + } + /** * For x, y in screen coordinates set Point to map-tile * coordinates at returned scale. @@ -308,16 +319,29 @@ public class MapViewPosition { /** * Get the GeoPoint for x,y in screen coordinates. - * (only used by MapEventsOverlay currently) * + * @deprecated * @param x screen coordinate * @param y screen coordinate * @return the corresponding GeoPoint */ public synchronized GeoPoint fromScreenPixels(float x, float y) { + fromScreenPixels(x, y, mMovePoint); + return new GeoPoint( + MercatorProjection.toLatitude(mMovePoint.y), + MercatorProjection.toLongitude(mMovePoint.x)); + } + + /** + * Get the map position for x,y in screen coordinates. + * + * @param x screen coordinate + * @param y screen coordinate + */ + public synchronized void fromScreenPixels(double x, double y, PointD out) { // scale to -1..1 - float mx = 1 - (x / mWidth * 2); - float my = 1 - (y / mHeight * 2); + float mx = (float) (1 - (x / mWidth * 2)); + float my = (float) (1 - (y / mHeight * 2)); unproject(-mx, my, getZ(-my), mu, 0); @@ -340,33 +364,39 @@ public class MapViewPosition { else if (dy < 0) dy = 0; - GeoPoint p = new GeoPoint( - MercatorProjection.toLatitude(dy), - MercatorProjection.toLongitude(dx)); - - return p; + out.x = dx; + out.y = dy; } /** * Get the screen pixel for a GeoPoint * + * @deprecated * @param geoPoint the GeoPoint + * @param out Point projected to screen pixel relative to center + */ + public synchronized void project(GeoPoint geoPoint, PointD out) { + MercatorProjection.project(geoPoint, out); + project(out.x, out.y, out); + } + + /** + * Get the screen pixel for map position + * * @param out Point projected to screen pixel */ - public synchronized void project(GeoPoint geoPoint, PointF out) { + public synchronized void project(double x, double y, PointD out) { - double x = MercatorProjection.longitudeToX(geoPoint.getLongitude()) * mCurScale; - double y = MercatorProjection.latitudeToY(geoPoint.getLatitude()) * mCurScale; - - mv[0] = (float) (x - mCurX); - mv[1] = (float) (y - mCurY); + mv[0] = (float) (x * mCurScale - mCurX); + mv[1] = (float) (y * mCurScale - mCurY); mv[2] = 0; mv[3] = 1; mVPMatrix.prj(mv); - out.x = (int) (mv[0] * (mWidth / 2)); - out.y = (int) -(mv[1] * (mHeight / 2)); + + out.x = (mv[0] * (mWidth / 2)); + out.y = -(mv[1] * (mHeight / 2)); } private void updateMatrix() { @@ -415,7 +445,7 @@ public class MapViewPosition { } /** - * Moves this MapViewPosition by the given amount of pixels. + * Moves this Viewport by the given amount of pixels. * * @param mx the amount of pixels to move the map horizontally. * @param my the amount of pixels to move the map vertically. @@ -515,19 +545,16 @@ public class MapViewPosition { } public synchronized boolean tiltMap(float move) { - float tilt = FastMath.clamp(mTilt + move, 0, MAX_ANGLE); - - if (mTilt == tilt) - return false; - - setTilt(tilt); - - return true; + return setTilt(mTilt + move); } - public synchronized void setTilt(float f) { - mTilt = f; + public synchronized boolean setTilt(float tilt) { + tilt = FastMath.clamp(tilt, 0, MAX_TILT); + if (tilt == mTilt) + return false; + mTilt = tilt; updateMatrix(); + return true; } public synchronized float getTilt() { @@ -673,7 +700,7 @@ public class MapViewPosition { mDuration = duration; mAnimEnd = System.currentTimeMillis() + (long) duration; - mMapView.render(); + mMap.render(); } private void animCancel() { @@ -754,7 +781,7 @@ public class MapViewPosition { } updatePosition(); - mMapView.updateMap(true); + mMap.updateMap(true); animCancel(); return; @@ -793,10 +820,10 @@ public class MapViewPosition { // continue animation if (changed) { // inform other layers that position has changed - mMapView.updateMap(true); + mMap.updateMap(true); } else { // just render next frame - mMapView.render(); + mMap.render(); } }