gdx: pass TileSource to GdxMap constructor
This commit is contained in:
parent
a35abdb2cf
commit
75e4d36945
@ -11,11 +11,11 @@ import org.oscim.renderer.GLRenderer;
|
|||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
import org.oscim.theme.InternalRenderTheme;
|
import org.oscim.theme.InternalRenderTheme;
|
||||||
import org.oscim.tilesource.TileSource;
|
import org.oscim.tilesource.TileSource;
|
||||||
import org.oscim.tilesource.oscimap4.OSciMap4TileSource;
|
|
||||||
import org.oscim.view.MapRenderCallback;
|
import org.oscim.view.MapRenderCallback;
|
||||||
import org.oscim.view.MapView;
|
import org.oscim.view.MapView;
|
||||||
import org.oscim.view.MapViewPosition;
|
import org.oscim.view.MapViewPosition;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Application;
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
@ -30,10 +30,11 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
private final MapView mMapView;
|
private final MapView mMapView;
|
||||||
private final GLRenderer mMapRenderer;
|
private final GLRenderer mMapRenderer;
|
||||||
|
private final TileSource mTileSource;
|
||||||
|
|
||||||
public GdxMap() {
|
public GdxMap(TileSource tileSource) {
|
||||||
AssetAdapter.g = new GdxAssetAdapter();
|
AssetAdapter.g = new GdxAssetAdapter();
|
||||||
|
mTileSource = tileSource;
|
||||||
mMapView = new MapView(this);
|
mMapView = new MapView(this);
|
||||||
mMapRenderer = new GLRenderer(mMapView);
|
mMapRenderer = new GLRenderer(mMapView);
|
||||||
}
|
}
|
||||||
@ -48,29 +49,26 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
Gdx.graphics.setContinuousRendering(false);
|
Gdx.graphics.setContinuousRendering(false);
|
||||||
|
|
||||||
if (Log.logger == null)
|
Log.logger = new GdxLog();
|
||||||
Log.logger = new GdxLog();
|
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||||
|
|
||||||
Gdx.app.log("gdx says", "Hi!");
|
|
||||||
Log.d("vtm says", "Hi!");
|
|
||||||
|
|
||||||
int w = Gdx.graphics.getWidth();
|
int w = Gdx.graphics.getWidth();
|
||||||
int h = Gdx.graphics.getHeight();
|
int h = Gdx.graphics.getHeight();
|
||||||
mWidth = w;
|
mWidth = w;
|
||||||
mHeight = h;
|
mHeight = h;
|
||||||
|
|
||||||
if (null == null) {
|
if (mTileSource != null) {
|
||||||
//TileSource tileSource = new OSciMap2TileSource();
|
//TileSource tileSource = new OSciMap2TileSource();
|
||||||
//tileSource.setOption("url",
|
//tileSource.setOption("url",
|
||||||
// "http://city.informatik.uni-bremen.de/osci/map-live");
|
// "http://city.informatik.uni-bremen.de/osci/map-live");
|
||||||
|
|
||||||
TileSource tileSource = new OSciMap4TileSource();
|
// TileSource tileSource = new OSciMap4TileSource();
|
||||||
tileSource.setOption("url",
|
// tileSource.setOption("url",
|
||||||
"http://city.informatik.uni-bremen.de/osci/testing");
|
// "http://city.informatik.uni-bremen.de/osci/testing");
|
||||||
|
|
||||||
// TileSource tileSource = new TestTileSource();
|
// TileSource tileSource = new TestTileSource();
|
||||||
|
|
||||||
mMapLayer = mMapView.setBaseMap(tileSource);
|
mMapLayer = mMapView.setBaseMap(mTileSource);
|
||||||
mMapLayer.setRenderTheme(InternalRenderTheme.DEFAULT);
|
mMapLayer.setRenderTheme(InternalRenderTheme.DEFAULT);
|
||||||
|
|
||||||
mMapView.getLayerManager().add(new BuildingOverlay(mMapView, mMapLayer.getTileLayer()));
|
mMapView.getLayerManager().add(new BuildingOverlay(mMapView, mMapLayer.getTileLayer()));
|
||||||
@ -78,8 +76,11 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mMapView.setBaseMap(new BitmapTileLayer(mMapView,
|
//mMapView.setBackgroundMap(new BitmapTileLayer(mMapView,
|
||||||
// OpenStreetMapMapnik.INSTANCE));
|
// ArcGISWorldShaded.INSTANCE));
|
||||||
|
|
||||||
|
//mMapView.setBackgroundMap(new BitmapTileLayer(mMapView,
|
||||||
|
// OpenStreetMapMapnik.INSTANCE));
|
||||||
|
|
||||||
//mMapView.getLayerManager().add(new GenericOverlay(mMapView, new
|
//mMapView.getLayerManager().add(new GenericOverlay(mMapView, new
|
||||||
// GridRenderLayer(mMapView)));
|
// GridRenderLayer(mMapView)));
|
||||||
@ -113,8 +114,6 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//private int fpsCnt = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
// Log.d("yo", )
|
// Log.d("yo", )
|
||||||
@ -122,17 +121,13 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
// GLState.blend(false);
|
// GLState.blend(false);
|
||||||
// GLState.test(false, false);
|
// GLState.test(false, false);
|
||||||
|
|
||||||
mMapRenderer.onDrawFrame();
|
if (mRenderRequest) {
|
||||||
|
mRenderRequest = false;
|
||||||
|
mMapRenderer.onDrawFrame();
|
||||||
|
}
|
||||||
// Gdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
// Gdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||||
// Gdx.gl20.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
// Gdx.gl20.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
// int f = Gdx.graphics.getFramesPerSecond();
|
|
||||||
// if (f != fpsCnt) {
|
|
||||||
// Log.d("fps", ">" + f);
|
|
||||||
// fpsCnt = f;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fps.setText("fps: " + Gdx.graphics.getFramesPerSecond());
|
// fps.setText("fps: " + Gdx.graphics.getFramesPerSecond());
|
||||||
// ui.draw();
|
// ui.draw();
|
||||||
}
|
}
|
||||||
@ -145,6 +140,8 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
mMapView.getMapViewPosition().setViewport(w, h);
|
mMapView.getMapViewPosition().setViewport(w, h);
|
||||||
mMapRenderer.onSurfaceChanged(w, h);
|
mMapRenderer.onSurfaceChanged(w, h);
|
||||||
|
|
||||||
|
renderMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -170,6 +167,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
mMapView.updateLayers();
|
mMapView.updateLayers();
|
||||||
|
|
||||||
// if (mClearMap) {
|
// if (mClearMap) {
|
||||||
|
mRenderRequest = true;
|
||||||
Gdx.graphics.requestRendering();
|
Gdx.graphics.requestRendering();
|
||||||
mClearMap = false;
|
mClearMap = false;
|
||||||
// }
|
// }
|
||||||
@ -192,14 +190,19 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMap(boolean forceRender) {
|
public void updateMap(boolean forceRender) {
|
||||||
|
|
||||||
if (!mWaitRedraw) {
|
if (!mWaitRedraw) {
|
||||||
mWaitRedraw = true;
|
mWaitRedraw = true;
|
||||||
Gdx.app.postRunnable(mRedrawRequest);
|
Gdx.app.postRunnable(mRedrawRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean mRenderRequest;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderMap() {
|
public void renderMap() {
|
||||||
|
mRenderRequest = true;
|
||||||
|
|
||||||
if (mClearMap)
|
if (mClearMap)
|
||||||
updateMap(false);
|
updateMap(false);
|
||||||
else
|
else
|
||||||
@ -227,7 +230,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean mActiveScale;
|
private boolean mActiveScale;
|
||||||
private boolean mActiveTilt;
|
//private boolean mActiveTilt;
|
||||||
private boolean mActiveRotate;
|
private boolean mActiveRotate;
|
||||||
|
|
||||||
private int mPosX, mPosY;
|
private int mPosX, mPosY;
|
||||||
@ -302,9 +305,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
// Log.d(TAG, "touch up " + pointer);
|
|
||||||
mActiveScale = false;
|
mActiveScale = false;
|
||||||
mActiveTilt = false;
|
|
||||||
mActiveRotate = false;
|
mActiveRotate = false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -314,7 +315,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
if (!(mActiveScale || mActiveRotate) )
|
if (!(mActiveScale || mActiveRotate))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mActiveScale) {
|
if (mActiveScale) {
|
||||||
@ -331,18 +332,18 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!(mActiveRotate || mActiveTilt || mActiveScale)) {
|
// if (!(mActiveRotate || mActiveTilt || mActiveScale)) {
|
||||||
// int dx = screenX - mPosX;
|
// int dx = screenX - mPosX;
|
||||||
// int dy = screenY - mPosY;
|
// int dy = screenY - mPosY;
|
||||||
// if (Math.abs(dx) > 0 || Math.abs(dy) > 0) {
|
// if (Math.abs(dx) > 0 || Math.abs(dy) > 0) {
|
||||||
// mMapPosition.moveMap(dx, dy);
|
// mMapPosition.moveMap(dx, dy);
|
||||||
// mPosX = screenX;
|
// mPosX = screenX;
|
||||||
// mPosY = screenY;
|
// mPosY = screenY;
|
||||||
// changed = true;
|
// changed = true;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (changed){
|
if (changed) {
|
||||||
updateMap(true);
|
updateMap(true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -453,10 +454,6 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean zoom(float initialDistance, float distance) {
|
public boolean zoom(float initialDistance, float distance) {
|
||||||
mayFling = false;
|
|
||||||
// float fx = mMapView.getWidth() / 2;
|
|
||||||
// float fy = mMapView.getHeight() / 2;
|
|
||||||
// mMapPosition.scaleMap(initialDistance / distance, fx, fy);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,17 +478,15 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
|
|||||||
|
|
||||||
mBeginTilt = false;
|
mBeginTilt = false;
|
||||||
mBeginRotate = false;
|
mBeginRotate = false;
|
||||||
mBeginScale= false;
|
mBeginScale = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log.d(TAG, "pinch " + pointer1 + " " + pointer2);
|
|
||||||
|
|
||||||
float x1 = pointer1.x;
|
float x1 = pointer1.x;
|
||||||
float y1 = pointer1.y;
|
float y1 = pointer1.y;
|
||||||
|
|
||||||
float mx = x1 - mPrevX;
|
//float mx = x1 - mPrevX;
|
||||||
float my = y1 - mPrevY;
|
float my = y1 - mPrevY;
|
||||||
|
|
||||||
float x2 = pointer2.x;
|
float x2 = pointer2.x;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user