Fixed issue 494.

Do not draw new map when it is already drawing and there is only
rotation change.
This commit is contained in:
Pavol Zibrita 2011-10-13 00:25:50 +02:00
parent 734888f238
commit b3c6fede74
4 changed files with 84 additions and 15 deletions

View file

@ -4,22 +4,21 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import org.apache.commons.logging.Log;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import net.osmand.Algoritms; import net.osmand.Algoritms;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader;
import net.osmand.data.TransportStop;
import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.DownloadRequest;
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.data.TransportStop;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import org.apache.commons.logging.Log;
import android.os.Handler;
import android.os.HandlerThread;
/** /**
* Thread to load map objects (POI, transport stops )async * Thread to load map objects (POI, transport stops )async
*/ */

View file

@ -13,6 +13,9 @@ public class RotatedTileBox {
private int zoom; private int zoom;
private float rotateCos; private float rotateCos;
private float rotateSin; private float rotateSin;
private RectF latLon;
private boolean rendering;
private RotatedTileBox parent;
public RotatedTileBox(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) { public RotatedTileBox(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) {
set(leftTileX, topTileY, tileWidth, tileHeight, rotate, zoom); set(leftTileX, topTileY, tileWidth, tileHeight, rotate, zoom);
@ -20,6 +23,9 @@ public class RotatedTileBox {
public RotatedTileBox(RotatedTileBox r){ public RotatedTileBox(RotatedTileBox r){
set(r.leftTileX, r.topTileY, r.tileWidth, r.tileHeight, r.rotate, r.zoom); set(r.leftTileX, r.topTileY, r.tileWidth, r.tileHeight, r.rotate, r.zoom);
this.latLon = r.latLon;
this.rendering = r.rendering;
this.parent = r;
} }
private void init() { private void init() {
@ -166,6 +172,61 @@ public class RotatedTileBox {
return calcPointTileY(tileWidth, tileHeight); return calcPointTileY(tileWidth, tileHeight);
} }
/**
* the lat lon bounds
* @param latLonBounds
*/
public void setLatLon(RectF latLonBounds) {
//on new latLonBounds reset rendering info and latLonBounds....
if (!latLonBounds.equals(this.latLon)) {
this.rendering = false;
this.latLon = latLonBounds;
}
}
/**
* @return true if rendering is in progress
*/
public boolean isRendering() {
return rendering;
}
/**
* Say we are rendering this box
*/
public void rendering() {
rendering = true;
if (parent != null) {
parent.rendering(latLon);
}
}
/**
* Say we are rendering this box for this coordinates
*
* @param aLatLon
*/
private void rendering(RectF aLatLon) {
if (aLatLon.equals(latLon)) {
rendering = true;
}
}
/**
* all if rendering was interrupted
*/
public void renderingInterrupted() {
rendered();
}
/**
* Call if rendering is finished
*/
public void rendered() {
rendering = false;
if (parent != null) {
parent.rendered();
}
}
} }

View file

@ -196,6 +196,9 @@ public class MapRenderRepositories {
} }
public void interruptLoadingMap(){ public void interruptLoadingMap(){
if (requestedBox != null) {
requestedBox.renderingInterrupted();
}
interrupted = true; interrupted = true;
if(currentRenderingContext != null){ if(currentRenderingContext != null){
currentRenderingContext.interrupted = true; currentRenderingContext.interrupted = true;
@ -207,6 +210,9 @@ public class MapRenderRepositories {
private boolean checkWhetherInterrupted(){ private boolean checkWhetherInterrupted(){
if(interrupted || (currentRenderingContext != null && currentRenderingContext.interrupted)){ if(interrupted || (currentRenderingContext != null && currentRenderingContext.interrupted)){
if (requestedBox != null) {
requestedBox.renderingInterrupted();
}
requestedBox = bmpLocation; requestedBox = bmpLocation;
return true; return true;
} }
@ -356,6 +362,10 @@ public class MapRenderRepositories {
currentRenderingContext = null; currentRenderingContext = null;
} }
try { try {
// prevent editing
requestedBox = new RotatedTileBox(tileRect);
requestedBox.rendering();
// find selected rendering type // find selected rendering type
OsmandApplication app = ((OsmandApplication)context.getApplicationContext()); OsmandApplication app = ((OsmandApplication)context.getApplicationContext());
Boolean renderDay = app.getDaynightHelper().getDayNightRenderer(); Boolean renderDay = app.getDaynightHelper().getDayNightRenderer();
@ -363,9 +373,6 @@ public class MapRenderRepositories {
// boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get(); // boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get();
BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer(); BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer();
// prevent editing
requestedBox = new RotatedTileBox(tileRect);
// calculate data box // calculate data box
RectF dataBox = requestedBox.calculateLatLonBox(new RectF()); RectF dataBox = requestedBox.calculateLatLonBox(new RectF());
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -419,7 +426,6 @@ public class MapRenderRepositories {
} }
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp,
prefs.USE_ENGLISH_NAMES.get(), renderingType, stepByStep ? notifyList : null); prefs.USE_ENGLISH_NAMES.get(), renderingType, stepByStep ? notifyList : null);
String renderingDebugInfo = currentRenderingContext.renderingDebugInfo; String renderingDebugInfo = currentRenderingContext.renderingDebugInfo;
@ -468,9 +474,11 @@ public class MapRenderRepositories {
Toast.makeText(context, R.string.rendering_out_of_memory, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.rendering_out_of_memory, Toast.LENGTH_SHORT).show();
} }
}); });
} finally {
if (requestedBox != null) {
requestedBox.rendered();
}
} }
} }
public Bitmap getBitmap() { public Bitmap getBitmap() {

View file

@ -93,10 +93,11 @@ public class MapVectorLayer extends BaseMapLayer {
tileLayer.drawTileMap(canvas, tilesRect); tileLayer.drawTileMap(canvas, tilesRect);
resourceManager.getRenderer().interruptLoadingMap(); resourceManager.getRenderer().interruptLoadingMap();
} else { } else {
rotatedTileBox.setLatLon(latLonBounds);
if (!view.isZooming()) { if (!view.isZooming()) {
pixRect.set(0, 0, view.getWidth(), view.getHeight()); pixRect.set(0, 0, view.getWidth(), view.getHeight());
updateRotatedTileBox(); updateRotatedTileBox();
if (resourceManager.updateRenderedMapNeeded(rotatedTileBox)) { if (!rotatedTileBox.isRendering() && resourceManager.updateRenderedMapNeeded(rotatedTileBox)) {
// pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * view.getHeight() / 2); // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * view.getHeight() / 2);
pixRect.set(-view.getWidth() / 3, -view.getHeight() / 4, 4 * view.getWidth() / 3, 5 * view.getHeight() / 4); pixRect.set(-view.getWidth() / 3, -view.getHeight() / 4, 4 * view.getWidth() / 3, 5 * view.getHeight() / 4);
updateRotatedTileBox(); updateRotatedTileBox();