diff --git a/frontend/src/pages/Properties/PropertyDetail.js b/frontend/src/pages/Properties/PropertyDetail.js
index b52cae3..c7e2b47 100644
--- a/frontend/src/pages/Properties/PropertyDetail.js
+++ b/frontend/src/pages/Properties/PropertyDetail.js
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
-import { MapContainer, TileLayer, Marker, Popup, Polygon, useMapEvents } from 'react-leaflet';
+import { MapContainer, TileLayer, Marker, Popup, Polygon, useMapEvents, useMap } from 'react-leaflet';
import { Icon } from 'leaflet';
import * as turf from '@turf/turf';
import {
@@ -88,6 +88,141 @@ function PolygonDrawer({ isDrawing, onPolygonComplete, currentColor }) {
) : null;
}
+// Component for editable polygons
+function EditablePolygon({ section, onUpdate, onEdit, onDelete }) {
+ // Import toast function from the module scope
+ const [isEditing, setIsEditing] = useState(false);
+ const [editedCoordinates, setEditedCoordinates] = useState(section.coordinates);
+ const map = useMap();
+
+ const handleMarkerDrag = (index, newLatLng) => {
+ const newCoords = [...editedCoordinates];
+ newCoords[index] = [newLatLng.lat, newLatLng.lng];
+ setEditedCoordinates(newCoords);
+
+ // Recalculate area
+ const area = calculateAreaInSqFt([...newCoords, newCoords[0]]);
+ onUpdate(section.id, { ...section, coordinates: newCoords, area });
+ };
+
+ const addPointAtIndex = (index, e) => {
+ e.originalEvent.stopPropagation();
+ const newCoords = [...editedCoordinates];
+ const newPoint = [e.latlng.lat, e.latlng.lng];
+ newCoords.splice(index + 1, 0, newPoint);
+ setEditedCoordinates(newCoords);
+
+ const area = calculateAreaInSqFt([...newCoords, newCoords[0]]);
+ onUpdate(section.id, { ...section, coordinates: newCoords, area });
+ };
+
+ const removePoint = (index) => {
+ if (editedCoordinates.length <= 3) {
+ toast.error('Polygon must have at least 3 points');
+ return;
+ }
+ const newCoords = editedCoordinates.filter((_, i) => i !== index);
+ setEditedCoordinates(newCoords);
+
+ const area = calculateAreaInSqFt([...newCoords, newCoords[0]]);
+ onUpdate(section.id, { ...section, coordinates: newCoords, area });
+ };
+
+ return (
+ <>
+ Point {index + 1}
+ {section.area.toLocaleString()} sq ft
+
Need at least 3 points to create a section. Press ESC to cancel.
++ 💡 After creating: Click any polygon to edit its points by dragging +