GDX double tap zoom, closes #263

This commit is contained in:
Emux 2016-12-02 10:48:55 +02:00
parent c21d7b4390
commit 0a92c84668
3 changed files with 18 additions and 3 deletions

View File

@ -11,6 +11,7 @@
- House numbers (nodes) fix visibility [#168](https://github.com/mapsforge/vtm/issues/168) - House numbers (nodes) fix visibility [#168](https://github.com/mapsforge/vtm/issues/168)
- Android fix quick scale vs long press [#250](https://github.com/mapsforge/vtm/issues/250) - Android fix quick scale vs long press [#250](https://github.com/mapsforge/vtm/issues/250)
- Use baseline 160dpi in scaling [#236](https://github.com/mapsforge/vtm/issues/236) - Use baseline 160dpi in scaling [#236](https://github.com/mapsforge/vtm/issues/236)
- libGDX double tap zoom [#263](https://github.com/mapsforge/vtm/issues/263)
- MapFileTileSource zoom level API enhancements [#219](https://github.com/mapsforge/vtm/issues/219) - MapFileTileSource zoom level API enhancements [#219](https://github.com/mapsforge/vtm/issues/219)
- Animator enhancements with easing functions [#246](https://github.com/mapsforge/vtm/issues/246) - Animator enhancements with easing functions [#246](https://github.com/mapsforge/vtm/issues/246)
- Tile grid layer scaling [#238](https://github.com/mapsforge/vtm/issues/238) - Tile grid layer scaling [#238](https://github.com/mapsforge/vtm/issues/238)

View File

@ -86,7 +86,7 @@ public abstract class GdxMap implements ApplicationListener {
InputMultiplexer mux = new InputMultiplexer(); InputMultiplexer mux = new InputMultiplexer();
if (!Map.NEW_GESTURES) { if (!Map.NEW_GESTURES) {
mGestureDetector = new GestureDetector(new LayerHandler(mMap)); mGestureDetector = new GestureDetector(new GestureHandlerImpl(mMap));
mux.addProcessor(mGestureDetector); mux.addProcessor(mGestureDetector);
} }
mux.addProcessor(new InputHandler(this)); mux.addProcessor(new InputHandler(this));

View File

@ -14,28 +14,42 @@
*/ */
package org.oscim.gdx; package org.oscim.gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.input.GestureDetector; import com.badlogic.gdx.input.GestureDetector;
import org.oscim.event.Gesture; import org.oscim.event.Gesture;
import org.oscim.event.MotionEvent; import org.oscim.event.MotionEvent;
import org.oscim.map.Map; import org.oscim.map.Map;
public class LayerHandler extends GestureDetector.GestureAdapter { public class GestureHandlerImpl extends GestureDetector.GestureAdapter {
private final Map map; private final Map map;
public LayerHandler(Map map) { public GestureHandlerImpl(Map map) {
this.map = map; this.map = map;
} }
@Override @Override
public boolean longPress(float x, float y) { public boolean longPress(float x, float y) {
// Handle gesture on layers
map.handleGesture(Gesture.LONG_PRESS, new GdxMotionEvent(MotionEvent.ACTION_DOWN, x, y)); map.handleGesture(Gesture.LONG_PRESS, new GdxMotionEvent(MotionEvent.ACTION_DOWN, x, y));
return true; return true;
} }
@Override @Override
public boolean tap(float x, float y, int count, int button) { public boolean tap(float x, float y, int count, int button) {
// Handle double tap zoom
if (button == Input.Buttons.LEFT) {
if (count == 2) {
float pivotX = x - map.getWidth() / 2;
float pivotY = y - map.getHeight() / 2;
map.animator().animateZoom(300, 2, pivotX, pivotY);
map.updateMap(true);
return false;
}
}
// Handle gesture on layers
map.handleGesture(Gesture.TAP, new GdxMotionEvent(MotionEvent.ACTION_UP, x, y, button)); map.handleGesture(Gesture.TAP, new GdxMotionEvent(MotionEvent.ACTION_UP, x, y, button));
return false; return false;
} }