libGDX layer gestures, closes #151
This commit is contained in:
parent
46f4d592d3
commit
ebd07950a4
@ -8,10 +8,11 @@
|
|||||||
- Mapsforge multilingual maps [#34](https://github.com/mapsforge/vtm/issues/34)
|
- Mapsforge multilingual maps [#34](https://github.com/mapsforge/vtm/issues/34)
|
||||||
- vtm-ios update module [#29](https://github.com/mapsforge/vtm/issues/29)
|
- vtm-ios update module [#29](https://github.com/mapsforge/vtm/issues/29)
|
||||||
- Native libraries for all platforms [#14](https://github.com/mapsforge/vtm/issues/14)
|
- Native libraries for all platforms [#14](https://github.com/mapsforge/vtm/issues/14)
|
||||||
- LWJGL desktop libGDX backend [#129](https://github.com/mapsforge/vtm/issues/129)
|
|
||||||
- Line stipple and texture rendering [#105](https://github.com/mapsforge/vtm/issues/105)
|
- Line stipple and texture rendering [#105](https://github.com/mapsforge/vtm/issues/105)
|
||||||
- Layer groups [#99](https://github.com/mapsforge/vtm/issues/99) [#103](https://github.com/mapsforge/vtm/issues/103)
|
- Layer groups [#99](https://github.com/mapsforge/vtm/issues/99) [#103](https://github.com/mapsforge/vtm/issues/103)
|
||||||
- Map scale bar multi-platform [#84](https://github.com/mapsforge/vtm/issues/84)
|
- Map scale bar multi-platform [#84](https://github.com/mapsforge/vtm/issues/84)
|
||||||
|
- libGDX layer gestures [#151](https://github.com/mapsforge/vtm/issues/151)
|
||||||
|
- LWJGL desktop libGDX backend [#129](https://github.com/mapsforge/vtm/issues/129)
|
||||||
- Render theme area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
|
- Render theme area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
|
||||||
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
|
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
|
||||||
- vtm-jts module [#53](https://github.com/mapsforge/vtm/issues/53)
|
- vtm-jts module [#53](https://github.com/mapsforge/vtm/issues/53)
|
||||||
|
@ -21,6 +21,7 @@ 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.InputMultiplexer;
|
import com.badlogic.gdx.InputMultiplexer;
|
||||||
|
import com.badlogic.gdx.input.GestureDetector;
|
||||||
import com.badlogic.gdx.utils.Timer;
|
import com.badlogic.gdx.utils.Timer;
|
||||||
import com.badlogic.gdx.utils.Timer.Task;
|
import com.badlogic.gdx.utils.Timer.Task;
|
||||||
|
|
||||||
@ -33,15 +34,12 @@ import org.oscim.map.Map;
|
|||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.theme.VtmThemes;
|
import org.oscim.theme.VtmThemes;
|
||||||
import org.oscim.tiling.TileSource;
|
import org.oscim.tiling.TileSource;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public abstract class GdxMap implements ApplicationListener {
|
public abstract class GdxMap implements ApplicationListener {
|
||||||
final static Logger log = LoggerFactory.getLogger(GdxMap.class);
|
|
||||||
|
|
||||||
protected Map mMap;
|
protected Map mMap;
|
||||||
|
protected GestureDetector mGestureDetector;
|
||||||
|
|
||||||
VectorTileLayer mMapLayer;
|
|
||||||
private MapRenderer mMapRenderer;
|
private MapRenderer mMapRenderer;
|
||||||
|
|
||||||
public GdxMap() {
|
public GdxMap() {
|
||||||
@ -52,14 +50,14 @@ public abstract class GdxMap implements ApplicationListener {
|
|||||||
Layers layers = mMap.layers();
|
Layers layers = mMap.layers();
|
||||||
|
|
||||||
if (tileSource != null) {
|
if (tileSource != null) {
|
||||||
mMapLayer = mMap.setBaseMap(tileSource);
|
VectorTileLayer mapLayer = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.DEFAULT);
|
mMap.setTheme(VtmThemes.DEFAULT);
|
||||||
|
|
||||||
if (buildings)
|
if (buildings)
|
||||||
layers.add(new BuildingLayer(mMap, mMapLayer));
|
layers.add(new BuildingLayer(mMap, mapLayer));
|
||||||
|
|
||||||
if (labels)
|
if (labels)
|
||||||
layers.add(new LabelLayer(mMap, mMapLayer));
|
layers.add(new LabelLayer(mMap, mapLayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileGrid)
|
if (tileGrid)
|
||||||
@ -82,6 +80,8 @@ public abstract class GdxMap implements ApplicationListener {
|
|||||||
mMapRenderer.onSurfaceChanged(w, h);
|
mMapRenderer.onSurfaceChanged(w, h);
|
||||||
|
|
||||||
InputMultiplexer mux = new InputMultiplexer();
|
InputMultiplexer mux = new InputMultiplexer();
|
||||||
|
mGestureDetector = new GestureDetector(new LayerHandler(mMap));
|
||||||
|
mux.addProcessor(mGestureDetector);
|
||||||
mux.addProcessor(new InputHandler(this));
|
mux.addProcessor(new InputHandler(this));
|
||||||
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
|
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
|
||||||
// new MapController(mMap)));
|
// new MapController(mMap)));
|
||||||
|
76
vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
Normal file
76
vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 devemux86
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.oscim.gdx;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
|
||||||
|
import org.oscim.event.MotionEvent;
|
||||||
|
|
||||||
|
public class GdxMotionEvent extends MotionEvent {
|
||||||
|
|
||||||
|
private final int action;
|
||||||
|
private final float x, y;
|
||||||
|
private final int button;
|
||||||
|
|
||||||
|
public GdxMotionEvent(int action, float x, float y) {
|
||||||
|
this(action, x, y, Input.Buttons.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GdxMotionEvent(int action, float x, float y, int button) {
|
||||||
|
this.action = action;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.button = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getButton() {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPointerCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getTime() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getX(int idx) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getY(int idx) {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
42
vtm-gdx/src/org/oscim/gdx/LayerHandler.java
Normal file
42
vtm-gdx/src/org/oscim/gdx/LayerHandler.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 devemux86
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.oscim.gdx;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.input.GestureDetector;
|
||||||
|
|
||||||
|
import org.oscim.event.Gesture;
|
||||||
|
import org.oscim.event.MotionEvent;
|
||||||
|
import org.oscim.map.Map;
|
||||||
|
|
||||||
|
public class LayerHandler extends GestureDetector.GestureAdapter {
|
||||||
|
|
||||||
|
private final Map map;
|
||||||
|
|
||||||
|
public LayerHandler(Map map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean longPress(float x, float y) {
|
||||||
|
map.handleGesture(Gesture.LONG_PRESS, new GdxMotionEvent(MotionEvent.ACTION_DOWN, x, y));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tap(float x, float y, int count, int button) {
|
||||||
|
map.handleGesture(Gesture.TAP, new GdxMotionEvent(MotionEvent.ACTION_UP, x, y, button));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user