refactor: rename MapView -> Map, MapViewPosition -> Viewport

This commit is contained in:
Hannes Janetzek 2013-09-03 04:17:49 +02:00
parent 07db32f394
commit 870363bf2f
39 changed files with 560 additions and 442 deletions

View File

@ -3,7 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<org.oscim.android.AndroidMapView <org.oscim.android.MapView
android:id="@+id/mapView" android:id="@+id/mapView"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" /> android:layout_height="fill_parent" />

View File

@ -1,6 +1,6 @@
package org.oscim.android.test; 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.labeling.LabelLayer;
import org.oscim.layers.overlay.BuildingOverlay; import org.oscim.layers.overlay.BuildingOverlay;
import org.oscim.layers.tile.vector.MapTileLayer; import org.oscim.layers.tile.vector.MapTileLayer;
@ -13,38 +13,38 @@ import android.view.Menu;
public class MapActivity extends org.oscim.android.MapActivity { public class MapActivity extends org.oscim.android.MapActivity {
private AndroidMapView mAndroidMapView; private MapView mMapView;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map); 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 tileSource = new OSciMap2TileSource();
//tileSource.setOption("url", "http://city.informatik.uni-bremen.de/osci/map-live"); //tileSource.setOption("url", "http://city.informatik.uni-bremen.de/osci/map-live");
TileSource tileSource = new OSciMap4TileSource(); TileSource tileSource = new OSciMap4TileSource();
tileSource.setOption("url", "http://city.informatik.uni-bremen.de/tiles/vtm"); tileSource.setOption("url", "http://city.informatik.uni-bremen.de/tiles/vtm");
MapTileLayer l = mMapView.setBaseMap(tileSource); MapTileLayer l = mMap.setBaseMap(tileSource);
//mMapView.setDebugSettings(new DebugSettings(false, false, true, false, false)); //mMap.setDebugSettings(new DebugSettings(false, false, true, false, false));
mMapView.getLayerManager().add(new BuildingOverlay(mMapView, l.getTileLayer())); mMap.getLayerManager().add(new BuildingOverlay(mMap, l.getTileLayer()));
mMapView.getLayerManager().add(new LabelLayer(mMapView, l.getTileLayer())); mMap.getLayerManager().add(new LabelLayer(mMap, l.getTileLayer()));
mMapView.setTheme(InternalRenderTheme.DEFAULT); mMap.setTheme(InternalRenderTheme.DEFAULT);
//mMapView.setTheme(InternalRenderTheme.TRONRENDER); //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)); //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); mMapView.setClickable(true);
mAndroidMapView.setFocusable(true); mMapView.setFocusable(true);
} }
@Override @Override

View File

@ -18,14 +18,14 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer;
import org.oscim.view.MapView; import org.oscim.view.Map;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
public class AndroidGLRenderer extends GLRenderer implements GLSurfaceView.Renderer{ public class AndroidGLRenderer extends GLRenderer implements GLSurfaceView.Renderer{
public AndroidGLRenderer(MapView mapView) { public AndroidGLRenderer(Map map) {
super(mapView); super(map);
} }
@Override @Override

View File

@ -14,7 +14,7 @@
*/ */
package org.oscim.android; package org.oscim.android;
import org.oscim.view.MapView; import org.oscim.view.Map;
import android.content.Context; import android.content.Context;
import android.hardware.Sensor; import android.hardware.Sensor;
@ -30,9 +30,9 @@ public class Compass {
if (Math.abs(event.values[0] - mAngle) > 0.25) { if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0]; mAngle = event.values[0];
if (mMapView != null) { if (mMap != null) {
mMapView.getMapViewPosition().setRotation(-mAngle); mMap.getViewport().setRotation(-mAngle);
mMapView.updateMap(true); mMap.updateMap(true);
} }
} }
} }
@ -43,13 +43,13 @@ public class Compass {
}; };
/* package */float mAngle = 0; /* package */float mAngle = 0;
/* package */MapView mMapView; /* package */Map mMap;
private final SensorManager mSensorManager; private final SensorManager mSensorManager;
private final Sensor mSensor; private final Sensor mSensor;
public Compass(MapActivity mapActivity, MapView mapView) { public Compass(MapActivity mapActivity, Map map) {
mMapView = mapView; mMap = map;
mSensorManager = (SensorManager) mapActivity mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE); .getSystemService(Context.SENSOR_SERVICE);
@ -63,6 +63,6 @@ public class Compass {
public void disable() { public void disable() {
mSensorManager.unregisterListener(mListener); mSensorManager.unregisterListener(mListener);
mMapView.getMapViewPosition().setRotation(0); mMap.getViewport().setRotation(0);
} }
} }

View File

@ -14,25 +14,25 @@
*/ */
package org.oscim.android; package org.oscim.android;
import org.oscim.view.MapView; import org.oscim.view.Map;
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
public class GLView extends GLSurfaceView { public class GLView extends GLSurfaceView {
MapView mMapView; Map mMap;
private final AndroidGLRenderer mRenderer; private final AndroidGLRenderer mRenderer;
public GLView(Context context, MapView mapView) { public GLView(Context context, Map map) {
super(context); super(context);
mMapView = mapView; mMap = map;
// Log.d(TAG, "init GLSurfaceLayer"); // Log.d(TAG, "init GLSurfaceLayer");
setEGLConfigChooser(new GlConfigChooser()); setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2); setEGLContextClientVersion(2);
setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS); setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
mRenderer = new AndroidGLRenderer(mMapView); mRenderer = new AndroidGLRenderer(mMap);
setRenderer(mRenderer); setRenderer(mRenderer);
//if (!MapView.debugFrameTime) //if (!MapView.debugFrameTime)

View File

@ -16,7 +16,7 @@ package org.oscim.android;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.view.MapView; import org.oscim.view.Map;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; 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 * 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. * subclasses need to override and no API key or registration is required.
* <p> * <p>
* A subclass may create a MapView either via one of the MapView constructors or * 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 PREFERENCES_FILE = "MapActivity";
//private static final String KEY_THEME = "Theme"; //private static final String KEY_THEME = "Theme";
private static boolean containsMapViewPosition(SharedPreferences sharedPreferences) { private static boolean containsViewport(SharedPreferences sharedPreferences) {
return sharedPreferences.contains(KEY_LATITUDE) return sharedPreferences.contains(KEY_LATITUDE)
&& sharedPreferences.contains(KEY_LONGITUDE) && sharedPreferences.contains(KEY_LONGITUDE)
&& sharedPreferences.contains(KEY_MAP_SCALE); && sharedPreferences.contains(KEY_MAP_SCALE);
} }
protected MapView mMapView; protected Map mMap;
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mMapView.destroy(); mMap.destroy();
} }
@Override @Override
@ -67,7 +67,7 @@ public abstract class MapActivity extends Activity {
// save the map position // save the map position
MapPosition mapPosition = new MapPosition(); MapPosition mapPosition = new MapPosition();
mMapView.getMapViewPosition().getMapPosition(mapPosition); mMap.getViewport().getMapPosition(mapPosition);
GeoPoint geoPoint = mapPosition.getGeoPoint(); GeoPoint geoPoint = mapPosition.getGeoPoint();
@ -75,7 +75,7 @@ public abstract class MapActivity extends Activity {
editor.putInt(KEY_LONGITUDE, geoPoint.longitudeE6); editor.putInt(KEY_LONGITUDE, geoPoint.longitudeE6);
editor.putFloat(KEY_MAP_SCALE, (float)mapPosition.scale); editor.putFloat(KEY_MAP_SCALE, (float)mapPosition.scale);
//editor.putString(KEY_THEME, mMapView.getRenderTheme()); //editor.putString(KEY_THEME, mMap.getRenderTheme());
editor.commit(); editor.commit();
} }
@ -93,16 +93,16 @@ public abstract class MapActivity extends Activity {
/** /**
* This method is called once by each MapView during its setup process. * This method is called once by each MapView during its setup process.
* *
* @param mapView * @param map
* the calling MapView. * the calling MapView.
*/ */
public final void registerMapView(MapView mapView) { public final void registerMapView(Map map) {
mMapView = mapView; mMap = map;
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE, SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
MODE_PRIVATE); MODE_PRIVATE);
if (containsMapViewPosition(sharedPreferences)) { if (containsViewport(sharedPreferences)) {
// get and set the map position and zoom level // get and set the map position and zoom level
int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0); int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 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.setPosition(latitudeE6 / 1E6, longitudeE6 / 1E6);
mapPosition.setScale(scale); mapPosition.setScale(scale);
mMapView.setMapPosition(mapPosition); mMap.setMapPosition(mapPosition);
} }
//String theme = sharedPreferences.getString(KEY_THEME, //String theme = sharedPreferences.getString(KEY_THEME,
@ -121,15 +121,15 @@ public abstract class MapActivity extends Activity {
// if (theme.startsWith("/")) { // if (theme.startsWith("/")) {
// try { // try {
// mapView.setRenderTheme(theme); // map.setRenderTheme(theme);
// } catch (FileNotFoundException e) { // } catch (FileNotFoundException e) {
// mapView.setRenderTheme(InternalRenderTheme.DEFAULT); // map.setRenderTheme(InternalRenderTheme.DEFAULT);
// } // }
// } else { // } else {
// try { // try {
// mapView.setRenderTheme(InternalRenderTheme.valueOf(theme)); // map.setRenderTheme(InternalRenderTheme.valueOf(theme));
// } catch (IllegalArgumentException e) { // } catch (IllegalArgumentException e) {
// mapView.setRenderTheme(InternalRenderTheme.DEFAULT); // map.setRenderTheme(InternalRenderTheme.DEFAULT);
// } // }
// } // }
} }

View File

@ -75,8 +75,8 @@ package org.oscim.android;
// private final Bitmap mMapScaleBitmap; // private final Bitmap mMapScaleBitmap;
// private final BitmapRenderLayer mBitmapLayer; // private final BitmapRenderLayer mBitmapLayer;
// //
// public MapScaleBar(MapView mapView) { // public MapScaleBar(MapView map) {
// super(mapView); // super(map);
// //
// mMapScaleBitmap = Bitmap.createBitmap( // mMapScaleBitmap = Bitmap.createBitmap(
// BITMAP_WIDTH, BITMAP_HEIGHT, // BITMAP_WIDTH, BITMAP_HEIGHT,
@ -89,7 +89,7 @@ package org.oscim.android;
// configurePaints(); // configurePaints();
// //
// mRedrawNeeded = true; // mRedrawNeeded = true;
// mLayer = mBitmapLayer = new BitmapRenderLayer(mapView); // mLayer = mBitmapLayer = new BitmapRenderLayer(map);
// mBitmapLayer.setBitmap(mMapScaleBitmap, 0, 0, // mBitmapLayer.setBitmap(mMapScaleBitmap, 0, 0,
// (int)(BITMAP_WIDTH * 1.2f), // (int)(BITMAP_WIDTH * 1.2f),
// (int)(BITMAP_HEIGHT * 1.2f)); // (int)(BITMAP_HEIGHT * 1.2f));

View File

