From aba68f28c9b56010a58a04dc54e8c12dc2a5b4ab Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 28 Sep 2020 18:28:53 +0300 Subject: [PATCH] Add editBoundaryMode on DrawingManager - This disables drawing outside the boundary - This also adds an editBoundary method that enables the mode --- .../io/ona/kujaku/manager/DrawingManager.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/library/src/main/java/io/ona/kujaku/manager/DrawingManager.java b/library/src/main/java/io/ona/kujaku/manager/DrawingManager.java index fc394b58..1f1e23bb 100644 --- a/library/src/main/java/io/ona/kujaku/manager/DrawingManager.java +++ b/library/src/main/java/io/ona/kujaku/manager/DrawingManager.java @@ -57,6 +57,7 @@ public class DrawingManager { private boolean drawingEnabled; private FillBoundaryLayer currentFillBoundaryLayer; + private boolean editBoundaryMode; /** * Constructor @@ -110,18 +111,21 @@ public void onAnnotationDragFinished(Circle circle) { mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { @Override public boolean onMapClick(@NonNull LatLng point) { - final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); - List features = mapboxMap.queryRenderedFeatures(pixel, (Expression) null, CircleManager.ID_GEOJSON_LAYER); - if (features.size() == 0 && drawingEnabled) { - if (getCurrentKujakuCircle() != null) { - unsetCurrentCircleDraggable(); - } else { - drawCircle(point); - } + if (!editBoundaryMode) { + final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); + List features = mapboxMap.queryRenderedFeatures(pixel, (Expression) null, CircleManager.ID_GEOJSON_LAYER); - if (onDrawingCircleClickListener != null) { - onDrawingCircleClickListener.onCircleNotClick(point); + if (features.size() == 0 && drawingEnabled) { + if (getCurrentKujakuCircle() != null) { + unsetCurrentCircleDraggable(); + } else { + drawCircle(point); + } + + if (onDrawingCircleClickListener != null) { + onDrawingCircleClickListener.onCircleNotClick(point); + } } } @@ -234,6 +238,11 @@ public boolean startDrawing(@Nullable FillBoundaryLayer fillBoundaryLayer) { return false; } + public boolean editBoundary(@NonNull FillBoundaryLayer fillBoundaryLayer) { + editBoundaryMode = true; + return startDrawing(fillBoundaryLayer); + } + /** * Start Drawing. A list of point can be passed to init the drawing. *