@Override public Coordinate getLocation(HumanInputEvent<?> event, RenderSpace renderSpace) { switch (renderSpace) { case WORLD: Coordinate screen = getLocation(event, RenderSpace.SCREEN); return mapWidget.getMapModel().getMapView().getWorldViewTransformer().viewToWorld(screen); case SCREEN: default: if (event instanceof MouseEvent<?>) { Element element = mapWidget.getDOM(); double offsetX = ((MouseEvent<?>) event).getRelativeX(element); double offsetY = ((MouseEvent<?>) event).getRelativeY(element); return new Coordinate(offsetX, offsetY); } else if (event instanceof TouchEvent<?>) { Touch touch = ((TouchEvent<?>) event).getTouches().get(0); return new Coordinate(touch.getClientX(), touch.getClientY()); } return new Coordinate(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); } }
public void onMapTouchMove(TouchEvent<?> event) { if (event.getTouches().length() == 2 && zooming) { Coordinate p1 = getWorldLocation(event.getTouches().get(0), RenderSpace.WORLD); Coordinate p2 = getWorldLocation(event.getTouches().get(1), RenderSpace.WORLD); double scale = MathService.distance(p1, p2) / startDist; Coordinate newCenter = getCenter(p1, p2); double dx = startCenter.getX() - newCenter.getX(); double dy = startCenter.getY() - newCenter.getY(); double resolution = mapPresenter.getViewPort().getResolution() / scale; Coordinate position = calculatePosition(scale, startCenter); View view = new View(new Coordinate(position.getX() + dx, position.getY() + dy), resolution); view.setInteractive(true); mapPresenter.getViewPort().applyView(view); } else { onDrag(event); } event.preventDefault(); event.stopPropagation(); }
private int getAbsoluteX(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientX()+Window.getScrollLeft(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientX()+Window.getScrollLeft(); } return 0; }
private int getAbsoluteY(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientY()+ Window.getScrollTop(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientY() + Window.getScrollTop(); } return 0; }
private static Point getPoint(EventHandlingTarget drawPanelCanvas, HumanInputEvent<?> event) { Element e = drawPanelCanvas.getElement(); if (event instanceof MouseEvent<?>) { return new Point(((MouseEvent<?>) event).getRelativeX(e), ((MouseEvent<?>) event).getRelativeY(e)); } else if (event instanceof TouchEndEvent) { return new Point(((TouchEvent<?>) event).getChangedTouches().get(0).getRelativeX(e), ((TouchEvent<?>) event).getChangedTouches().get(0).getRelativeY(e)); } else if (event instanceof TouchEvent<?>) { return new Point(((TouchEvent<?>) event).getTouches().get(0).getRelativeX(e), ((TouchEvent<?>) event).getTouches().get(0).getRelativeY(e)); } else { throw new RuntimeException("Unknown Event Type: " + event); } }
private static Point getPointAbsolute(HumanInputEvent<?> event) { if (event instanceof MouseEvent<?>) { return new Point(((MouseEvent<?>) event).getClientX(), ((MouseEvent<?>) event).getClientY()); } else if (event instanceof TouchEndEvent) { return new Point(((TouchEvent<?>) event).getChangedTouches().get(0).getPageX(), ((TouchEvent<?>) event).getChangedTouches().get(0).getPageY()); } else if (event instanceof TouchEvent<?>) { return new Point(((TouchEvent<?>) event).getTouches().get(0).getPageX(), ((TouchEvent<?>) event).getTouches().get(0).getPageY()); } else { throw new RuntimeException("Unknown Event Type: " + event); } }
private void setColour(TouchEvent event, Canvas targetCanvas, VerticalPanel targetPanel) { if (event.getTouches().length() > 0) { final JsArray<Touch> touches = event.getTargetTouches(); if (touches.length() > 0) { Touch touch = touches.get(0); setColour(touch.getRelativeX(targetCanvas.getElement()), touch.getRelativeY(targetCanvas.getElement()), targetCanvas, targetPanel); } } }
private void setHue(TouchEvent event, Canvas targetCanvas) { if (event.getTouches().length() > 0) { final JsArray<Touch> touches = event.getTargetTouches(); if (touches.length() > 0) { Touch touch = touches.get(0); setHue(touch.getRelativeX(targetCanvas.getElement()), touch.getRelativeY(targetCanvas.getElement()), targetCanvas); } } }
public void onMapTouchStart(TouchEvent<?> event) { if (event.getTouches().length() == 2) { Coordinate p1 = getWorldLocation(event.getTouches().get(0), RenderSpace.WORLD); Coordinate p2 = getWorldLocation(event.getTouches().get(1), RenderSpace.WORLD); startCenter = getCenter(p1, p2); startDist = MathService.distance(p1, p2); stopPanning(null); this.zooming = true; } else { onDown(event); } event.preventDefault(); event.stopPropagation(); }
public void onMapTouchEnd(TouchEvent<?> event) { if (zooming) { if (event.getTouches().length() == 0) { zooming = false; } mapPresenter.getViewPort().stopInteraction(); } else { onUp(event); } event.preventDefault(); event.stopPropagation(); }
/** * Forward as mouse down and stop the event. * @since 2.4.0 */ @Override public void onMapTouchStart(TouchEvent<?> event) { onDown(event); event.stopPropagation(); event.preventDefault(); }
/** * Forward as mouse move and stop the event. * @since 2.4.0 */ @Override public void onMapTouchMove(TouchEvent<?> event) { onDrag(event); event.stopPropagation(); event.preventDefault(); }
/** * Forward as mouse up and stop the event. * @since 2.4.0 */ @Override public void onMapTouchEnd(TouchEvent<?> event) { onUp(event); event.stopPropagation(); event.preventDefault(); }
/** * Forward as mouse up and stop the event. * @since 2.4.0 */ @Override public void onMapTouchCancel(TouchEvent<?> event) { onUp(event); event.stopPropagation(); event.preventDefault(); }
private void addHandlers() { addDomHandler(this, KeyUpEvent.getType()); if (TouchEvent.isSupported()) { addDomHandler(this, TouchStartEvent.getType()); addDomHandler(this, TouchMoveEvent.getType()); addDomHandler(this, TouchEndEvent.getType()); addDomHandler(this, TouchCancelEvent.getType()); } else { addDomHandler(this, MouseDownEvent.getType()); addDomHandler(this, MouseUpEvent.getType()); addDomHandler(this, MouseMoveEvent.getType()); } addDomHandler(this, FocusEvent.getType()); addDomHandler(this, BlurEvent.getType()); }
public TouchOnImageEvent getTouchOnImageEvent(TouchEvent<? extends EventHandler> touchEvent) { List<Point> pointsList = getPoints(touchEvent); return new TouchOnImageEvent(pointsList); }
private List<Point> getPoints(TouchEvent<? extends EventHandler> touchEvent) { JsArray<Touch> touches = touchEvent.getTouches(); JsArrayIterable<Touch> iterableTouches = JsArrayIterable.create(touches); return FluentIterable.from(iterableTouches).transform(touchToPointTransforemer).toList(); }
public void onMapTouchCancel(TouchEvent<?> event) { onMapTouchEnd(event); }
void onMapTouchStart(TouchEvent<?> event);
void onMapTouchMove(TouchEvent<?> event);
void onMapTouchEnd(TouchEvent<?> event);
void onMapTouchCancel(TouchEvent<?> event);