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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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