Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public void updateSource() {
mapView.post(() -> {
isSourceUpToDate.set(true);

enableDragIfNeeded();

if (!style.isFullyLoaded()) {
// We are in progress of loading a new style
return;
Expand Down Expand Up @@ -398,6 +400,19 @@ private void initializeSourcesAndLayers(GeoJsonOptions geoJsonOptions) {
updateSource();
}

private void enableDragIfNeeded(){
boolean hasDraggableAnnotation = false;
for (int i = 0, size = annotations.size(); i < size; i++) {
Annotation annotation = annotations.valueAt(i);

if (annotation.isDraggable()) {
hasDraggableAnnotation=true;
break;
}
}
draggableAnnotationController.setEnable(hasDraggableAnnotation);
}

/**
* Inner class for transforming map click events into annotation clicks
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import android.annotation.SuppressLint;
import android.graphics.PointF;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;

import org.maplibre.android.gestures.AndroidGesturesManager;
import org.maplibre.android.gestures.MoveDistancesObject;
import org.maplibre.android.gestures.MoveGestureDetector;
Expand Down Expand Up @@ -54,6 +54,8 @@ private static void clearInstance() {
@Nullable
private AnnotationManager draggedAnnotationManager;

private AndroidGesturesManager androidGesturesManager;

@SuppressLint("ClickableViewAccessibility")
DraggableAnnotationController(MapView mapView, MapLibreMap maplibreMap) {
this(mapView, maplibreMap, new AndroidGesturesManager(mapView.getContext(), false),
Expand All @@ -72,18 +74,25 @@ public DraggableAnnotationController(MapView mapView, MapLibreMap maplibreMap,
this.touchAreaMaxX = touchAreaMaxX;
this.touchAreaMaxY = touchAreaMaxY;

androidGesturesManager.setMoveGestureListener(new AnnotationMoveGestureListener());
this.androidGesturesManager = androidGesturesManager;
}

void setEnable(boolean enable) {
if (enable) {
androidGesturesManager.setMoveGestureListener(new AnnotationMoveGestureListener());

mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mapView.setOnTouchListener((v, event) -> {
// Using active gesture manager
Annotation oldAnnotation = draggedAnnotation;
androidGesturesManager.onTouchEvent(event);
// if drag is started or drag is finished, don't pass motion events further
return draggedAnnotation != null || oldAnnotation != null;
}
});
boolean t = draggedAnnotation != null || oldAnnotation != null;
return t;
});
} else {
androidGesturesManager.removeMoveGestureListener();
mapView.setOnTouchListener(null);
Comment thread
louwers marked this conversation as resolved.
}
}

void addAnnotationManager(AnnotationManager annotationManager) {
Expand Down