private double abs(Coordinate c) { return MathService.distance(c, new Coordinate()); }
/** * Is the event at the same location as the "down" event? * * @param event * The event to check. * @return true or false. */ private boolean isDownPosition(HumanInputEvent<?> event) { if (onDownLocation != null) { Coordinate location = getLocation(event, RenderSpace.SCREEN); if (MathService.distance(onDownLocation, location) < clickDelta) { return true; } } return false; }
/** * Transform a pixel-length into a real-life distance expressed in map CRS. This depends on the current map scale. * * @param pixels * The number of pixels to calculate the distance for. * @return The distance the given number of pixels entails. */ private double pixelsToUnits(int pixels) { Coordinate c1 = mapPresenter.getViewPort().transform(new Coordinate(0, 0), RenderSpace.SCREEN, RenderSpace.WORLD); Coordinate c2 = mapPresenter.getViewPort().transform(new Coordinate(pixels, 0), RenderSpace.SCREEN, RenderSpace.WORLD); return MathService.distance(c1, c2); }
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 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(); }