gdx: simplify sub-classing GdxMap apps, add createLayers()
This commit is contained in:
parent
1498325ecd
commit
a660048bcb
@ -19,42 +19,41 @@ import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
public class MainActivity extends AndroidApplication {
|
||||
|
||||
private final class AndroidGLAdapter extends AndroidGL20 implements GL20{
|
||||
private final class AndroidGLAdapter extends AndroidGL20 implements GL20 {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// set globals
|
||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
||||
GLAdapter.g = new AndroidGLAdapter();
|
||||
// set globals
|
||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
||||
GLAdapter.g = new AndroidGLAdapter();
|
||||
Log.logger = new AndroidLog();
|
||||
|
||||
// TODO make this dpi dependent
|
||||
Tile.SIZE = 400;
|
||||
|
||||
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
|
||||
cfg.useGL20 = true;
|
||||
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
|
||||
cfg.useGL20 = true;
|
||||
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
|
||||
initialize(new GdxMapAndroid(), cfg);
|
||||
}
|
||||
initialize(new GdxMapAndroid(), cfg);
|
||||
}
|
||||
|
||||
class GdxMapAndroid extends GdxMap {
|
||||
|
||||
class GdxMapAndroid extends GdxMap{
|
||||
@Override
|
||||
public void create() {
|
||||
super.create();
|
||||
public void createLayers() {
|
||||
|
||||
//TileSource ts = new OSciMap4TileSource();
|
||||
//ts.setOption("url", "http://city.informatik.uni-bremen.de/osci/testing");
|
||||
//TileSource ts = new OSciMap4TileSource();
|
||||
//ts.setOption("url", "http://opensciencemap.org/tiles/vtm");
|
||||
|
||||
TileSource ts = new OSciMap2TileSource();
|
||||
ts.setOption("url", "http://city.informatik.uni-bremen.de/osci/map-live");
|
||||
TileSource ts = new OSciMap2TileSource();
|
||||
ts.setOption("url", "http://opensciencemap.org/osci/map-live");
|
||||
|
||||
initDefaultMap(ts, true, true, true);
|
||||
initDefaultLayers(ts, true, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
* compatible. Some glGetXXX methods are not implemented.
|
||||
*
|
||||
* @author mzechner */
|
||||
final class GdxGLAdapter implements org.oscim.backend.GL20 {
|
||||
public final class GdxGLAdapter implements org.oscim.backend.GL20 {
|
||||
public void glActiveTexture (int texture) {
|
||||
GL13.glActiveTexture(texture);
|
||||
}
|
||||
|
@ -11,9 +11,22 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
public class Main {
|
||||
public class GdxMapApp extends GdxMap {
|
||||
|
||||
static {
|
||||
// set our globals
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
CanvasAdapter.g = AwtGraphics.INSTANCE;
|
||||
GLAdapter.g = new GdxGLAdapter();
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Tile.SIZE = 360;
|
||||
new LwjglApplication(new GdxMapApp(), getConfig());
|
||||
}
|
||||
|
||||
static protected LwjglApplicationConfiguration getConfig() {
|
||||
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
|
||||
cfg.title = "vtm-gdx";
|
||||
cfg.useGL20 = true;
|
||||
@ -21,34 +34,13 @@ public class Main {
|
||||
cfg.height = 800;
|
||||
cfg.stencil = 8;
|
||||
cfg.foregroundFPS = 20;
|
||||
// cfg.samples = 4;
|
||||
|
||||
// set our globals
|
||||
CanvasAdapter.g = AwtGraphics.INSTANCE;
|
||||
GLAdapter.g = new GdxGLAdapter();
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
|
||||
Tile.SIZE = 360;
|
||||
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
|
||||
new LwjglApplication(new GdxMapDesktop(), cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static class GdxMapDesktop extends GdxMap {
|
||||
|
||||
public GdxMapDesktop() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
super.create();
|
||||
|
||||
TileSource tileSource = new OSciMap4TileSource();
|
||||
tileSource.setOption("url", "http://city.informatik.uni-bremen.de/tiles/vtm");
|
||||
|
||||
initDefaultMap(tileSource, false, true, true);
|
||||
}
|
||||
@Override
|
||||
public void createLayers() {
|
||||
TileSource tileSource = new OSciMap4TileSource();
|
||||
tileSource.setOption("url", "http://opensciencemap.org/tiles/vtm");
|
||||
initDefaultLayers(tileSource, false, true, true);
|
||||
}
|
||||
}
|
@ -98,7 +98,7 @@ class GwtGdxMap extends GdxMap {
|
||||
|
||||
tileSource.setOption("url", url);
|
||||
|
||||
initDefaultMap(tileSource, false, true, true);
|
||||
initDefaultLayers(tileSource, false, true, true);
|
||||
|
||||
if ("naturalearth".equals(c.getBackgroundLayer()))
|
||||
mMap.setBackgroundMap(new BitmapTileLayer(mMap, NaturalEarth.INSTANCE));
|
||||
@ -139,4 +139,8 @@ class GwtGdxMap extends GdxMap {
|
||||
};
|
||||
timer.scheduleRepeating(5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.oscim.gdx;
|
||||
|
||||
import org.oscim.backend.AssetAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.layers.tile.vector.BuildingLayer;
|
||||
@ -10,9 +9,9 @@ import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GridRenderer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.theme.InternalRenderTheme;
|
||||
import org.oscim.tiling.source.TileSource;
|
||||
|
||||
@ -29,7 +28,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
|
||||
public class GdxMap implements ApplicationListener {
|
||||
public abstract class GdxMap implements ApplicationListener {
|
||||
|
||||
protected final Map mMap;
|
||||
private final MapRenderer mMapRenderer;
|
||||
@ -89,7 +88,7 @@ public class GdxMap implements ApplicationListener {
|
||||
|
||||
}
|
||||
|
||||
protected void initDefaultMap(TileSource tileSource, boolean tileGrid, boolean labels,
|
||||
protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolean labels,
|
||||
boolean buildings) {
|
||||
|
||||
if (tileSource != null) {
|
||||
@ -133,11 +132,13 @@ public class GdxMap implements ApplicationListener {
|
||||
mHeight = h;
|
||||
|
||||
mMap.getViewport().setViewport(w, h);
|
||||
MapPosition p = new MapPosition();
|
||||
p.setZoomLevel(14);
|
||||
p.setPosition(53.08, 8.83);
|
||||
|
||||
//MapPosition p = new MapPosition();
|
||||
//p.setZoomLevel(14);
|
||||
//p.setPosition(53.08, 8.83);
|
||||
//p.setPosition(0.0, 0.0);
|
||||
mMap.setMapPosition(p);
|
||||
//mMap.setMapPosition(p);
|
||||
|
||||
mMapRenderer.onSurfaceCreated();
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
|
||||
@ -154,8 +155,11 @@ public class GdxMap implements ApplicationListener {
|
||||
// fps.setPosition(10, 30);
|
||||
// fps.setColor(0, 1, 0, 1);
|
||||
// ui.addActor(fps);
|
||||
createLayers();
|
||||
}
|
||||
|
||||
protected abstract void createLayers();
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user