Skip to content

Commit

Permalink
libGDX layer gestures, closes opensciencemap#151
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Aug 23, 2016
1 parent 46f4d59 commit ebd0795
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
- Mapsforge multilingual maps [#34](https://github.com/mapsforge/vtm/issues/34)
- 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)
- 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)
- 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)
- 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)
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
- vtm-jts module [#53](https://github.com/mapsforge/vtm/issues/53)
Expand Down
14 changes: 7 additions & 7 deletions vtm-gdx/src/org/oscim/gdx/GdxMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;

Expand All @@ -33,15 +34,12 @@
import org.oscim.renderer.MapRenderer;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.TileSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GdxMap implements ApplicationListener {
final static Logger log = LoggerFactory.getLogger(GdxMap.class);

protected Map mMap;
protected GestureDetector mGestureDetector;

VectorTileLayer mMapLayer;
private MapRenderer mMapRenderer;

public GdxMap() {
Expand All @@ -52,14 +50,14 @@ protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolea
Layers layers = mMap.layers();

if (tileSource != null) {
mMapLayer = mMap.setBaseMap(tileSource);
VectorTileLayer mapLayer = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.DEFAULT);

if (buildings)
layers.add(new BuildingLayer(mMap, mMapLayer));
layers.add(new BuildingLayer(mMap, mapLayer));

if (labels)
layers.add(new LabelLayer(mMap, mMapLayer));
layers.add(new LabelLayer(mMap, mapLayer));
}

if (tileGrid)
Expand All @@ -82,6 +80,8 @@ public void create() {
mMapRenderer.onSurfaceChanged(w, h);

InputMultiplexer mux = new InputMultiplexer();
mGestureDetector = new GestureDetector(new LayerHandler(mMap));
mux.addProcessor(mGestureDetector);
mux.addProcessor(new InputHandler(this));
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
// new MapController(mMap)));
Expand Down
76 changes: 76 additions & 0 deletions vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
Original file line number Diff line number Diff line change
@@ -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 changes: 42 additions & 0 deletions vtm-gdx/src/org/oscim/gdx/LayerHandler.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit ebd0795

Please sign in to comment.