@ -23,7 +23,7 @@ import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GLAdapter; import org.oscim.backend.GLAdapter;
import org.oscim.backend.Log; import org.oscim.backend.Log;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.view.MapView; import org.oscim.view.Map;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; 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 * 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. * 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 debugFrameTime = false;
public static final boolean testRegionZoom = false; public static final boolean testRegionZoom = false;
@ -52,7 +52,7 @@ public class AndroidMapView extends RelativeLayout {
private int mHeight; private int mHeight;
private final MapView mMapView; private final Map mMap;
final GLView mGLView; final GLView mGLView;
boolean mPausing = false; boolean mPausing = false;
@ -61,10 +61,6 @@ public class AndroidMapView extends RelativeLayout {
static { static {
System.loadLibrary("vtm-jni"); System.loadLibrary("vtm-jni");
//System.loadLibrary("tessellate"); //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 * if the context object is not an instance of
* {@link MapActivity} . * {@link MapActivity} .
*/ */
public AndroidMapView(Context context) { public MapView(Context context) {
this(context, null); this(context, null);
} }
@ -88,7 +84,7 @@ public class AndroidMapView extends RelativeLayout {
* {@link MapActivity} . * {@link MapActivity} .
*/ */
public AndroidMapView(Context context, AttributeSet attributeSet) { public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet); super(context, attributeSet);
if (!(context instanceof MapActivity)) { if (!(context instanceof MapActivity)) {
@ -96,7 +92,10 @@ public class AndroidMapView extends RelativeLayout {
"context is not an instance of MapActivity"); "context is not an instance of MapActivity");
} }
Log.logger = new AndroidLog();
CanvasAdapter.g = AndroidGraphics.INSTANCE;
AssetAdapter.g = new AndroidAssetAdapter(context); AssetAdapter.g = new AndroidAssetAdapter(context);
GLAdapter.g = new AndroidGL();
this.setWillNotDraw(true); this.setWillNotDraw(true);
@ -108,9 +107,9 @@ public class AndroidMapView extends RelativeLayout {
MapActivity mapActivity = (MapActivity) context; MapActivity mapActivity = (MapActivity) context;
final AndroidMapView m = this; final MapView m = this;
mMapView = new MapView(){ mMap = new Map(){
boolean mWaitRedraw; boolean mWaitRedraw;
@ -176,10 +175,10 @@ public class AndroidMapView extends RelativeLayout {
} }
}; };
mGLView = new GLView(context, mMapView); mGLView = new GLView(context, mMap);
mCompass = new Compass(mapActivity, mMapView); mCompass = new Compass(mapActivity, mMap);
mapActivity.registerMapView(mMapView); mapActivity.registerMapView(mMap);
LayoutParams params = new LayoutParams( LayoutParams params = new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT,
@ -187,21 +186,21 @@ public class AndroidMapView extends RelativeLayout {
addView(mGLView, params); addView(mGLView, params);
mMapView.clearMap(); mMap.clearMap();
mMapView.updateMap(false); mMap.updateMap(false);
} }
View getView(){ View getView(){
return this; return this;
} }
public MapView getMap() { public Map getMap() {
return mMapView; return mMap;
} }
public void onStop() { public void onStop() {
Log.d(TAG, "onStop"); Log.d(TAG, "onStop");
//mLayerManager.destroy(); //mMap.destroy();
} }
@ -230,7 +229,7 @@ public class AndroidMapView extends RelativeLayout {
mMotionEvent.wrap(motionEvent); mMotionEvent.wrap(motionEvent);
return mMapView.getLayerManager().handleMotionEvent(mMotionEvent); return mMap.getLayers().handleMotionEvent(mMotionEvent);
} }
// synchronized ??? // synchronized ???
@ -247,7 +246,7 @@ public class AndroidMapView extends RelativeLayout {
mInitialized = (mWidth > 0 && mHeight > 0); mInitialized = (mWidth > 0 && mHeight > 0);
if (mInitialized) if (mInitialized)
mMapView.getMapViewPosition().setViewport(width, height); mMap.getViewport().setViewport(width, height);
} }

View File

@ -55,7 +55,7 @@ package org.oscim.android;
// @Override // @Override
// public void onClick(View view) { // public void onClick(View view) {
// // if (MapView.testRegionZoom) // // if (MapView.testRegionZoom)
// // mMapView.mRegionLookup.updateRegion(1, null); // // mMap.mRegionLookup.updateRegion(1, null);
// // else // // else
// // MapZoomControls.this.zoom((byte) 1); // // MapZoomControls.this.zoom((byte) 1);
// mMapZoomControls.zoom((byte) 1); // mMapZoomControls.zoom((byte) 1);
@ -72,7 +72,7 @@ package org.oscim.android;
// @Override // @Override
// public void onClick(View view) { // public void onClick(View view) {
// // if (MapView.testRegionZoom) // // if (MapView.testRegionZoom)
// // mMapView.mRegionLookup.updateRegion(-1, null); // // mMap.mRegionLookup.updateRegion(-1, null);
// // else // // else
// mMapZoomControls.zoom((byte) -1); // mMapZoomControls.zoom((byte) -1);
// } // }
@ -117,10 +117,10 @@ package org.oscim.android;
// private final Handler mZoomControlsHideHandler; // private final Handler mZoomControlsHideHandler;
// private byte mZoomLevelMax; // private byte mZoomLevelMax;
// private byte mZoomLevelMin; // private byte mZoomLevelMin;
// private final MapView mMapView; // private final MapView mMap;
// //
// MapZoomControls(Context context, final MapView mapView) { // MapZoomControls(Context context, final MapView map) {
// mMapView = mapView; // mMap = map;
// mZoomControls = new ZoomControls(context); // mZoomControls = new ZoomControls(context);
// mShowMapZoomControls = true; // mShowMapZoomControls = true;
// mZoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX; // mZoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX;
@ -135,7 +135,7 @@ package org.oscim.android;
// //
// int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; // int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
// LayoutParams layoutParams = new LayoutParams(wrapContent, wrapContent); // 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. // * @return true if the zoom level was changed, false otherwise.
// */ // */
// boolean zoom(byte zoomLevelDiff) { // boolean zoom(byte zoomLevelDiff) {
// MapViewPosition mapViewPosition = mMapView.getMapViewPosition(); // Viewport mapPosition = mMap.getViewport();
// int z = mapViewPosition.getZoomLevel() + zoomLevelDiff; // int z = mapPosition.getZoomLevel() + zoomLevelDiff;
// if (zoomLevelDiff > 0) { // if (zoomLevelDiff > 0) {
// // check if zoom in is possible // // check if zoom in is possible
// if (z > mZoomLevelMax) { // if (z > mZoomLevelMax) {
@ -161,8 +161,8 @@ package org.oscim.android;
// } // }
// } // }
// //
// mapViewPosition.setZoomLevel((byte) z); // mapPosition.setZoomLevel((byte) z);
// mMapView.redrawMap(true); // mMap.redrawMap(true);
// //
// return true; // return true;
// } // }

View File

@ -81,10 +81,10 @@ class GwtGdxMap extends GdxMap {
p.angle = rotation; p.angle = rotation;
p.tilt = tilt; p.tilt = tilt;
mMapView.setMapPosition(p); mMap.setMapPosition(p);
//mMapView.getMapViewPosition().setTilt(tilt); //mMap.getViewport().setTilt(tilt);
//mMapView.getMapViewPosition().setRotation(rotation); //mMap.getViewport().setRotation(rotation);
String url = c.getTileUrl(); String url = c.getTileUrl();
String sourceName = c.getTileSource(); String sourceName = c.getTileSource();
@ -101,9 +101,9 @@ class GwtGdxMap extends GdxMap {
initDefaultMap(tileSource, false, true, true); initDefaultMap(tileSource, false, true, true);
if ("naturalearth".equals(c.getBackgroundLayer())) 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 // update URL hash to current position, every 5 seconds
Timer timer = new Timer() { Timer timer = new Timer() {
@ -111,7 +111,7 @@ class GwtGdxMap extends GdxMap {
private MapPosition pos = new MapPosition(); private MapPosition pos = new MapPosition();
public void run() { public void run() {
mMapView.getMapViewPosition().getMapPosition(pos); mMap.getViewport().getMapPosition(pos);
int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000); int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000);
int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000); int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000);
int rot = (int) (pos.angle); int rot = (int) (pos.angle);

View File

@ -8,7 +8,7 @@ import org.oscim.core.BoundingBox;
import org.oscim.core.GeometryBuffer; import org.oscim.core.GeometryBuffer;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.layers.overlay.PathOverlay; 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.cell.client.AbstractCell;
import com.google.gwt.core.client.JavaScriptObject; 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 Button searchButton = new Button("Search");
final TextBox searchField = new TextBox(); final TextBox searchField = new TextBox();
//searchField.setText("Bremen"); //searchField.setText("Bremen");
final PathOverlay mOverlay = new PathOverlay(mapView, 0xCC0000FF); final PathOverlay mOverlay = new PathOverlay(map, 0xCC0000FF);
mapView.getLayerManager().add(mOverlay); map.getLayerManager().add(mOverlay);
// We can add style names to widgets // We can add style names to widgets
searchButton.addStyleName("sendButton"); searchButton.addStyleName("sendButton");
@ -237,9 +237,9 @@ public class SearchBox {
if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 && if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 &&
b.maxLongitudeE6 - b.minLongitudeE6 < 100) b.maxLongitudeE6 - b.minLongitudeE6 < 100)
// for small bbox use zoom=16 to get an overview // 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 else
mapView.getMapViewPosition().animateTo(b); map.getViewport().animateTo(b);
if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) { if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) {
String wkt = ((NominatimData) d).getWkt(); String wkt = ((NominatimData) d).getWkt();
@ -261,7 +261,7 @@ public class SearchBox {
mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6);
} }
// hide overlay after 5 seconds // hide overlay after 5 seconds
mapView.postDelayed(new Runnable() { map.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
mOverlay.clearPath(); mOverlay.clearPath();
@ -270,13 +270,13 @@ public class SearchBox {
} else { } else {
MapPosition pos = new MapPosition(); MapPosition pos = new MapPosition();
mapView.getMapViewPosition().setTilt(0); map.getViewport().setTilt(0);
mapView.getMapViewPosition().setRotation(0); map.getViewport().setRotation(0);
pos.setZoomLevel(13); pos.setZoomLevel(13);
pos.setPosition(d.getLatitude(), d.getLongitude()); pos.setPosition(d.getLatitude(), d.getLongitude());
mapView.setMapPosition(pos); map.setMapPosition(pos);
mapView.updateMap(true); map.updateMap(true);
} }
scroller.setVisible(false); scroller.setVisible(false);

View File

@ -28,7 +28,7 @@ import org.oscim.layers.tile.bitmap.TileSource.FadeStep;
import org.oscim.renderer.sublayers.BitmapLayer; import org.oscim.renderer.sublayers.BitmapLayer;
import org.oscim.renderer.sublayers.Layers; import org.oscim.renderer.sublayers.Layers;
import org.oscim.utils.FastMath; 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.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler; import com.google.gwt.event.dom.client.ErrorHandler;
@ -42,8 +42,8 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
final TileSource mTileSource; final TileSource mTileSource;
private final FadeStep[] mFade; private final FadeStep[] mFade;
public BitmapTileLayer(MapView mapView, TileSource tileSource) { public BitmapTileLayer(Map map, TileSource tileSource) {
super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100);
mTileSource = tileSource; mTileSource = tileSource;
mFade = mTileSource.getFadeSteps(); mFade = mTileSource.getFadeSteps();
} }

View File

@ -13,8 +13,8 @@ import org.oscim.renderer.GLState;
import org.oscim.renderer.layers.GridRenderLayer; import org.oscim.renderer.layers.GridRenderLayer;
import org.oscim.theme.InternalRenderTheme; import org.oscim.theme.InternalRenderTheme;
import org.oscim.tilesource.TileSource; import org.oscim.tilesource.TileSource;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
import com.badlogic.gdx.Application; import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.ApplicationListener;
@ -31,7 +31,7 @@ import com.badlogic.gdx.utils.Timer.Task;
public class GdxMap implements ApplicationListener { public class GdxMap implements ApplicationListener {
protected final MapView mMapView; protected final Map mMap;
private final GLRenderer mMapRenderer; private final GLRenderer mMapRenderer;
boolean mRenderRequest; boolean mRenderRequest;
@ -39,7 +39,7 @@ public class GdxMap implements ApplicationListener {
public GdxMap() { public GdxMap() {
AssetAdapter.g = new GdxAssetAdapter(); AssetAdapter.g = new GdxAssetAdapter();
mMapView = new MapView() { mMap = new Map() {
@Override @Override
public int getWidth() { public int getWidth() {
return mWidth; 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) { boolean buildings) {
if (tileSource != null) { if (tileSource != null) {
mMapLayer = mMapView.setBaseMap(tileSource); mMapLayer = mMap.setBaseMap(tileSource);
mMapView.setTheme(InternalRenderTheme.DEFAULT); mMap.setTheme(InternalRenderTheme.DEFAULT);
if (buildings) if (buildings)
mMapView.getLayerManager().add( mMap.getLayerManager().add(
new BuildingOverlay(mMapView, mMapLayer.getTileLayer())); new BuildingOverlay(mMap, mMapLayer.getTileLayer()));
if (labels) if (labels)
mMapView.getLayerManager().add(new LabelLayer(mMapView, mMap.getLayerManager().add(new LabelLayer(mMap,
mMapLayer.getTileLayer())); mMapLayer.getTileLayer()));
} }
if (tileGrid) if (tileGrid)
mMapView.getLayerManager().add(new GenericOverlay(mMapView, mMap.getLayerManager().add(new GenericOverlay(mMap,
new GridRenderLayer())); new GridRenderLayer()));
} }
@ -132,12 +132,12 @@ public class GdxMap implements ApplicationListener {
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
mMapView.getMapViewPosition().setViewport(w, h); mMap.getViewport().setViewport(w, h);
MapPosition p = new MapPosition(); MapPosition p = new MapPosition();
p.setZoomLevel(14); p.setZoomLevel(14);
p.setPosition(53.08, 8.83); p.setPosition(53.08, 8.83);
//p.setPosition(0.0, 0.0); //p.setPosition(0.0, 0.0);
mMapView.setMapPosition(p); mMap.setMapPosition(p);
mMapRenderer.onSurfaceCreated(); mMapRenderer.onSurfaceCreated();
mMapRenderer.onSurfaceChanged(w, h); mMapRenderer.onSurfaceChanged(w, h);
@ -183,9 +183,9 @@ public class GdxMap implements ApplicationListener {
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
mMapView.getMapViewPosition().setViewport(w, h); mMap.getViewport().setViewport(w, h);
mMapRenderer.onSurfaceChanged(w, h); mMapRenderer.onSurfaceChanged(w, h);
mMapView.render(); mMap.render();
} }
@Override @Override
@ -206,7 +206,7 @@ public class GdxMap implements ApplicationListener {
GLState.blend(false); GLState.blend(false);
GLState.test(false, false); GLState.test(false, false);
mMapView.updateLayers(); mMap.updateLayers();
mRenderRequest = true; mRenderRequest = true;
Gdx.graphics.requestRendering(); Gdx.graphics.requestRendering();
@ -223,10 +223,10 @@ public class GdxMap implements ApplicationListener {
class TouchHandler implements InputProcessor { class TouchHandler implements InputProcessor {
private MapViewPosition mMapPosition; private Viewport mMapPosition;
public TouchHandler() { public TouchHandler() {
mMapPosition = mMapView.getMapViewPosition(); mMapPosition = mMap.getViewport();
} }
private boolean mActiveScale; private boolean mActiveScale;
@ -241,54 +241,54 @@ public class GdxMap implements ApplicationListener {
case Input.Keys.UP: case Input.Keys.UP:
mMapPosition.moveMap(0, -50); mMapPosition.moveMap(0, -50);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.DOWN: case Input.Keys.DOWN:
mMapPosition.moveMap(0, 50); mMapPosition.moveMap(0, 50);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.LEFT: case Input.Keys.LEFT:
mMapPosition.moveMap(-50, 0); mMapPosition.moveMap(-50, 0);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.RIGHT: case Input.Keys.RIGHT:
mMapPosition.moveMap(50, 0); mMapPosition.moveMap(50, 0);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.M: case Input.Keys.M:
mMapPosition.scaleMap(1.05f, 0, 0); mMapPosition.scaleMap(1.05f, 0, 0);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.N: case Input.Keys.N:
mMapPosition.scaleMap(0.95f, 0, 0); mMapPosition.scaleMap(0.95f, 0, 0);
mMapView.updateMap(true); mMap.updateMap(true);
break; break;
case Input.Keys.D: case Input.Keys.D:
mMapView.setTheme(InternalRenderTheme.DEFAULT); mMap.setTheme(InternalRenderTheme.DEFAULT);
mMapView.updateMap(false); mMap.updateMap(false);
break; break;
case Input.Keys.T: case Input.Keys.T:
mMapView.setTheme(InternalRenderTheme.TRONRENDER); mMap.setTheme(InternalRenderTheme.TRONRENDER);
mMapView.updateMap(false); mMap.updateMap(false);
break; break;
case Input.Keys.G: case Input.Keys.G:
if (mGridLayer == null) { if (mGridLayer == null) {
mGridLayer = new GenericOverlay(mMapView, new GridRenderLayer()); mGridLayer = new GenericOverlay(mMap, new GridRenderLayer());
mGridLayer.setEnabled(true); mGridLayer.setEnabled(true);
mMapView.getLayerManager().add(mGridLayer); mMap.getLayerManager().add(mGridLayer);
} else { } else {
if (mGridLayer.isEnabled()) { if (mGridLayer.isEnabled()) {
mGridLayer.setEnabled(false); mGridLayer.setEnabled(false);
mMapView.getLayerManager().remove(mGridLayer); mMap.getLayerManager().remove(mGridLayer);
} else { } else {
mGridLayer.setEnabled(true); mGridLayer.setEnabled(true);
mMapView.getLayerManager().add(mGridLayer); mMap.getLayerManager().add(mGridLayer);
} }
} }
mMapView.render(); mMap.render();
break; break;
} }
return false; return false;
@ -348,7 +348,7 @@ public class GdxMap implements ApplicationListener {
} }
if (changed) { if (changed) {
mMapView.updateMap(true); mMap.updateMap(true);
} }
return true; return true;
} }
@ -367,12 +367,12 @@ public class GdxMap implements ApplicationListener {
mMapPosition.animateZoom(150, 0.8f, 0, 0); mMapPosition.animateZoom(150, 0.8f, 0, 0);
} else { } else {
float fx = mPosX - mMapView.getWidth() / 2; float fx = mPosX - mMap.getWidth() / 2;
float fy = mPosY - mMapView.getHeight() / 2; float fy = mPosY - mMap.getHeight() / 2;
mMapPosition.animateZoom(150, 1.25f, fx, fy); mMapPosition.animateZoom(150, 1.25f, fx, fy);
} }
mMapView.updateMap(false); mMap.updateMap(false);
return true; return true;
} }
@ -408,10 +408,10 @@ public class GdxMap implements ApplicationListener {
protected static final double PINCH_ROTATE_THRESHOLD = 0.02; protected static final double PINCH_ROTATE_THRESHOLD = 0.02;
protected static final float PINCH_TILT_THRESHOLD = 1f; protected static final float PINCH_TILT_THRESHOLD = 1f;
private MapViewPosition mMapPosition; private Viewport mMapPosition;
public ViewController() { public ViewController() {
mMapPosition = mMapView.getMapViewPosition(); mMapPosition = mMap.getViewport();
} }
@Override @Override
@ -450,7 +450,7 @@ public class GdxMap implements ApplicationListener {
return true; return true;
mMapPosition.moveMap(deltaX, deltaY); mMapPosition.moveMap(deltaX, deltaY);
mMapView.updateMap(true); mMap.updateMap(true);
return false; return false;
} }
@ -583,7 +583,7 @@ public class GdxMap implements ApplicationListener {
} }
if (changed) { if (changed) {
mMapView.updateMap(true); mMap.updateMap(true);
mPrevPinchWidth = pinchWidth; mPrevPinchWidth = pinchWidth;
mPrevY2 = y2; mPrevY2 = y2;

View File

@ -12,8 +12,29 @@
* You should have received a copy of the GNU Lesser General Public License along with * You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
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);
}
} }

View File

@ -17,12 +17,12 @@ package org.oscim.layers;
import org.oscim.backend.input.KeyEvent; import org.oscim.backend.input.KeyEvent;
import org.oscim.backend.input.MotionEvent; import org.oscim.backend.input.MotionEvent;
import org.oscim.view.MapView; import org.oscim.view.Map;
public abstract class InputLayer extends Layer { public abstract class InputLayer extends Layer {
public InputLayer(MapView mapView) { public InputLayer(Map map) {
super(mapView); super(map);
} }
@ -30,7 +30,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param keyCode * @param keyCode
* ... * ...
@ -46,7 +46,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param keyCode * @param keyCode
* ... * ...
@ -63,7 +63,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param event * @param event
* ... * ...
@ -77,7 +77,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -93,7 +93,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -107,7 +107,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -121,7 +121,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -137,7 +137,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -172,7 +172,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...
@ -186,7 +186,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param pEvent1 * @param pEvent1
* ... * ...
@ -215,7 +215,7 @@ public abstract class InputLayer extends Layer {
* By default does nothing (<code>return false</code>). If you handled the * By default does nothing (<code>return false</code>). If you handled the
* Event, return <code>true</code>, otherwise return <code>false</code>. If * Event, return <code>true</code>, otherwise return <code>false</code>. If
* you returned <code>true</code> none of the following Overlays or the * you returned <code>true</code> none of the following Overlays or the
* underlying {@link MapView} has the chance to handle this event. * underlying {@link Map} has the chance to handle this event.
* *
* @param e * @param e
* ... * ...

View File

@ -14,17 +14,17 @@
*/ */
package org.oscim.layers; package org.oscim.layers;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.renderer.RenderLayer; import org.oscim.renderer.RenderLayer;
public abstract class Layer { public abstract class Layer {
public Layer(MapView mapView) { public Layer(Map map) {
mMapView = mapView; mMap = map;
} }
private boolean mEnabled = true; private boolean mEnabled = true;
protected final MapView mMapView; protected final Map mMap;
/** RenderLayer used to draw this layer. To be implemented by sub-classes */ /** RenderLayer used to draw this layer. To be implemented by sub-classes */
protected RenderLayer mLayer; protected RenderLayer mLayer;

View File

@ -18,11 +18,11 @@ import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.Log; import org.oscim.backend.Log;
import org.oscim.backend.input.MotionEvent; import org.oscim.backend.input.MotionEvent;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; 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: * @TODO:
* - better recognition of tilt/rotate/scale state * - 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 double PINCH_ROTATE_THRESHOLD = 0.02;
protected static final float PINCH_TILT_THRESHOLD = 1f; protected static final float PINCH_TILT_THRESHOLD = 1f;
private final MapViewPosition mMapPosition; private final Viewport mMapPosition;
private final VelocityTracker mTracker; private final VelocityTracker mTracker;
public MapEventLayer(MapView mapView) { public MapEventLayer(Map map) {
super(mapView); super(map);
mMapPosition = mapView.getMapViewPosition(); mMapPosition = map.getViewport();
mTracker = new VelocityTracker(); mTracker = new VelocityTracker();
} }
private long mPrevTime; 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 @Override
public boolean onTouchEvent(MotionEvent e) { public boolean onTouchEvent(MotionEvent e) {
@ -121,8 +146,8 @@ public class MapEventLayer extends InputLayer {
float mx = x1 - mPrevX; float mx = x1 - mPrevX;
float my = y1 - mPrevY; float my = y1 - mPrevY;
float width = mMapView.getWidth(); float width = mMap.getWidth();
float height = mMapView.getHeight(); float height = mMap.getHeight();
mTracker.update(x1, y1, e.getTime()); mTracker.update(x1, y1, e.getTime());
@ -135,7 +160,7 @@ public class MapEventLayer extends InputLayer {
if (debug) if (debug)
Log.d(TAG, "tap scale: " + mx + " " + my); Log.d(TAG, "tap scale: " + mx + " " + my);
mMapPosition.scaleMap(1 - my / (height / 8), 0, 0); mMapPosition.scaleMap(1 - my / (height / 8), 0, 0);
mMapView.updateMap(true); mMap.updateMap(true);
mPrevX = x1; mPrevX = x1;
mPrevY = y1; mPrevY = y1;
@ -146,7 +171,7 @@ public class MapEventLayer extends InputLayer {
if (mx > 1 || mx < -1 || my > 1 || my < -1) { if (mx > 1 || mx < -1 || my > 1 || my < -1) {
mMapPosition.moveMap(mx, my); mMapPosition.moveMap(mx, my);
mMapView.updateMap(true); mMap.updateMap(true);
mPrevX = x1; mPrevX = x1;
mPrevY = y1; mPrevY = y1;
@ -233,7 +258,7 @@ public class MapEventLayer extends InputLayer {
} }
if (changed) { if (changed) {
mMapView.updateMap(true); mMap.updateMap(true);
mPrevPinchWidth = pinchWidth; mPrevPinchWidth = pinchWidth;
mPrevX2 = x2; mPrevX2 = x2;
@ -274,7 +299,7 @@ public class MapEventLayer extends InputLayer {
printState("onDoubleTap"); printState("onDoubleTap");
// avoid onLongPress // avoid onLongPress
mMapView.getLayerManager().cancelGesture(); mMap.getLayerManager().cancelGesture();
return true; return true;
} }
@ -285,7 +310,7 @@ public class MapEventLayer extends InputLayer {
if (e2.getPointerCount() == 1) { if (e2.getPointerCount() == 1) {
mMapPosition.moveMap(-distanceX, -distanceY); mMapPosition.moveMap(-distanceX, -distanceY);
mMapView.updateMap(true); mMap.updateMap(true);
return true; return true;
} }
@ -300,7 +325,7 @@ public class MapEventLayer extends InputLayer {
int w = Tile.SIZE * 3; int w = Tile.SIZE * 3;
int h = Tile.SIZE * 3; int h = Tile.SIZE * 3;
//if (mMapView.enablePagedFling) { //if (mMap.enablePagedFling) {
// double a = Math.sqrt(velocityX * velocityX + velocityY * velocityY); // double a = Math.sqrt(velocityX * velocityX + velocityY * velocityY);
// //
// float vx = (float) (velocityX / a); // float vx = (float) (velocityX / a);
@ -309,7 +334,7 @@ public class MapEventLayer extends InputLayer {
// if (a < 400) // if (a < 400)
// return true; // 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); // mMapPosition.animateTo(vx * move, vy * move, 250);
//} else { //} else {
float s = 1; //(200 / CanvasAdapter.dpi); float s = 1; //(200 / CanvasAdapter.dpi);

View File

@ -18,7 +18,7 @@ import org.oscim.backend.input.MotionEvent;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.layers.InputLayer; import org.oscim.layers.InputLayer;
import org.oscim.layers.tile.TileRenderLayer; import org.oscim.layers.tile.TileRenderLayer;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.backend.Log; import org.oscim.backend.Log;
@ -26,11 +26,11 @@ public class LabelLayer extends InputLayer {
private final static String TAG = LabelLayer.class.getName(); private final static String TAG = LabelLayer.class.getName();
final TextRenderLayer mTextLayer; final TextRenderLayer mTextLayer;
public LabelLayer(MapView mapView, TileRenderLayer tileRenderLayer) { public LabelLayer(Map map, TileRenderLayer tileRenderLayer) {
super(mapView); super(map);
//mTextLayer = new org.oscim.renderer.layers.TextRenderLayer(mapView, tileRenderLayer); //mTextLayer = new org.oscim.renderer.layers.TextRenderLayer(map, tileRenderLayer);
mTextLayer = new TextRenderLayer(mapView, tileRenderLayer); mTextLayer = new TextRenderLayer(map, tileRenderLayer);
mLayer = mTextLayer; mLayer = mTextLayer;
} }

View File

@ -50,8 +50,8 @@ import org.oscim.utils.FastMath;
import org.oscim.utils.OBB2D; import org.oscim.utils.OBB2D;
import org.oscim.utils.pool.LList; import org.oscim.utils.pool.LList;
import org.oscim.utils.pool.Pool; import org.oscim.utils.pool.Pool;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
class TextRenderLayer extends BasicRenderLayer { class TextRenderLayer extends BasicRenderLayer {
private final static String TAG = TextRenderLayer.class.getName(); 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 static long MAX_RELABEL_DELAY = 200;
private final MapViewPosition mMapViewPosition; private final Viewport mViewport;
private final TileSet mTileSet; private final TileSet mTileSet;
class TextureLayers { class TextureLayers {
@ -131,11 +131,11 @@ class TextRenderLayer extends BasicRenderLayer {
private float mSquareRadius; private float mSquareRadius;
private int mRelabelCnt; private int mRelabelCnt;
private final TileRenderLayer mTileLayer; private final TileRenderLayer mTileLayer;
private final MapView mMapView; private final Map mMap;
public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) { public TextRenderLayer(Map map, TileRenderLayer baseLayer) {
mMapView = mapView; mMap = map;
mMapViewPosition = mapView.getMapViewPosition(); mViewport = map.getViewport();
mTileLayer = baseLayer; mTileLayer = baseLayer;
mTileSet = new TileSet(); mTileSet = new TileSet();
@ -294,9 +294,9 @@ class TextRenderLayer extends BasicRenderLayer {
MapPosition pos = mNextLayer.pos; MapPosition pos = mNextLayer.pos;
synchronized (mMapViewPosition) { synchronized (mViewport) {
changedPos = mMapViewPosition.getMapPosition(pos); changedPos = mViewport.getMapPosition(pos);
//mMapViewPosition.getMapViewProjection(coords); //mViewport.getMapViewProjection(coords);
} }
if (!changedTiles && !changedPos) { if (!changedTiles && !changedPos) {
@ -305,11 +305,11 @@ class TextRenderLayer extends BasicRenderLayer {
} }
Layers dbg = null; Layers dbg = null;
if (mMapView.getDebugSettings().debugLabels) if (mMap.getDebugSettings().debugLabels)
dbg = new Layers(); dbg = new Layers();
int mw = (mMapView.getWidth() + Tile.SIZE) / 2; int mw = (mMap.getWidth() + Tile.SIZE) / 2;
int mh = (mMapView.getHeight() + Tile.SIZE) / 2; int mh = (mMap.getHeight() + Tile.SIZE) / 2;
mSquareRadius = mw * mw + mh * mh; mSquareRadius = mw * mw + mh * mh;
MapTile[] tiles = mTileSet.tiles; MapTile[] tiles = mTileSet.tiles;
@ -650,7 +650,7 @@ class TextRenderLayer extends BasicRenderLayer {
labelsChanged = updateLabels(); labelsChanged = updateLabels();
if (!isCancelled && labelsChanged) if (!isCancelled && labelsChanged)
mMapView.render(); mMap.render();
mLabelTask = null; mLabelTask = null;
mRequestRun = false; mRequestRun = false;
@ -674,7 +674,7 @@ class TextRenderLayer extends BasicRenderLayer {
public void run() { public void run() {
if (mLabelTask == null) { if (mLabelTask == null) {
mLabelTask = new LabelTask(); mLabelTask = new LabelTask();
mMapView.addTask(mLabelTask); mMap.addTask(mLabelTask);
} }
} }
}; };
@ -687,7 +687,7 @@ class TextRenderLayer extends BasicRenderLayer {
mRequestRun = true; mRequestRun = true;
long delay = (mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis(); long delay = (mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis();
//Log.d(TAG, "relabel in: " + delay); //Log.d(TAG, "relabel in: " + delay);
mMapView.postDelayed(mLabelUpdate, Math.max(delay, 0)); mMap.postDelayed(mLabelUpdate, Math.max(delay, 0));
} }
} }
} }

View File

@ -19,7 +19,7 @@ import org.oscim.core.MapPosition;
import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layers.ExtrusionRenderLayer; import org.oscim.renderer.layers.ExtrusionRenderLayer;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.view.MapView; import org.oscim.view.Map;
/** /**
* @author Hannes Janetzek * @author Hannes Janetzek
@ -29,8 +29,8 @@ public class BuildingOverlay extends Overlay {
final ExtrusionRenderLayer mExtLayer; final ExtrusionRenderLayer mExtLayer;
public BuildingOverlay(MapView mapView, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { public BuildingOverlay(Map map, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) {
super(mapView); super(map);
mExtLayer = new ExtrusionRenderLayer(tileRenderLayer) { mExtLayer = new ExtrusionRenderLayer(tileRenderLayer) {
private long mStartTime; private long mStartTime;
@ -48,7 +48,7 @@ public class BuildingOverlay extends Overlay {
} }
float a = (now - mStartTime) / mFadeTime; float a = (now - mStartTime) / mFadeTime;
mAlpha = FastMath.clamp(a, 0, 1); mAlpha = FastMath.clamp(a, 0, 1);
mMapView.render(); mMap.render();
} else } else
mStartTime = 0; mStartTime = 0;
} else { } else {
@ -62,7 +62,7 @@ public class BuildingOverlay extends Overlay {
float a = 1 - diff / mFadeTime; float a = 1 - diff / mFadeTime;
mAlpha = FastMath.clamp(a, 0, 1); mAlpha = FastMath.clamp(a, 0, 1);
} }
mMapView.render(); mMap.render();
} else } else
mStartTime = 0; mStartTime = 0;
} }

View File

@ -14,18 +14,18 @@
*/ */
package org.oscim.layers.overlay; package org.oscim.layers.overlay;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.renderer.RenderLayer; import org.oscim.renderer.RenderLayer;
public class GenericOverlay extends Overlay { public class GenericOverlay extends Overlay {
/** /**
* @param mapView * @param map
* ... * ...
* @param renderer * @param renderer
* ... * ...
*/ */
public GenericOverlay(MapView mapView, RenderLayer renderer) { public GenericOverlay(Map map, RenderLayer renderer) {
super(mapView); super(map);
mLayer = renderer; mLayer = renderer;
} }
} }

View File

@ -19,9 +19,10 @@ import java.util.List;
import org.oscim.backend.input.MotionEvent; import org.oscim.backend.input.MotionEvent;
import org.oscim.core.BoundingBox; import org.oscim.core.BoundingBox;
import org.oscim.core.PointD;
import org.oscim.core.PointF; import org.oscim.core.PointF;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverlay<Item> { public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverlay<Item> {
//private static final String TAG = ItemizedIconOverlay.class.getName(); //private static final String TAG = ItemizedIconOverlay.class.getName();
@ -30,30 +31,30 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
protected OnItemGestureListener<Item> mOnItemGestureListener; protected OnItemGestureListener<Item> mOnItemGestureListener;
private int mDrawnItemsLimit = Integer.MAX_VALUE; private int mDrawnItemsLimit = Integer.MAX_VALUE;
private final PointF mTmpPoint = new PointF(); private final PointD mTmpPoint = new PointD();
public ItemizedIconOverlay( public ItemizedIconOverlay(
final MapView mapView, final Map map,
final List<Item> pList, final List<Item> pList,
final OverlayMarker pDefaultMarker, final OverlayMarker pDefaultMarker,
final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) { final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) {
super(mapView, pDefaultMarker); super(map, pDefaultMarker);
this.mItemList = pList; this.mItemList = pList;
this.mOnItemGestureListener = pOnItemGestureListener; this.mOnItemGestureListener = pOnItemGestureListener;
populate(); populate();
} }
// public ItemizedIconOverlay( // public ItemizedIconOverlay(
// final MapView mapView, // final MapView map,
// final Context pContext, // final Context pContext,
// final List<Item> pList, // final List<Item> pList,
// final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) { // final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) {
// this(mapView, pList, // this(map, pList,
// null, //pContext.getResources().getDrawable(R.drawable.marker_default), // null, //pContext.getResources().getDrawable(R.drawable.marker_default),
// pOnItemGestureListener); // pOnItemGestureListener);
// } // }
@Override @Override
public boolean onSnapToItem(final int pX, final int pY, final PointF pSnapPoint) { public boolean onSnapToItem(final int pX, final int pY, final PointF pSnapPoint) {
@ -136,6 +137,7 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
return onSingleTapUpHelper(index, that.mItemList.get(index)); return onSingleTapUpHelper(index, that.mItemList.get(index));
} }
}; };
@Override @Override
public boolean onLongPress(final MotionEvent event) { public boolean onLongPress(final MotionEvent event) {
return activateSelectedItems(event, mActiveItemLongPress) || super.onLongPress(event); return activateSelectedItems(event, mActiveItemLongPress) || super.onLongPress(event);
@ -172,11 +174,11 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
if (size == 0) if (size == 0)
return false; return false;
int eventX = (int) event.getX() - mMapView.getWidth() / 2; int eventX = (int) event.getX() - mMap.getWidth() / 2;
int eventY = (int) event.getY() - mMapView.getHeight() / 2; int eventY = (int) event.getY() - mMap.getHeight() / 2;
MapViewPosition mapViewPosition = mMapView.getMapViewPosition(); Viewport mapPosition = mMap.getViewport();
BoundingBox bbox = mapViewPosition.getViewBox(); BoundingBox bbox = mapPosition.getViewBox();
int nearest = -1; int nearest = -1;
double dist = Double.MAX_VALUE; double dist = Double.MAX_VALUE;
@ -188,10 +190,10 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
continue; continue;
// TODO use intermediate projection // TODO use intermediate projection
mapViewPosition.project(item.getPoint(), mTmpPoint); mapPosition.project(item.getPoint(), mTmpPoint);
float dx = mTmpPoint.x - eventX; float dx = (float) (mTmpPoint.x - eventX);
float dy = mTmpPoint.y - eventY; float dy = (float) (mTmpPoint.y - eventY);
double d = dx * dx + dy * dy; double d = dx * dx + dy * dy;
// squared dist: 50*50 pixel // squared dist: 50*50 pixel

View File

@ -30,7 +30,7 @@ import org.oscim.renderer.layers.BasicRenderLayer;
import org.oscim.renderer.sublayers.SymbolItem; import org.oscim.renderer.sublayers.SymbolItem;
import org.oscim.renderer.sublayers.SymbolLayer; import org.oscim.renderer.sublayers.SymbolLayer;
import org.oscim.utils.GeometryUtils; import org.oscim.utils.GeometryUtils;
import org.oscim.view.MapView; import org.oscim.view.Map;
/* @author Marc Kurtz /* @author Marc Kurtz
* @author Nicolas Gramlich * @author Nicolas Gramlich
@ -98,7 +98,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
int changedVisible = 0; int changedVisible = 0;
int numVisible = 0; int numVisible = 0;
mMapView.getMapViewPosition().getMapViewProjection(mBox); mMap.getViewport().getMapViewProjection(mBox);
synchronized (lock) { synchronized (lock) {
if (mItems == null) { if (mItems == null) {
@ -209,11 +209,11 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
*/ */
public abstract int size(); public abstract int size();
public ItemizedOverlay(MapView mapView, OverlayMarker defaultMarker) { public ItemizedOverlay(Map map, OverlayMarker defaultMarker) {
super(mapView); super(map);
// if (defaultMarker == null) { // if (defaultMarker == null) {
// defaultMarker = AndroidGraphics.makeMarker(mapView.getContext().getResources() // defaultMarker = AndroidGraphics.makeMarker(map.getContext().getResources()
// .getDrawable(R.drawable.marker_default), null); // .getDrawable(R.drawable.marker_default), null);
// //throw new IllegalArgumentException("You must pass a default marker to ItemizedOverlay."); // //throw new IllegalArgumentException("You must pass a default marker to ItemizedOverlay.");
// } // }

View File

@ -16,14 +16,14 @@
package org.oscim.layers.overlay; package org.oscim.layers.overlay;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.core.PointF; import org.oscim.core.PointF;
import org.oscim.layers.InputLayer; import org.oscim.layers.InputLayer;
/** /**
* Base class representing an overlay which may be displayed on top of a * 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, * {@link Map}. To add an overlay, subclass this class, create an instance,
* and add via addOverlay() of {@link MapView}. * and add via addOverlay() of {@link Map}.
* This class implements a form of Gesture Handling similar to * This class implements a form of Gesture Handling similar to
* {@link android.view.GestureDetector.SimpleOnGestureListener} and * {@link android.view.GestureDetector.SimpleOnGestureListener} and
* GestureDetector.OnGestureListener. * GestureDetector.OnGestureListener.
@ -32,8 +32,8 @@ import org.oscim.layers.InputLayer;
*/ */
public abstract class Overlay extends InputLayer { public abstract class Overlay extends InputLayer {
public Overlay(MapView mapView) { public Overlay(Map map) {
super(mapView); super(map);
} }
/** /**

View File

@ -32,7 +32,7 @@ import org.oscim.renderer.sublayers.LineLayer;
import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Line;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.LineClipper; import org.oscim.utils.LineClipper;
import org.oscim.view.MapView; import org.oscim.view.Map;
/** This class draws a path line in given color. */ /** This class draws a path line in given color. */
public class PathOverlay extends Layer { public class PathOverlay extends Layer {
@ -234,8 +234,8 @@ public class PathOverlay extends Layer {
} }
} }
public PathOverlay(MapView mapView, int lineColor, float lineWidth) { public PathOverlay(Map map, int lineColor, float lineWidth) {
super(mapView); super(map);
mLineStyle = new Line(lineColor, lineWidth, Cap.BUTT); mLineStyle = new Line(lineColor, lineWidth, Cap.BUTT);
@ -244,8 +244,8 @@ public class PathOverlay extends Layer {
mLayer = new RenderPath(); mLayer = new RenderPath();
} }
public PathOverlay(MapView mapView, int lineColor) { public PathOverlay(Map map, int lineColor) {
this(mapView, lineColor, 2); this(map, lineColor, 2);
} }
/** /**

View File

@ -18,7 +18,7 @@ import java.util.ArrayList;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.layers.Layer; import org.oscim.layers.Layer;
import org.oscim.view.MapView; import org.oscim.view.Map;
public abstract class TileLayer<T extends TileLoader> extends Layer { public abstract class TileLayer<T extends TileLoader> extends Layer {
//private final static String TAG = TileLayer.class.getName(); //private final static String TAG = TileLayer.class.getName();
@ -34,16 +34,16 @@ public abstract class TileLayer<T extends TileLoader> extends Layer {
protected boolean mInitial = true; protected boolean mInitial = true;
public TileLayer(MapView mapView) { public TileLayer(Map map) {
this(mapView, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT); this(map, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT);
} }
public TileLayer(MapView mapView, int minZoom, int maxZoom, int cacheLimit) { public TileLayer(Map map, int minZoom, int maxZoom, int cacheLimit) {
super(mapView); super(map);
// TileManager responsible for adding visible tiles // TileManager responsible for adding visible tiles
// to load queue and managing in-memory tile cache. // 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 // Instantiate TileLoader threads
mTileLoader = new ArrayList<T>(); mTileLoader = new ArrayList<T>();

View File

@ -30,8 +30,8 @@ import org.oscim.utils.FastMath;
import org.oscim.utils.ScanBox; import org.oscim.utils.ScanBox;
import org.oscim.utils.quadtree.QuadTree; import org.oscim.utils.quadtree.QuadTree;
import org.oscim.utils.quadtree.QuadTreeIndex; import org.oscim.utils.quadtree.QuadTreeIndex;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
/** /**
* @TODO - prefetching to cache file - this class should probably not be in * @TODO - prefetching to cache file - this class should probably not be in
@ -50,8 +50,8 @@ public class TileManager {
// cache limit threshold // cache limit threshold
private static final int CACHE_THRESHOLD = 30; private static final int CACHE_THRESHOLD = 30;
private final MapView mMapView; private final Map mMap;
private final MapViewPosition mMapViewPosition; private final Viewport mViewport;
// cache for all tiles // cache for all tiles
private MapTile[] mTiles; private MapTile[] mTiles;
@ -112,14 +112,14 @@ public class TileManager {
private final float[] mMapPlane = new float[8]; private final float[] mMapPlane = new float[8];
private final TileLayer<?> mTileLayer; private final TileLayer<?> mTileLayer;
public TileManager(MapView mapView, TileLayer<?> tileLayer, int minZoom, int maxZoom, int cacheLimit) { public TileManager(Map map, TileLayer<?> tileLayer, int minZoom, int maxZoom, int cacheLimit) {
mMapView = mapView; mMap = map;
mTileLayer = tileLayer; mTileLayer = tileLayer;
mMaxZoom = maxZoom; mMaxZoom = maxZoom;
mMinZoom = minZoom; mMinZoom = minZoom;
mCacheLimit = cacheLimit; mCacheLimit = cacheLimit;
mMapViewPosition = mapView.getMapViewPosition(); mViewport = map.getViewport();
jobQueue = new JobQueue(); jobQueue = new JobQueue();
mJobs = new ArrayList<MapTile>(); mJobs = new ArrayList<MapTile>();
@ -168,7 +168,7 @@ public class TileManager {
mTilesCount = 0; mTilesCount = 0;
// set up TileSet large enough to hold current tiles // 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 size = Tile.SIZE >> 1;
int numTiles = (num * num) / (size * size) * 4; int numTiles = (num * num) / (size * size) * 4;
@ -212,7 +212,7 @@ public class TileManager {
tileZoom = match; tileZoom = match;
} }
mMapViewPosition.getMapViewProjection(mMapPlane); mViewport.getMapViewProjection(mMapPlane);
// scan visible tiles. callback function calls 'addTile' // scan visible tiles. callback function calls 'addTile'
// which updates mNewTiles // which updates mNewTiles
@ -260,7 +260,7 @@ public class TileManager {
} }
//Log.d(TAG, newCnt + " << " + Arrays.deepToString(mCurrentTiles.tiles)); //Log.d(TAG, newCnt + " << " + Arrays.deepToString(mCurrentTiles.tiles));
// request rendering as tiles changed // request rendering as tiles changed
mMapView.render(); mMap.render();
} }
/* Add tile jobs to queue */ /* Add tile jobs to queue */
@ -590,7 +590,7 @@ public class TileManager {
// locked means the tile is visible or referenced by // locked means the tile is visible or referenced by
// a tile that might be visible. // a tile that might be visible.
if (tile.isLocked()) if (tile.isLocked())
mMapView.render(); mMap.render();
return true; return true;
} }

View File

@ -32,7 +32,7 @@ import org.oscim.layers.tile.bitmap.TileSource.FadeStep;
import org.oscim.renderer.sublayers.BitmapLayer; import org.oscim.renderer.sublayers.BitmapLayer;
import org.oscim.renderer.sublayers.Layers; import org.oscim.renderer.sublayers.Layers;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.view.MapView; import org.oscim.view.Map;
public class BitmapTileLayer extends TileLayer<TileLoader> { public class BitmapTileLayer extends TileLayer<TileLoader> {
@ -43,8 +43,8 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
final TileSource mTileSource; final TileSource mTileSource;
private final FadeStep[] mFade; private final FadeStep[] mFade;
public BitmapTileLayer(MapView mapView, TileSource tileSource) { public BitmapTileLayer(Map map, TileSource tileSource) {
super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100); super(map, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100);
mTileSource = tileSource; mTileSource = tileSource;
mFade = mTileSource.getFadeSteps(); mFade = mTileSource.getFadeSteps();

View File

@ -14,7 +14,7 @@
*/ */
package org.oscim.layers.tile.geojson; 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.MapTile;
import org.oscim.layers.tile.TileLayer; import org.oscim.layers.tile.TileLayer;
import org.oscim.layers.tile.TileLoader; import org.oscim.layers.tile.TileLoader;
@ -22,8 +22,8 @@ import org.oscim.layers.tile.TileManager;
public class GeoJsonTileLayer extends TileLayer<TileLoader> { public class GeoJsonTileLayer extends TileLayer<TileLoader> {
public GeoJsonTileLayer(MapView mapView) { public GeoJsonTileLayer(Map map) {
super(mapView); super(map);
} }
@Override @Override

View File

@ -14,7 +14,7 @@
*/ */
package org.oscim.layers.tile.test; 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.Color;
import org.oscim.backend.canvas.Paint.Cap; import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.core.GeometryBuffer; import org.oscim.core.GeometryBuffer;
@ -33,8 +33,8 @@ import org.oscim.backend.Log;
public class TestTileLayer extends TileLayer<TestTileLoader> { public class TestTileLayer extends TileLayer<TestTileLoader> {
final static String TAG = TestTileLayer.class.getName(); final static String TAG = TestTileLayer.class.getName();
public TestTileLayer(MapView mapView) { public TestTileLayer(Map map) {
super(mapView); super(map);
} }
@Override @Override

View File

@ -25,7 +25,7 @@ import org.oscim.tilesource.ITileDataSource;
import org.oscim.tilesource.MapInfo; import org.oscim.tilesource.MapInfo;
import org.oscim.tilesource.TileSource; import org.oscim.tilesource.TileSource;
import org.oscim.tilesource.TileSource.OpenResult; 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 * The vector-tile-map layer. This class manages instances of
@ -37,8 +37,8 @@ public class MapTileLayer extends TileLayer<MapTileLoader> {
private TileSource mTileSource; private TileSource mTileSource;
public MapTileLayer(MapView mapView) { public MapTileLayer(Map map) {
super(mapView); super(map);
} }
@Override @Override
@ -78,7 +78,7 @@ public class MapTileLayer extends TileLayer<MapTileLoader> {
mTileManager.setZoomTable(mTileSource.getMapInfo().zoomLevel); mTileManager.setZoomTable(mTileSource.getMapInfo().zoomLevel);
mMapView.clearMap(); mMap.clearMap();
resumeLoaders(); resumeLoaders();

View File

@ -31,8 +31,8 @@ import org.oscim.utils.GlUtils;
import org.oscim.utils.Matrix4; import org.oscim.utils.Matrix4;
import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.Pool; import org.oscim.utils.pool.Pool;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
public class GLRenderer { public class GLRenderer {
private static final String TAG = GLRenderer.class.getName(); private static final String TAG = GLRenderer.class.getName();
@ -46,10 +46,10 @@ public class GLRenderer {
static int CACHE_TILES = CACHE_TILES_MAX; static int CACHE_TILES = CACHE_TILES_MAX;
private static MapView mMapView; private static Map mMap;
public static int screenWidth, screenHeight; public static int screenWidth, screenHeight;
private static MapViewPosition mMapViewPosition; private static Viewport mViewport;
private static MapPosition mMapPosition; private static MapPosition mMapPosition;
private static short[] mFillCoords; private static short[] mFillCoords;
@ -79,9 +79,9 @@ public class GLRenderer {
mvp.setScale(ratio, ratio, ratio); mvp.setScale(ratio, ratio, ratio);
else else
mvp.setTransScale( mvp.setTransScale(
(-screenWidth / 2) * ratio * scale, (-screenWidth / 2) * ratio * scale,
(-screenHeight / 2) * ratio * scale, (-screenHeight / 2) * ratio * scale,
ratio); ratio);
mvp.multiplyLhs(proj); mvp.multiplyLhs(proj);
} }
@ -93,6 +93,7 @@ public class GLRenderer {
static float[] mClearColor = null; static float[] mClearColor = null;
public static int mQuadIndicesID; public static int mQuadIndicesID;
private static int mQuadVerticesID;
public final static int maxQuads = 64; public final static int maxQuads = 64;
private static boolean mUpdateColor = false; private static boolean mUpdateColor = false;
@ -101,14 +102,16 @@ public class GLRenderer {
// static ReentrantLock tilelock = new ReentrantLock(); // static ReentrantLock tilelock = new ReentrantLock();
public static Object drawlock = new Object(); public static Object drawlock = new Object();
public static long frametime;
/** /**
* @param mapView * @param map
* the MapView * the MapView
*/ */
public GLRenderer(MapView mapView) { public GLRenderer(Map map) {
mMapView = mapView; mMap = map;
mMapViewPosition = mapView.getMapViewPosition(); mViewport = map.getViewport();
mMapPosition = new MapPosition(); mMapPosition = new MapPosition();
mMatrices = new Matrices(); mMatrices = new Matrices();
@ -127,7 +130,7 @@ public class GLRenderer {
mFillCoords[7] = min; mFillCoords[7] = min;
} }
public static void setBackgroundColor(int color){ public static void setBackgroundColor(int color) {
mClearColor = GlUtils.colorToFloat(color); mClearColor = GlUtils.colorToFloat(color);
mUpdateColor = true; mUpdateColor = true;
} }
@ -146,8 +149,8 @@ public class GLRenderer {
size = (1 << 15); size = (1 << 15);
ByteBuffer buf = ByteBuffer ByteBuffer buf = ByteBuffer
.allocateDirect(size) .allocateDirect(size)
.order(ByteOrder.nativeOrder()); .order(ByteOrder.nativeOrder());
this.floatBuffer = buf.asFloatBuffer(); this.floatBuffer = buf.asFloatBuffer();
this.shortBuffer = buf.asShortBuffer(); this.shortBuffer = buf.asShortBuffer();
@ -155,19 +158,20 @@ public class GLRenderer {
this.tmpBufferSize = size; this.tmpBufferSize = size;
} }
} }
static class BufferPool extends Pool<BufferItem>{
static class BufferPool extends Pool<BufferItem> {
private BufferItem mUsedBuffers; private BufferItem mUsedBuffers;
@Override @Override
protected BufferItem createItem() { protected BufferItem createItem() {
// unused; // unused;
return null; return null;
} }
public BufferItem get(int size){ public BufferItem get(int size) {
BufferItem b = pool; BufferItem b = pool;
if (b == null){ if (b == null) {
b = new BufferItem(); b = new BufferItem();
} else { } else {
pool = b.next; pool = b.next;
@ -181,12 +185,13 @@ public class GLRenderer {
return b; return b;
} }
public void releaseBuffers(){ public void releaseBuffers() {
mBufferPool.releaseAll(mUsedBuffers); mBufferPool.releaseAll(mUsedBuffers);
mUsedBuffers = null; mUsedBuffers = null;
} }
} }
// Do not use the same buffer to upload data within a frame twice // 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 // - Contrary to what the OpenGL doc says data seems *not* to be
// *always* copied after glBufferData returns... // *always* copied after glBufferData returns...
@ -194,7 +199,6 @@ public class GLRenderer {
// but not when using libgdx bindings (LWJGL or AndroidGL20) // but not when using libgdx bindings (LWJGL or AndroidGL20)
private static BufferPool mBufferPool = new BufferPool(); private static BufferPool mBufferPool = new BufferPool();
/** /**
* Only use on GL Thread! Get a native ShortBuffer for temporary use. * 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, public static boolean uploadLayers(Layers layers, int newSize,
boolean addFill) { boolean addFill) {
// add fill coordinates // add fill coordinates
if (addFill) if (addFill)
newSize += 8; newSize += 8;
@ -238,10 +242,10 @@ public class GLRenderer {
if (newSize != sbuf.remaining()) { if (newSize != sbuf.remaining()) {
Log.d(TAG, "wrong size: " Log.d(TAG, "wrong size: "
+ " new size: " + newSize + " new size: " + newSize
+ " buffer pos: " + sbuf.position() + " buffer pos: " + sbuf.position()
+ " buffer limit: " + sbuf.limit() + " buffer limit: " + sbuf.limit()
+ " buffer fill: " + sbuf.remaining()); + " buffer fill: " + sbuf.remaining());
return false; return false;
} }
newSize *= SHORT_BYTES; newSize *= SHORT_BYTES;
@ -254,7 +258,8 @@ public class GLRenderer {
// prevent main thread recreating all tiles (updateMap) // prevent main thread recreating all tiles (updateMap)
// while rendering is going on. // while rendering is going on.
synchronized(drawlock){ synchronized (drawlock) {
frametime = System.currentTimeMillis();
draw(); draw();
} }
@ -272,8 +277,8 @@ public class GLRenderer {
GL.glDepthMask(true); GL.glDepthMask(true);
GL.glStencilMask(0xFF); GL.glStencilMask(0xFF);
GL.glClear(GL20.GL_COLOR_BUFFER_BIT GL.glClear(GL20.GL_COLOR_BUFFER_BIT
| GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT
| GL20.GL_STENCIL_BUFFER_BIT); | GL20.GL_STENCIL_BUFFER_BIT);
GLState.blend(false); GLState.blend(false);
GL.glDisable(GL20.GL_BLEND); GL.glDisable(GL20.GL_BLEND);
@ -282,17 +287,17 @@ public class GLRenderer {
MapPosition pos = mMapPosition; MapPosition pos = mMapPosition;
synchronized (mMapViewPosition) { synchronized (mViewport) {
// update MapPosition // update MapPosition
mMapViewPosition.updateAnimation(); mViewport.updateAnimation();
// get current MapPosition // get current MapPosition
changed = mMapViewPosition.getMapPosition(pos); changed = mViewport.getMapPosition(pos);
if (changed) 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) { if (debugView) {
mMatrices.mvp.setScale(0.5f, 0.5f, 1); mMatrices.mvp.setScale(0.5f, 0.5f, 1);
@ -305,7 +310,7 @@ public class GLRenderer {
//GL.glBindTexture(GL20.GL_TEXTURE_2D, 0); //GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
/* update layers */ /* update layers */
RenderLayer[] layers = mMapView.getLayerManager().getRenderLayers(); RenderLayer[] layers = mMap.getLayerManager().getRenderLayers();
for (int i = 0, n = layers.length; i < n; i++) for (int i = 0, n = layers.length; i < n; i++)
layers[i].update(pos, changed, mMatrices); layers[i].update(pos, changed, mMatrices);
@ -346,7 +351,7 @@ public class GLRenderer {
screenWidth = width; screenWidth = width;
screenHeight = height; screenHeight = height;
mMapViewPosition.getMatrix(null, mMatrices.proj, null); mViewport.getMatrix(null, mMatrices.proj, null);
if (debugView) { if (debugView) {
// modify this to scale only the view, to see better which tiles // 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); GL.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
if (!mNewSurface) { if (!mNewSurface) {
mMapView.updateMap(false); mMap.updateMap(false);
return; return;
} }
mNewSurface = false; mNewSurface = false;
// upload quad indices used by Texture- and LineTexRenderer // upload quad indices used by Texture- and LineTexRenderer
int[] vboIds = GlUtils.glGenBuffers(1); int[] vboIds = GlUtils.glGenBuffers(2);
mQuadIndicesID = vboIds[0]; mQuadIndicesID = vboIds[0];
int maxIndices = maxQuads * 6; int maxIndices = maxQuads * 6;
@ -391,17 +396,30 @@ public class GLRenderer {
buf.flip(); buf.flip();
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER,
mQuadIndicesID); mQuadIndicesID);
GL.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, 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); 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) if (mClearColor != null)
mUpdateColor = true; mUpdateColor = true;
GLState.init(); GLState.init();
mMapView.updateMap(true); mMap.updateMap(true);
} }
public void onSurfaceCreated() { public void onSurfaceCreated() {
@ -422,4 +440,13 @@ public class GLRenderer {
private boolean mNewSurface; private boolean mNewSurface;
public static final boolean debugView = false; public static final boolean debugView = false;
public static int getQuadIndicesVBO() {
return mQuadIndicesID;
}
public static int getQuadVertexVBO() {
return mQuadVerticesID;
}
} }

View File

@ -25,7 +25,7 @@ import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.GLState; import org.oscim.renderer.GLState;
import org.oscim.renderer.RenderLayer; import org.oscim.renderer.RenderLayer;
import org.oscim.utils.GlUtils; 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 static final GL20 GL = GLAdapter.get();
private final MapView mMapView; private final Map mMap;
private int mProgramObject; private int mProgramObject;
private int hVertexPosition; private int hVertexPosition;
@ -54,8 +54,8 @@ public class CustomRenderLayer extends RenderLayer {
}; };
private boolean mInitialized; private boolean mInitialized;
public CustomRenderLayer(MapView mapView) { public CustomRenderLayer(Map map) {
mMapView = mapView; mMap = map;
} }
// ---------- everything below runs in GLRender Thread ---------- // ---------- everything below runs in GLRender Thread ----------
@ -113,7 +113,7 @@ public class CustomRenderLayer extends RenderLayer {
// set mvp (tmp) matrix relative to mMapPosition // set mvp (tmp) matrix relative to mMapPosition
// i.e. fixed on the map // i.e. fixed on the map
float ratio = 1f / mMapView.getWidth(); float ratio = 1f / mMap.getWidth();
m.mvp.setScale(ratio, ratio, 1); m.mvp.setScale(ratio, ratio, 1);
m.mvp.multiplyLhs(m.proj); m.mvp.multiplyLhs(m.proj);

View File

@ -49,8 +49,8 @@ import org.oscim.utils.FastMath;
import org.oscim.utils.OBB2D; import org.oscim.utils.OBB2D;
import org.oscim.utils.pool.LList; import org.oscim.utils.pool.LList;
import org.oscim.utils.pool.Pool; import org.oscim.utils.pool.Pool;
import org.oscim.view.MapView; import org.oscim.view.Map;
import org.oscim.view.MapViewPosition; import org.oscim.view.Viewport;
public class TextRenderLayer extends BasicRenderLayer { public class TextRenderLayer extends BasicRenderLayer {
@ -62,7 +62,7 @@ public class TextRenderLayer extends BasicRenderLayer {
//private final static long MAX_RELABEL_DELAY = 200; //private final static long MAX_RELABEL_DELAY = 200;
private final MapViewPosition mMapViewPosition; private final Viewport mViewport;
private final TileSet mTileSet; private final TileSet mTileSet;
private MapPosition mTmpPos; private MapPosition mTmpPos;
@ -157,11 +157,11 @@ public class TextRenderLayer extends BasicRenderLayer {
private float mSquareRadius; private float mSquareRadius;
private int mRelabelCnt; private int mRelabelCnt;
private final TileRenderLayer mTileLayer; private final TileRenderLayer mTileLayer;
private final MapView mMapView; private final Map mMap;
public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) { public TextRenderLayer(Map map, TileRenderLayer baseLayer) {
mMapView = mapView; mMap = map;
mMapViewPosition = mapView.getMapViewPosition(); mViewport = map.getViewport();
mTileLayer = baseLayer; mTileLayer = baseLayer;
mTileSet = new TileSet(); mTileSet = new TileSet();
layers.textureLayers = new TextLayer(); layers.textureLayers = new TextLayer();
@ -318,9 +318,9 @@ public class TextRenderLayer extends BasicRenderLayer {
//float[] coords = mTmpCoords; //float[] coords = mTmpCoords;
MapPosition pos = mTmpPos; MapPosition pos = mTmpPos;
synchronized (mMapViewPosition) { synchronized (mViewport) {
changedPos = mMapViewPosition.getMapPosition(pos); changedPos = mViewport.getMapPosition(pos);
//mMapViewPosition.getMapViewProjection(coords); //mViewport.getMapViewProjection(coords);
} }
if (!changedTiles && !changedPos) { if (!changedTiles && !changedPos) {
@ -329,11 +329,11 @@ public class TextRenderLayer extends BasicRenderLayer {
} }
Layers dbg = null; Layers dbg = null;
if (mMapView.getDebugSettings().debugLabels) if (mMap.getDebugSettings().debugLabels)
dbg = new Layers(); dbg = new Layers();
int mw = (mMapView.getWidth() + Tile.SIZE) / 2; int mw = (mMap.getWidth() + Tile.SIZE) / 2;
int mh = (mMapView.getHeight() + Tile.SIZE) / 2; int mh = (mMap.getHeight() + Tile.SIZE) / 2;
mSquareRadius = mw * mw + mh * mh; mSquareRadius = mw * mw + mh * mh;
MapTile[] tiles = mTileSet.tiles; MapTile[] tiles = mTileSet.tiles;
@ -680,7 +680,7 @@ public class TextRenderLayer extends BasicRenderLayer {
// labelsChanged = updateLabels(); // labelsChanged = updateLabels();
// //
// if (!isCancelled() && labelsChanged) // if (!isCancelled() && labelsChanged)
// mMapView.render(); // mMap.render();
// //
// //Log.d(TAG, "relabel " + labelsChanged); // //Log.d(TAG, "relabel " + labelsChanged);
// //

View File

@ -448,8 +448,8 @@ public class GlUtils {
// //
// public static void addOffsetM(float[] matrix, int delta) { // public static void addOffsetM(float[] matrix, int delta) {
// // from http://www.mathfor3dgameprogramming.com/code/Listing9.1.cpp // // from http://www.mathfor3dgameprogramming.com/code/Listing9.1.cpp
// // float n = MapViewPosition.VIEW_NEAR; // // float n = Viewport.VIEW_NEAR;
// // float f = MapViewPosition.VIEW_FAR; // // float f = Viewport.VIEW_FAR;
// // float pz = 1; // // float pz = 1;
// // float epsilon = -2.0f * f * n * delta / ((f + n) * pz * (pz + delta)); // // float epsilon = -2.0f * f * n * delta / ((f + n) * pz * (pz + delta));
// float epsilon = 1.0f / (1 << 11); // float epsilon = 1.0f / (1 << 11);

View File

@ -25,7 +25,7 @@ import org.oscim.core.Tile;
* bounds to the map. * bounds to the map.
* *
* use: * use:
* MapViewPosition.getMapViewProjection(box) * Viewport.getMapViewProjection(box)
* yourScanBox.scan(pos.x, pos.y, pos.scale, zoomLevel, coords); * yourScanBox.scan(pos.x, pos.y, pos.scale, zoomLevel, coords);
* *
* where zoomLevel is the zoom-level for which tile coordinates * where zoomLevel is the zoom-level for which tile coordinates

View File

@ -428,14 +428,14 @@ public class LayerManager extends AbstractList<Layer> {
// //
// public boolean onCreateOptionsMenu(final Menu pMenu, final int // public boolean onCreateOptionsMenu(final Menu pMenu, final int
// menuIdOffset, // menuIdOffset,
// final MapView mapView) { // final MapView map) {
// boolean result = true; // boolean result = true;
// for (final Layer overlay : this.overlaysReversed()) { // for (final Layer overlay : this.overlaysReversed()) {
// if ((overlay instanceof ILayerMenuProvider) // if ((overlay instanceof ILayerMenuProvider)
// && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) { // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) {
// result &= ((ILayerMenuProvider) overlay).onCreateOptionsMenu(pMenu, // result &= ((ILayerMenuProvider) overlay).onCreateOptionsMenu(pMenu,
// menuIdOffset, // menuIdOffset,
// mapView); // map);
// } // }
// } // }
// //
@ -443,7 +443,7 @@ public class LayerManager extends AbstractList<Layer> {
// ILayerMenuProvider) // ILayerMenuProvider)
// && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) { // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) {
// result &= mTilesLayer.onCreateOptionsMenu(pMenu, menuIdOffset, // result &= mTilesLayer.onCreateOptionsMenu(pMenu, menuIdOffset,
// mapView); // map);
// } // }
// //
// return result; // return result;
@ -451,19 +451,19 @@ public class LayerManager extends AbstractList<Layer> {
// //
// public boolean onPrepareOptionsMenu(final Menu pMenu, final int // public boolean onPrepareOptionsMenu(final Menu pMenu, final int
// menuIdOffset, // menuIdOffset,
// final MapView mapView) { // final MapView map) {
// for (final Layer overlay : this.overlaysReversed()) { // for (final Layer overlay : this.overlaysReversed()) {
// if ((overlay instanceof ILayerMenuProvider) // if ((overlay instanceof ILayerMenuProvider)
// && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) { // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()) {
// ((ILayerMenuProvider) overlay).onPrepareOptionsMenu(pMenu, // ((ILayerMenuProvider) overlay).onPrepareOptionsMenu(pMenu,
// menuIdOffset, mapView); // menuIdOffset, map);
// } // }
// } // }
// //
// if ((mTilesLayer != null) && (mTilesLayer instanceof // if ((mTilesLayer != null) && (mTilesLayer instanceof
// ILayerMenuProvider) // ILayerMenuProvider)
// && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) { // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()) {
// mTilesLayer.onPrepareOptionsMenu(pMenu, menuIdOffset, mapView); // mTilesLayer.onPrepareOptionsMenu(pMenu, menuIdOffset, map);
// } // }
// //
// return true; // return true;
@ -471,13 +471,13 @@ public class LayerManager extends AbstractList<Layer> {
// //
// public boolean onOptionsItemSelected(final MenuItem item, final int // public boolean onOptionsItemSelected(final MenuItem item, final int
// menuIdOffset, // menuIdOffset,
// final MapView mapView) { // final MapView map) {
// for (final Layer overlay : this.overlaysReversed()) { // for (final Layer overlay : this.overlaysReversed()) {
// if ((overlay instanceof ILayerMenuProvider) // if ((overlay instanceof ILayerMenuProvider)
// && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled() // && ((ILayerMenuProvider) overlay).isOptionsMenuEnabled()
// && ((ILayerMenuProvider) overlay).onOptionsItemSelected(item, // && ((ILayerMenuProvider) overlay).onOptionsItemSelected(item,
// menuIdOffset, // menuIdOffset,
// mapView)) { // map)) {
// return true; // return true;
// } // }
// } // }
@ -487,7 +487,7 @@ public class LayerManager extends AbstractList<Layer> {
// && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled() // && ((ILayerMenuProvider) mTilesLayer).isOptionsMenuEnabled()
// && ((ILayerMenuProvider) mTilesLayer).onOptionsItemSelected(item, // && ((ILayerMenuProvider) mTilesLayer).onOptionsItemSelected(item,
// menuIdOffset, // menuIdOffset,
// mapView)) { // map)) {
// return true; // return true;
// } // }
// //

View File

@ -33,23 +33,27 @@ import org.oscim.theme.ThemeLoader;
import org.oscim.tilesource.TileSource; import org.oscim.tilesource.TileSource;
import org.oscim.utils.async.AsyncExecutor; 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; //public static boolean enableClosePolygons;
private final LayerManager mLayerManager; private final LayerManager mLayerManager;
private final MapViewPosition mMapViewPosition; private final Viewport mViewport;
private final MapPosition mMapPosition; private final MapPosition mMapPosition;
private final AsyncExecutor mAsyncExecutor; private final AsyncExecutor mAsyncExecutor;
private DebugSettings mDebugSettings; private DebugSettings mDebugSettings;
protected boolean mClearMap; 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(); mMapPosition = new MapPosition();
mLayerManager = new LayerManager(); mLayerManager = new LayerManager();
mAsyncExecutor = new AsyncExecutor(2); mAsyncExecutor = new AsyncExecutor(2);
@ -58,11 +62,13 @@ public abstract class MapView {
mDebugSettings = new DebugSettings(); mDebugSettings = new DebugSettings();
MapTileLoader.setDebugSettings(mDebugSettings); MapTileLoader.setDebugSettings(mDebugSettings);
mLayerManager.add(0, new MapEventLayer(this)); mEventLayer = new MapEventLayer(this);
mLayerManager.add(0, mEventLayer);
} }
private MapTileLayer mBaseLayer; public MapEventLayer getEventLayer() {
//private BitmapTileLayer mBackgroundLayer; return mEventLayer;
}
public MapTileLayer setBaseMap(TileSource tileSource) { public MapTileLayer setBaseMap(TileSource tileSource) {
mBaseLayer = new MapTileLayer(this); mBaseLayer = new MapTileLayer(this);
@ -82,17 +88,25 @@ public abstract class MapView {
return null; return null;
} }
private InternalRenderTheme mCurrentTheme;
public void setTheme(InternalRenderTheme theme) { public void setTheme(InternalRenderTheme theme) {
if (mBaseLayer == null) { if (mBaseLayer == null) {
Log.e(TAG, "No base layer set"); Log.e(TAG, "No base layer set");
throw new IllegalStateException(); throw new IllegalStateException();
} }
if (mCurrentTheme == theme){
Log.d(TAG, "same theme: " + theme);
return;
}
IRenderTheme t = ThemeLoader.load(theme); IRenderTheme t = ThemeLoader.load(theme);
if (t == null) { if (t == null) {
Log.e(TAG, "Invalid theme"); Log.e(TAG, "Invalid theme");
throw new IllegalStateException(); throw new IllegalStateException();
} }
mCurrentTheme = theme;
mBaseLayer.setRenderTheme(t); mBaseLayer.setRenderTheme(t);
GLRenderer.setBackgroundColor(t.getMapBackground()); GLRenderer.setBackgroundColor(t.getMapBackground());
@ -158,7 +172,7 @@ public abstract class MapView {
boolean changed = false; boolean changed = false;
// get the current MapPosition // get the current MapPosition
changed |= mMapViewPosition.getMapPosition(mMapPosition); changed |= mViewport.getMapPosition(mMapPosition);
mLayerManager.onUpdate(mMapPosition, changed, mClearMap); mLayerManager.onUpdate(mMapPosition, changed, mClearMap);
mClearMap = false; mClearMap = false;
@ -174,7 +188,11 @@ public abstract class MapView {
} }
public void setMapPosition(MapPosition mapPosition) { 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) { public void setCenter(GeoPoint geoPoint) {
mMapViewPosition.setMapCenter(geoPoint); mViewport.setMapCenter(geoPoint);
updateMap(true); updateMap(true);
} }
/** /**
* @return MapViewPosition * @return Viewport
*/ */
public MapViewPosition getMapViewPosition() { public Viewport getViewport() {
return mMapViewPosition; return mViewport;
} }
/** /**
@ -215,7 +233,6 @@ public abstract class MapView {
* @return estimated visible axis aligned bounding box * @return estimated visible axis aligned bounding box
*/ */
public BoundingBox getBoundingBox() { public BoundingBox getBoundingBox() {
return mMapViewPosition.getViewBox(); return mViewport.getViewBox();
} }
} }

View File

@ -16,6 +16,7 @@
package org.oscim.view; package org.oscim.view;
import org.oscim.core.BoundingBox; import org.oscim.core.BoundingBox;
import org.oscim.core.Box;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
@ -25,8 +26,8 @@ import org.oscim.core.Tile;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.Matrix4; import org.oscim.utils.Matrix4;
public class MapViewPosition { public class Viewport {
private static final String TAG = MapViewPosition.class.getName(); //private static final String TAG = Viewport.class.getName();
// needs to fit for int: 2 * 20 * Tile.SIZE // needs to fit for int: 2 * 20 * Tile.SIZE
public final static int MAX_ZOOMLEVEL = 20; 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 MAX_SCALE = (1 << MAX_ZOOMLEVEL);
public final static double MIN_SCALE = (1 << MIN_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 mAbsScale;
private double mAbsX; private double mAbsX;
@ -68,7 +69,9 @@ public class MapViewPosition {
private final PointD mMovePoint = new PointD(); private final PointD mMovePoint = new PointD();
private final float[] mv = new float[4]; private final float[] mv = new float[4];
private final float[] mu = 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; private float mHeight, mWidth;
@ -78,8 +81,8 @@ public class MapViewPosition {
// scale map plane at VIEW_DISTANCE to near plane // scale map plane at VIEW_DISTANCE to near plane
public final static float VIEW_SCALE = (VIEW_NEAR / VIEW_DISTANCE) * 0.5f; public final static float VIEW_SCALE = (VIEW_NEAR / VIEW_DISTANCE) * 0.5f;
MapViewPosition(MapView map) { Viewport(Map map) {
mMapView = map; mMap = map;
mAbsScale = 4; mAbsScale = 4;
mAbsX = 0.5; mAbsX = 0.5;
@ -196,17 +199,25 @@ public class MapViewPosition {
* and the map plane * and the map plane
*/ */
private float getZ(float y) { private float getZ(float y) {
if (y == 0)
return 0;
// origin is moved by VIEW_DISTANCE // origin is moved by VIEW_DISTANCE
double cx = VIEW_DISTANCE; double cx = VIEW_DISTANCE;
// 'height' of the ray // 'height' of the ray
double ry = y * (mHeight / mWidth) * 0.5f; double ry = y * (mHeight / mWidth) * 0.5f;
// tilt of the plane (center is kept on x = 0) double ua;
double t = Math.toRadians(mTilt);
double px = y * Math.sin(t);
double py = y * Math.cos(t);
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[0] = 0;
mv[1] = (float) (ry / ua); mv[1] = (float) (ry / ua);
@ -241,46 +252,46 @@ public class MapViewPosition {
* @return BoundingBox containing view * @return BoundingBox containing view
*/ */
public synchronized BoundingBox getViewBox() { public synchronized BoundingBox getViewBox() {
getViewBox(mMapBBox);
float[] coords = mBBoxCoords; // scale map-pixel coordinates at current scale to
// get depth at bottom and top // absolute coordinates and apply mercator projection.
float t = getZ(1); double minLon = MercatorProjection.toLongitude(mMapBBox.minX);
float t2 = getZ(-1); double maxLon = MercatorProjection.toLongitude(mMapBBox.maxX);
// sic(k)
// project screen corners onto map double minLat = MercatorProjection.toLatitude(mMapBBox.maxY);
unproject(1, -1, t, coords, 0); double maxLat = MercatorProjection.toLatitude(mMapBBox.minY);
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);
return new BoundingBox(minLat, minLon, maxLat, maxLon); 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 * For x, y in screen coordinates set Point to map-tile
* coordinates at returned scale. * coordinates at returned scale.
@ -308,16 +319,29 @@ public class MapViewPosition {
/** /**
* Get the GeoPoint for x,y in screen coordinates. * Get the GeoPoint for x,y in screen coordinates.
* (only used by MapEventsOverlay currently)
* *
* @deprecated
* @param x screen coordinate * @param x screen coordinate
* @param y screen coordinate * @param y screen coordinate
* @return the corresponding GeoPoint * @return the corresponding GeoPoint
*/ */
public synchronized GeoPoint fromScreenPixels(float x, float y) { 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 // scale to -1..1
float mx = 1 - (x / mWidth * 2); float mx = (float) (1 - (x / mWidth * 2));
float my = 1 - (y / mHeight * 2); float my = (float) (1 - (y / mHeight * 2));
unproject(-mx, my, getZ(-my), mu, 0); unproject(-mx, my, getZ(-my), mu, 0);
@ -340,33 +364,39 @@ public class MapViewPosition {
else if (dy < 0) else if (dy < 0)
dy = 0; dy = 0;
GeoPoint p = new GeoPoint( out.x = dx;
MercatorProjection.toLatitude(dy), out.y = dy;
MercatorProjection.toLongitude(dx));
return p;
} }
/** /**
* Get the screen pixel for a GeoPoint * Get the screen pixel for a GeoPoint
* *
* @deprecated
* @param geoPoint the GeoPoint * @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 * @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; mv[0] = (float) (x * mCurScale - mCurX);
double y = MercatorProjection.latitudeToY(geoPoint.getLatitude()) * mCurScale; mv[1] = (float) (y * mCurScale - mCurY);
mv[0] = (float) (x - mCurX);
mv[1] = (float) (y - mCurY);
mv[2] = 0; mv[2] = 0;
mv[3] = 1; mv[3] = 1;
mVPMatrix.prj(mv); 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() { 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 mx the amount of pixels to move the map horizontally.
* @param my the amount of pixels to move the map vertically. * @param my the amount of pixels to move the map vertically.
@ -515,19 +545,16 @@ public class MapViewPosition {
} }
public synchronized boolean tiltMap(float move) { public synchronized boolean tiltMap(float move) {
float tilt = FastMath.clamp(mTilt + move, 0, MAX_ANGLE); return setTilt(mTilt + move);
if (mTilt == tilt)
return false;
setTilt(tilt);
return true;
} }
public synchronized void setTilt(float f) { public synchronized boolean setTilt(float tilt) {
mTilt = f; tilt = FastMath.clamp(tilt, 0, MAX_TILT);
if (tilt == mTilt)
return false;
mTilt = tilt;
updateMatrix(); updateMatrix();
return true;
} }
public synchronized float getTilt() { public synchronized float getTilt() {
@ -673,7 +700,7 @@ public class MapViewPosition {
mDuration = duration; mDuration = duration;
mAnimEnd = System.currentTimeMillis() + (long) duration; mAnimEnd = System.currentTimeMillis() + (long) duration;
mMapView.render(); mMap.render();
} }
private void animCancel() { private void animCancel() {
@ -754,7 +781,7 @@ public class MapViewPosition {
} }
updatePosition(); updatePosition();
mMapView.updateMap(true); mMap.updateMap(true);
animCancel(); animCancel();
return; return;
@ -793,10 +820,10 @@ public class MapViewPosition {
// continue animation // continue animation
if (changed) { if (changed) {
// inform other layers that position has changed // inform other layers that position has changed
mMapView.updateMap(true); mMap.updateMap(true);
} else { } else {
// just render next frame // just render next frame
mMapView.render(); mMap.render();
} }
} }