Search in sources :

Example 1 with MoveDistancesObject

use of com.mapbox.android.gestures.MoveDistancesObject in project mapbox-plugins-android by mapbox.

the class DraggableAnnotationController method onMove.

boolean onMove(MoveGestureDetector detector) {
    if (draggedAnnotation != null && (detector.getPointersCount() > 1 || !draggedAnnotation.isDraggable())) {
        // Stopping the drag when we don't work with a simple, on-pointer move anymore
        stopDragging(draggedAnnotation, draggedAnnotationManager);
        return true;
    }
    // Updating symbol's position
    if (draggedAnnotation != null) {
        MoveDistancesObject moveObject = detector.getMoveObject(0);
        float x = moveObject.getCurrentX() - touchAreaShiftX;
        float y = moveObject.getCurrentY() - touchAreaShiftY;
        PointF pointF = new PointF(x, y);
        if (pointF.x < 0 || pointF.y < 0 || pointF.x > touchAreaMaxX || pointF.y > touchAreaMaxY) {
            stopDragging(draggedAnnotation, draggedAnnotationManager);
            return true;
        }
        Geometry shiftedGeometry = draggedAnnotation.getOffsetGeometry(mapboxMap.getProjection(), moveObject, touchAreaShiftX, touchAreaShiftY);
        if (shiftedGeometry != null) {
            draggedAnnotation.setGeometry(shiftedGeometry);
            draggedAnnotationManager.internalUpdateSource();
            for (OnAnnotationDragListener d : (List<OnAnnotationDragListener>) draggedAnnotationManager.getDragListeners()) {
                d.onAnnotationDrag(draggedAnnotation);
            }
            return true;
        }
    }
    return false;
}
Also used : Geometry(com.mapbox.geojson.Geometry) MoveDistancesObject(com.mapbox.android.gestures.MoveDistancesObject) PointF(android.graphics.PointF) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

PointF (android.graphics.PointF)1 MoveDistancesObject (com.mapbox.android.gestures.MoveDistancesObject)1 Geometry (com.mapbox.geojson.Geometry)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1