Skip to content

Commit

Permalink
Make drawing tools delete function one click
Browse files Browse the repository at this point in the history
  • Loading branch information
gdalcengio authored and micheal-w-wells committed Dec 1, 2023
1 parent 2055b0d commit f09b766
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 19 additions & 1 deletion appv2/src/UI/Map/ActivityGeo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import '@geoman-io/leaflet-geoman-free';
import '@geoman-io/leaflet-geoman-free/dist/leaflet-geoman.css';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ACTIVITY_UPDATE_GEO_REQUEST } from 'state/actions';
import { ACTIVITY_TOGGLE_NOTIFICATION_SUCCESS, ACTIVITY_UPDATE_GEO_REQUEST } from 'state/actions';
import { GeoJSON, useMap, useMapEvent } from 'react-leaflet';
import type { LayerGroup } from 'leaflet';

export const GeoEditTools = (props) => {
const { map, layerContainer } = useLeafletContext();
const container = (layerContainer as LayerGroup) || map;
const dispatch = useDispatch();

if (!container) {
console.warn('[GEOMAN-CONTROLS] No map or container instance found');
Expand All @@ -28,6 +29,23 @@ export const GeoEditTools = (props) => {
cutPolygon: false,
rotateMode: false
});

// Set up remove button listener workaround
const removeButton = document.getElementsByClassName("leaflet-pm-icon-delete")[0];
removeButton.addEventListener("click", () => {
map?.pm?.toggleGlobalRemovalMode();
dispatch({ type: ACTIVITY_UPDATE_GEO_REQUEST, payload: { geometry: [] } });
dispatch({
type: ACTIVITY_TOGGLE_NOTIFICATION_SUCCESS,
payload: {
notification: {
visible: true,
message: 'Geometry Removed',
severity: 'success'
}
}
});
});
};

useEffect(() => {
Expand Down
15 changes: 14 additions & 1 deletion appv2/src/state/sagas/activity/dataAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,20 @@ export function* handle_ACTIVITY_UPDATE_GEO_REQUEST(action) {
if (latitude && longitude) utm = calc_utm(longitude, latitude);
const reported_area = calculateGeometryArea(action.payload.geometry);


if (action.payload.geometry.length < 1) {
yield put({
type: ACTIVITY_UPDATE_GEO_SUCCESS,
payload: {
geometry: action.payload.geometry,
utm: utm,
lat: latitude,
long: longitude,
reported_area: reported_area,
Well_Information: []
}
});
return;
}

const isPointGeometry = action.payload.geometry[0].geometry.type === 'Point';
if (!isPointGeometry) {
Expand Down

0 comments on commit f09b766

Please sign in to comment.