Viewport size change not render map completely, fixes #160

This commit is contained in:
Emux 2016-09-06 13:52:21 +03:00
parent ab98b676fc
commit 12869c6718
3 changed files with 18 additions and 19 deletions

View File

@ -2,6 +2,7 @@
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov
* Copyright 2016 Stephan Leuschner
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -25,7 +26,6 @@ import org.oscim.event.Event;
import org.oscim.event.EventDispatcher;
import org.oscim.event.EventListener;
import org.oscim.event.Gesture;
import org.oscim.event.GestureDetector;
import org.oscim.event.MotionEvent;
import org.oscim.layers.Layer;
import org.oscim.layers.MapEventLayer;
@ -106,7 +106,6 @@ public abstract class Map implements TaskQueue {
protected final MapPosition mMapPosition;
protected final MapEventLayer mEventLayer;
protected GestureDetector mGestureDetector;
protected boolean mClearMap = true;
@ -147,7 +146,7 @@ public abstract class Map implements TaskQueue {
/**
* Create OsmTileLayer with given TileSource and
* set as base map (layer 1)
* <p/>
* <p>
* TODO deprecate
*/
public VectorTileLayer setBaseMap(TileSource tileSource) {
@ -239,7 +238,7 @@ public abstract class Map implements TaskQueue {
public abstract boolean postDelayed(Runnable action, long delay);
/**
* Post a task to run on a shared worker-thread. Shoul only use for
* Post a task to run on a shared worker-thread. Should only use for
* tasks running less than a second.
*/
@Override
@ -342,7 +341,7 @@ public abstract class Map implements TaskQueue {
/**
* This function is run on main-thread before rendering a frame.
* <p/>
* <p>
* For internal use only. Do not call!
*/
protected void prepareFrame() {
@ -353,10 +352,11 @@ public abstract class Map implements TaskQueue {
mAnimator.updateAnimation();
boolean changed = mViewport.getMapPosition(pos);
boolean sizeChanged = mViewport.sizeChanged();
if (mClearMap)
events.fire(CLEAR_EVENT, pos);
else if (changed)
else if (changed || sizeChanged)
events.fire(POSITION_EVENT, pos);
else
events.fire(UPDATE_EVENT, pos);

View File

@ -136,9 +136,6 @@ public class ViewController extends Viewport {
* Scale map by scale width center at pivot in pixel relative to
* screen center. Map scale is clamp to MIN_SCALE and MAX_SCALE.
*
* @param scale
* @param pivotX
* @param pivotY
* @return true if scale was changed
*/
public boolean scaleMap(float scale, float pivotX, float pivotY) {
@ -172,10 +169,6 @@ public class ViewController extends Viewport {
/**
* Rotate map by radians around pivot. Pivot is in pixel relative
* to screen center.
*
* @param radians
* @param pivotX
* @param pivotY
*/
public void rotateMap(double radians, float pivotX, float pivotY) {
ThreadUtils.assertMainThread();
@ -269,6 +262,12 @@ public class ViewController extends Viewport {
return mNextFrame;
}
boolean sizeChanged() {
synchronized (mNextFrame) {
return mNextFrame.sizeChanged(this);
}
}
void syncViewport() {
synchronized (mNextFrame) {
mNextFrame.copy(this);

View File

@ -26,20 +26,16 @@ import org.oscim.core.Point;
import org.oscim.core.Tile;
import org.oscim.renderer.GLMatrix;
import org.oscim.utils.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Viewport class contains a MapPosition and the projection matrices.
* It provides functions to modify the MapPosition and translate between
* map and screen coordinates.
* <p/>
* <p>
* Public methods are thread safe.
*/
public class Viewport {
static final Logger log = LoggerFactory.getLogger(Viewport.class);
private final static int MAX_ZOOMLEVEL = 20;
private final static int MIN_ZOOMLEVEL = 2;
private final static float MIN_TILT = 0;
@ -389,8 +385,12 @@ public class Viewport {
}
}
boolean sizeChanged(Viewport viewport) {
return mHeight != viewport.mHeight || mWidth != viewport.mWidth;
}
protected boolean copy(Viewport viewport) {
boolean sizeChanged = mHeight != viewport.mHeight || mWidth != viewport.mWidth;
boolean sizeChanged = sizeChanged(viewport);
mHeight = viewport.mHeight;
mWidth = viewport.mWidth;