Fix blank tiles on large windows and tilt (#522)

This commit is contained in:
Gustl22 2018-04-12 11:09:56 +02:00 committed by Emux
parent 7aac624ec7
commit d1f9a4e8f6
No known key found for this signature in database
GPG Key ID: 89C6921D7AF2BDD0
6 changed files with 76 additions and 8 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2012 Hannes Janetzek * Copyright 2012 Hannes Janetzek
* Copyright 2016-2017 devemux86 * Copyright 2016-2018 devemux86
* Copyright 2018 Gustl22
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -18,11 +19,16 @@
package org.oscim.android; package org.oscim.android;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.graphics.Point;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Display;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.WindowManager;
import org.oscim.android.canvas.AndroidGraphics; import org.oscim.android.canvas.AndroidGraphics;
import org.oscim.android.gl.AndroidGL; import org.oscim.android.gl.AndroidGL;
@ -45,7 +51,7 @@ import javax.microedition.khronos.opengles.GL10;
* <p/> * <p/>
* add it your App, have a map! * add it your App, have a map!
* <p/> * <p/>
* Dont forget to call onPause / onResume! * Don't forget to call onPause / onResume!
*/ */
public class MapView extends GLSurfaceView { public class MapView extends GLSurfaceView {
@ -160,14 +166,18 @@ public class MapView extends GLSurfaceView {
static class AndroidMap extends Map { static class AndroidMap extends Map {
private final MapView mMapView; private final MapView mMapView;
private final WindowManager mWindowManager;
private boolean mRenderRequest; private boolean mRenderRequest;
private boolean mRenderWait; private boolean mRenderWait;
private boolean mPausing; private boolean mPausing;
private final Point mScreenSize = new Point();
public AndroidMap(MapView mapView) { public AndroidMap(MapView mapView) {
super(); super();
mMapView = mapView; mMapView = mapView;
mWindowManager = (WindowManager) mMapView.getContext().getSystemService(Context.WINDOW_SERVICE);
} }
@Override @Override
@ -180,6 +190,29 @@ public class MapView extends GLSurfaceView {
return mMapView.getHeight(); return mMapView.getHeight();
} }
@Override
public int getScreenWidth() {
return getScreenSize().x;
}
@Override
public int getScreenHeight() {
return getScreenSize().y;
}
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private Point getScreenSize() {
Display display = mWindowManager.getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
display.getSize(mScreenSize);
else {
mScreenSize.x = display.getWidth();
mScreenSize.y = display.getHeight();
}
return mScreenSize;
}
private final Runnable mRedrawCb = new Runnable() { private final Runnable mRedrawCb = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -208,7 +241,7 @@ public class MapView extends GLSurfaceView {
if (mPausing) if (mPausing)
return; return;
/** TODO should not need to call prepareFrame in mRedrawCb */ /* TODO should not need to call prepareFrame in mRedrawCb */
updateMap(false); updateMap(false);
} }

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016-2018 devemux86 * Copyright 2016-2018 devemux86
* Copyright 2018 Gustl22
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -149,6 +150,16 @@ public abstract class GdxMap implements ApplicationListener {
return Gdx.graphics.getHeight(); return Gdx.graphics.getHeight();
} }
@Override
public int getScreenWidth() {
return Gdx.graphics.getDisplayMode().width;
}
@Override
public int getScreenHeight() {
return Gdx.graphics.getDisplayMode().height;
}
private final Runnable mRedrawCb = new Runnable() { private final Runnable mRedrawCb = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -51,6 +51,16 @@ public class MapAdapter extends Map implements Map.UpdateListener {
return height; return height;
} }
@Override
public int getScreenWidth() {
return Gdx.graphics.getDisplayMode().width;
}
@Override
public int getScreenHeight() {
return Gdx.graphics.getDisplayMode().height;
}
private final Runnable mRedrawCb = new Runnable() { private final Runnable mRedrawCb = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -217,8 +217,9 @@ public class TileManager {
mTilesEnd = 0; mTilesEnd = 0;
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(mMap.getWidth(), mMap.getHeight()); * Use screen size as workaround for blank tiles in #520. */
int num = Math.max(mMap.getScreenWidth(), mMap.getScreenHeight());
int size = Tile.SIZE >> 1; int size = Tile.SIZE >> 1;
int numTiles = (num * num) / (size * size) * 4; int numTiles = (num * num) / (size * size) * 4;

View File

@ -2,8 +2,9 @@
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov * Copyright 2016 Andrey Novikov
* Copyright 2016 Stephan Leuschner * Copyright 2016 Stephan Leuschner
* Copyright 2016-2017 devemux86 * Copyright 2016-2018 devemux86
* Copyright 2016 Longri * Copyright 2016 Longri
* Copyright 2018 Gustl22
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -272,15 +273,25 @@ public abstract class Map implements TaskQueue {
} }
/** /**
* Return screen width in pixel. * Return view width in pixel.
*/ */
public abstract int getWidth(); public abstract int getWidth();
/** /**
* Return screen height in pixel. * Return view height in pixel.
*/ */
public abstract int getHeight(); public abstract int getHeight();
/**
* Return screen width in pixel.
*/
public abstract int getScreenWidth();
/**
* Return screen height in pixel.
*/
public abstract int getScreenHeight();
/** /**
* Request to clear all layers before rendering next frame * Request to clear all layers before rendering next frame
*/ */

View File

@ -42,6 +42,8 @@ public class Viewport {
public final static int MAX_ZOOM_LEVEL = 20; public final static int MAX_ZOOM_LEVEL = 20;
public final static int MIN_ZOOM_LEVEL = 2; public final static int MIN_ZOOM_LEVEL = 2;
public final static float MIN_TILT = 0; public final static float MIN_TILT = 0;
/* Note: limited by numTiles in TileManager to ~80° */
public final static float MAX_TILT = 65; public final static float MAX_TILT = 65;
protected double mMaxScale = (1 << MAX_ZOOM_LEVEL); protected double mMaxScale = (1 << MAX_ZOOM_LEVEL);