@burdenoff/microfe-healthybowl 2026.710.7 → 2026.710.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/healthybowl/components/FieldMap.js +37 -32
- package/dist/healthybowl/components/FieldMap.js.map +1 -1
- package/dist/healthybowl/components/WeatherMap.js +34 -34
- package/dist/healthybowl/components/WeatherMap.js.map +1 -1
- package/dist/healthybowl/context/HealthyBowlContext.js +21 -19
- package/dist/healthybowl/context/HealthyBowlContext.js.map +1 -1
- package/dist/healthybowl/pages/weather/WeatherOverviewPage.js +30 -30
- package/dist/healthybowl/pages/weather/WeatherOverviewPage.js.map +1 -1
- package/dist/healthybowl/utils/geocode.js +50 -11
- package/dist/healthybowl/utils/geocode.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __toESM as e } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { geocodePlace as t } from "../utils/geocode.js";
|
|
3
|
+
import { useHealthyBowl as n } from "../context/HealthyBowlContext.js";
|
|
4
|
+
import { ToastContainer as r } from "./Toast.js";
|
|
5
|
+
import { require_leaflet_src as i } from "../../node_modules/leaflet/dist/leaflet-src.js";
|
|
6
6
|
import { useToast as a } from "../hooks/useToast.js";
|
|
7
7
|
import { ensureLeafletCss as ee } from "../utils/leaflet.js";
|
|
8
8
|
import { extractPolygon as o, isValidPolygon as te, polygonAreaInUnit as s, ringToPolygon as ne } from "../utils/geo.js";
|
|
@@ -14,7 +14,7 @@ import { Button as g } from "@burdenoff/fe-libs/ui";
|
|
|
14
14
|
import { gql as _ } from "@apollo/client";
|
|
15
15
|
import { useMutation as pe } from "@apollo/client/react";
|
|
16
16
|
//#region src/healthybowl/components/FieldMap.tsx
|
|
17
|
-
var v = /* @__PURE__ */ e(
|
|
17
|
+
var v = /* @__PURE__ */ e(i(), 1), me = _`
|
|
18
18
|
mutation UpdateHealthyBowlFieldBoundary($input: UpdateHealthyBowlFieldInput!) {
|
|
19
19
|
updateHealthyBowlField(input: $input) {
|
|
20
20
|
id
|
|
@@ -46,8 +46,8 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
46
46
|
lng: r,
|
|
47
47
|
label: `${n.toFixed(6)}, ${r.toFixed(6)}`
|
|
48
48
|
} : null;
|
|
49
|
-
}, Te = ({ fieldId: e, unit:
|
|
50
|
-
let { t: b } = re(), { workspaceId: x } =
|
|
49
|
+
}, Te = ({ fieldId: e, unit: i, center: _, initialBoundary: Te, onSaved: Ee, onAreaChange: De }) => {
|
|
50
|
+
let { t: b } = re(), { workspaceId: x } = n(), { toasts: Oe, toast: S, dismiss: ke } = a(), C = u(null), w = u(null), T = u(null), E = u(null), D = u(null), O = u(null), k = u(null), A = u(null), j = u(_ ?? null), M = u([]), N = u([]), P = u(null), F = u("view"), [I, Ae] = d("loading"), [L, R] = d("view"), [z, je] = d(!1), [B, Me] = d(null), [Ne, Pe] = d(0), [Fe, V] = d(!1), [Ie, H] = d(!1), [Le, Re] = d(!1), [ze, U] = d(!1), [W, Be] = d(""), [G, Ve] = d(!1), [K, q] = d(null), He = Fe || Ie, [Ue] = pe(me);
|
|
51
51
|
l(() => {
|
|
52
52
|
j.current = _ ?? null;
|
|
53
53
|
}, [_]), l(() => {
|
|
@@ -60,14 +60,14 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
60
60
|
let n = T.current;
|
|
61
61
|
if (!n) return;
|
|
62
62
|
E.current && n.removeLayer(E.current);
|
|
63
|
-
let
|
|
64
|
-
if (E.current =
|
|
65
|
-
n.fitBounds(
|
|
63
|
+
let r = v.default.geoJSON(e, { style: () => be }).addTo(n);
|
|
64
|
+
if (E.current = r, P.current = e, je(!0), Me(s(e, i)), t) try {
|
|
65
|
+
n.fitBounds(r.getBounds(), {
|
|
66
66
|
padding: [24, 24],
|
|
67
67
|
maxZoom: 18
|
|
68
68
|
});
|
|
69
69
|
} catch {}
|
|
70
|
-
}, [
|
|
70
|
+
}, [i]), X = c(() => {
|
|
71
71
|
let e = T.current;
|
|
72
72
|
E.current && e && e.removeLayer(E.current), E.current = null, P.current = null, je(!1), Me(null);
|
|
73
73
|
}, []), Z = c(() => {
|
|
@@ -167,8 +167,8 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
167
167
|
S
|
|
168
168
|
]), qe = c(async (e) => {
|
|
169
169
|
e.preventDefault();
|
|
170
|
-
let
|
|
171
|
-
if (!
|
|
170
|
+
let n = W.trim();
|
|
171
|
+
if (!n) {
|
|
172
172
|
S({
|
|
173
173
|
title: b("healthybowl.fieldMap.toast.searchRequired.title", "Place required"),
|
|
174
174
|
description: b("healthybowl.fieldMap.toast.searchRequired.description", "Enter a village, city, region, or coordinates."),
|
|
@@ -176,14 +176,14 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
176
176
|
});
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
-
let
|
|
180
|
-
if (
|
|
181
|
-
Q(
|
|
179
|
+
let r = we(n);
|
|
180
|
+
if (r) {
|
|
181
|
+
Q(r);
|
|
182
182
|
return;
|
|
183
183
|
}
|
|
184
184
|
Ve(!0);
|
|
185
185
|
try {
|
|
186
|
-
let e = await
|
|
186
|
+
let e = await t(n);
|
|
187
187
|
if (!e) {
|
|
188
188
|
S({
|
|
189
189
|
title: b("healthybowl.fieldMap.toast.searchNotFound.title", "Place not found"),
|
|
@@ -192,15 +192,15 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
192
192
|
});
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
let
|
|
195
|
+
let r = [
|
|
196
196
|
e.name,
|
|
197
197
|
e.admin1,
|
|
198
198
|
e.country
|
|
199
|
-
].filter(Boolean).join(", ") ||
|
|
199
|
+
].filter(Boolean).join(", ") || n;
|
|
200
200
|
Q({
|
|
201
201
|
lat: e.latitude,
|
|
202
202
|
lng: e.longitude,
|
|
203
|
-
label:
|
|
203
|
+
label: r
|
|
204
204
|
});
|
|
205
205
|
} catch (e) {
|
|
206
206
|
S({
|
|
@@ -293,7 +293,7 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
293
293
|
]), et = c(async () => {
|
|
294
294
|
Re(!0);
|
|
295
295
|
try {
|
|
296
|
-
let t = P.current, n = t ? s(t,
|
|
296
|
+
let t = P.current, n = t ? s(t, i) : void 0, r = K ? {
|
|
297
297
|
lat: K.lat,
|
|
298
298
|
lng: K.lng
|
|
299
299
|
} : void 0;
|
|
@@ -301,13 +301,13 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
301
301
|
id: e,
|
|
302
302
|
boundary: t,
|
|
303
303
|
...n == null ? {} : { area: n },
|
|
304
|
-
...
|
|
304
|
+
...r ? { location: r } : {},
|
|
305
305
|
context: { workspaceId: x }
|
|
306
|
-
} } }),
|
|
306
|
+
} } }), r && (j.current = r), V(!1), H(!1), q(null), Ee?.(), S({
|
|
307
307
|
title: b("healthybowl.fieldMap.toast.saved.title", "Map saved"),
|
|
308
|
-
description:
|
|
308
|
+
description: r ? b("healthybowl.fieldMap.toast.savedLocation.description", "Field GPS location updated.") : t ? b("healthybowl.fieldMap.toast.saved.description", "Field area updated to {{area}} {{unit}}.", {
|
|
309
309
|
area: String(n ?? ""),
|
|
310
|
-
unit:
|
|
310
|
+
unit: i
|
|
311
311
|
}) : b("healthybowl.fieldMap.toast.savedCleared.description", "Boundary removed from this field."),
|
|
312
312
|
variant: "success"
|
|
313
313
|
});
|
|
@@ -326,7 +326,7 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
326
326
|
K,
|
|
327
327
|
b,
|
|
328
328
|
S,
|
|
329
|
-
|
|
329
|
+
i,
|
|
330
330
|
Ue,
|
|
331
331
|
x
|
|
332
332
|
]);
|
|
@@ -336,21 +336,26 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
336
336
|
ee();
|
|
337
337
|
let t = v.default.tileLayer(he, {
|
|
338
338
|
attribution: ge,
|
|
339
|
-
maxZoom:
|
|
339
|
+
maxZoom: 21,
|
|
340
|
+
maxNativeZoom: 18
|
|
340
341
|
}), n = v.default.tileLayer(_e, {
|
|
341
342
|
attribution: ve,
|
|
342
|
-
maxZoom:
|
|
343
|
+
maxZoom: 21,
|
|
344
|
+
maxNativeZoom: 17
|
|
343
345
|
}), r = v.default.tileLayer(_e, {
|
|
344
346
|
attribution: ve,
|
|
345
|
-
maxZoom:
|
|
347
|
+
maxZoom: 21,
|
|
348
|
+
maxNativeZoom: 17,
|
|
346
349
|
opacity: .6
|
|
347
350
|
}), i = v.default.tileLayer(ye, {
|
|
348
351
|
attribution: "© OpenStreetMap contributors",
|
|
349
|
-
maxZoom:
|
|
352
|
+
maxZoom: 21,
|
|
353
|
+
maxNativeZoom: 19
|
|
350
354
|
}), a = v.default.map(e, {
|
|
351
355
|
center: [20, 0],
|
|
352
356
|
zoom: 2,
|
|
353
357
|
scrollWheelZoom: !0,
|
|
358
|
+
maxZoom: 21,
|
|
354
359
|
layers: [t]
|
|
355
360
|
});
|
|
356
361
|
T.current = a, v.default.control.layers({ [b("healthybowl.fieldMap.layers.satellite", "Satellite (Esri)")]: t }, {
|
|
@@ -454,7 +459,7 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
454
459
|
className: "text-xs text-text-secondary",
|
|
455
460
|
children: b("healthybowl.fieldMap.computedArea", "Area: {{area}} {{unit}}", {
|
|
456
461
|
area: String(B),
|
|
457
|
-
unit:
|
|
462
|
+
unit: i
|
|
458
463
|
})
|
|
459
464
|
}), /* @__PURE__ */ h(g, {
|
|
460
465
|
variant: "default",
|
|
@@ -563,7 +568,7 @@ var v = /* @__PURE__ */ e(r(), 1), me = _`
|
|
|
563
568
|
className: "mt-2 text-xs text-text-secondary",
|
|
564
569
|
children: b("healthybowl.fieldMap.attribution", "Imagery © Esri, Maxar, Earthstar Geographics · overlays © OpenTopoMap / OpenStreetMap")
|
|
565
570
|
}),
|
|
566
|
-
/* @__PURE__ */ m(
|
|
571
|
+
/* @__PURE__ */ m(r, {
|
|
567
572
|
toasts: Oe,
|
|
568
573
|
onDismiss: ke
|
|
569
574
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldMap.js","names":[],"sources":["../../../src/healthybowl/components/FieldMap.tsx"],"sourcesContent":["import { type FC, type FormEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport L from 'leaflet';\nimport { gql } from '@apollo/client';\nimport { useMutation } from '@apollo/client/react';\nimport { Pencil, Trash2, Save, Upload, Check, X, MapPin, LocateFixed, MapPinned, Search } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport { useToast } from '../hooks/useToast';\nimport { ToastContainer } from './Toast';\nimport { geocodePlace } from '../utils/geocode';\nimport {\n ensureLeafletCss,\n extractPolygon,\n isValidPolygon,\n polygonAreaInUnit,\n ringToPolygon,\n type GeoJsonPolygon,\n} from '../utils';\n\n// The service schema (wspace-healthybowl-svc) ships `boundary: JSON` on Field\n// and both field inputs. Until a connected-env `schema:pull` + `codegen` runs,\n// the generated hooks don't type `boundary`, so we persist it via a raw gql\n// document — mirroring the existing raw-gql pattern in useHealthyBowlData.ts.\nconst UPDATE_FIELD_BOUNDARY_DOC = gql`\n mutation UpdateHealthyBowlFieldBoundary($input: UpdateHealthyBowlFieldInput!) {\n updateHealthyBowlField(input: $input) {\n id\n area\n boundary\n location\n }\n }\n`;\n\ninterface UpdateFieldBoundaryVars {\n input: {\n id: string;\n boundary: GeoJsonPolygon | null;\n area?: number;\n location?: { lat: number; lng: number };\n context: { workspaceId: string };\n };\n}\n\ninterface PendingFieldLocation {\n lat: number;\n lng: number;\n label: string;\n}\n\ninterface FieldMapProps {\n fieldId: string;\n /** Field measurement unit — the computed area is written back in this unit. */\n unit: 'acres' | 'hectares';\n /** Approximate field centre (from Field.location); used only for the initial view. */\n center?: { lat: number; lng: number } | null;\n /** Existing boundary (Field.boundary) to render on load, if any. */\n initialBoundary?: unknown;\n /** Called after a successful save so the parent can refetch. */\n onSaved?: () => void;\n /**\n * Emits the live boundary area (in `unit`) whenever it changes — as the user\n * draws, imports, or clears a boundary. Lets the parent drive planting-capacity\n * planning off the drawn boundary before it is even saved. `null` when no boundary.\n */\n onAreaChange?: (area: number | null) => void;\n}\n\nconst ESRI_IMAGERY = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';\nconst ESRI_ATTR = 'Esri, Maxar, Earthstar Geographics';\nconst TOPO_URL = 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png';\nconst TOPO_ATTR = '© OpenTopoMap (CC-BY-SA) · © OpenStreetMap contributors';\nconst OSM_URL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';\n\nconst BOUNDARY_STYLE: L.PathOptions = { color: '#16a34a', weight: 2, fillColor: '#16a34a', fillOpacity: 0.25 };\nconst DRAFT_STYLE: L.PathOptions = {\n color: '#f59e0b',\n weight: 2,\n dashArray: '6 4',\n fillColor: '#f59e0b',\n fillOpacity: 0.15,\n};\nconst FIELD_VIEW_ZOOM = 16;\nconst USER_VIEW_ZOOM = 17;\n\nconst isUsableCoordinate = (value?: { lat: number; lng: number } | null): value is { lat: number; lng: number } =>\n Boolean(\n value &&\n Number.isFinite(value.lat) &&\n Number.isFinite(value.lng) &&\n value.lat >= -90 &&\n value.lat <= 90 &&\n value.lng >= -180 &&\n value.lng <= 180 &&\n (value.lat !== 0 || value.lng !== 0)\n );\n\nconst parseCoordinateSearch = (query: string): PendingFieldLocation | null => {\n const match = query.trim().match(/^(-?\\d+(?:\\.\\d+)?)\\s*,\\s*(-?\\d+(?:\\.\\d+)?)$/);\n if (!match) return null;\n const lat = Number(match[1]);\n const lng = Number(match[2]);\n if (!isUsableCoordinate({ lat, lng })) return null;\n return { lat, lng, label: `${lat.toFixed(6)}, ${lng.toFixed(6)}` };\n};\n\nexport const FieldMap: FC<FieldMapProps> = ({ fieldId, unit, center, initialBoundary, onSaved, onAreaChange }) => {\n const { t } = useI18n();\n const { workspaceId } = useHealthyBowl();\n const { toasts, toast, dismiss } = useToast();\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const containerRef = useRef<HTMLDivElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const boundaryLayerRef = useRef<L.GeoJSON | null>(null);\n const draftPolyRef = useRef<L.Polygon | null>(null);\n const userLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const userAccuracyCircleRef = useRef<L.Circle | null>(null);\n const fieldLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const savedCenterRef = useRef<{ lat: number; lng: number } | null>(center ?? null);\n const vertexMarkersRef = useRef<L.CircleMarker[]>([]);\n const draftVerticesRef = useRef<L.LatLng[]>([]);\n const currentBoundaryRef = useRef<GeoJsonPolygon | null>(null);\n const modeRef = useRef<'view' | 'draw'>('view');\n\n const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');\n const [mode, setMode] = useState<'view' | 'draw'>('view');\n const [hasBoundary, setHasBoundary] = useState(false);\n const [area, setArea] = useState<number | null>(null);\n const [vertexCount, setVertexCount] = useState(0);\n const [boundaryDirty, setBoundaryDirty] = useState(false);\n const [locationDirty, setLocationDirty] = useState(false);\n const [saving, setSaving] = useState(false);\n const [locating, setLocating] = useState(false);\n const [searchQuery, setSearchQuery] = useState('');\n const [searching, setSearching] = useState(false);\n const [pendingFieldLocation, setPendingFieldLocation] = useState<PendingFieldLocation | null>(null);\n const dirty = boundaryDirty || locationDirty;\n\n const [updateBoundary] = useMutation<{ updateHealthyBowlField: { id: string } }, UpdateFieldBoundaryVars>(\n UPDATE_FIELD_BOUNDARY_DOC\n );\n\n useEffect(() => {\n savedCenterRef.current = center ?? null;\n }, [center]);\n\n // Surface the live boundary area so the parent can drive planting capacity off\n // the drawn boundary (not just the stored field area).\n useEffect(() => {\n onAreaChange?.(area);\n }, [area, onAreaChange]);\n\n // ── Render helpers ──────────────────────────────────────────────────────────\n const clearDraft = useCallback(() => {\n const map = mapRef.current;\n if (draftPolyRef.current && map) map.removeLayer(draftPolyRef.current);\n draftPolyRef.current = null;\n vertexMarkersRef.current.forEach((m) => map?.removeLayer(m));\n vertexMarkersRef.current = [];\n draftVerticesRef.current = [];\n setVertexCount(0);\n }, []);\n\n const showBoundary = useCallback(\n (polygon: GeoJsonPolygon, fit: boolean) => {\n const map = mapRef.current;\n if (!map) return;\n if (boundaryLayerRef.current) map.removeLayer(boundaryLayerRef.current);\n const layer = L.geoJSON(polygon, { style: () => BOUNDARY_STYLE }).addTo(map);\n boundaryLayerRef.current = layer;\n currentBoundaryRef.current = polygon;\n setHasBoundary(true);\n setArea(polygonAreaInUnit(polygon, unit));\n if (fit) {\n try {\n map.fitBounds(layer.getBounds(), { padding: [24, 24], maxZoom: 18 });\n } catch {\n /* empty bounds — ignore */\n }\n }\n },\n [unit]\n );\n\n const removeBoundary = useCallback(() => {\n const map = mapRef.current;\n if (boundaryLayerRef.current && map) map.removeLayer(boundaryLayerRef.current);\n boundaryLayerRef.current = null;\n currentBoundaryRef.current = null;\n setHasBoundary(false);\n setArea(null);\n }, []);\n\n const clearUserLocation = useCallback(() => {\n const map = mapRef.current;\n if (userLocationMarkerRef.current && map) map.removeLayer(userLocationMarkerRef.current);\n if (userAccuracyCircleRef.current && map) map.removeLayer(userAccuracyCircleRef.current);\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n }, []);\n\n const clearFieldLocationCandidate = useCallback(() => {\n const map = mapRef.current;\n if (fieldLocationMarkerRef.current && map) map.removeLayer(fieldLocationMarkerRef.current);\n fieldLocationMarkerRef.current = null;\n setPendingFieldLocation(null);\n setLocationDirty(false);\n }, []);\n\n const showFieldLocationCandidate = useCallback((candidate: PendingFieldLocation) => {\n const map = mapRef.current;\n if (!map) return;\n if (fieldLocationMarkerRef.current) map.removeLayer(fieldLocationMarkerRef.current);\n\n const latlng: L.LatLngExpression = [candidate.lat, candidate.lng];\n const popupEl = document.createElement('span');\n popupEl.textContent = candidate.label;\n fieldLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 8,\n color: '#ffffff',\n weight: 2,\n fillColor: '#16a34a',\n fillOpacity: 1,\n })\n .addTo(map)\n .bindPopup(popupEl)\n .openPopup();\n map.flyTo(latlng, Math.max(map.getZoom(), USER_VIEW_ZOOM), { duration: 0.75 });\n setPendingFieldLocation(candidate);\n setLocationDirty(true);\n }, []);\n\n const focusField = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n const boundaryLayer = boundaryLayerRef.current;\n if (boundaryLayer) {\n try {\n const bounds = boundaryLayer.getBounds();\n if (bounds.isValid()) {\n map.fitBounds(bounds, { padding: [24, 24], maxZoom: 18 });\n return;\n }\n } catch {\n /* empty bounds — fall back to field location */\n }\n }\n const savedCenter = savedCenterRef.current;\n if (isUsableCoordinate(savedCenter)) {\n map.flyTo([savedCenter.lat, savedCenter.lng], FIELD_VIEW_ZOOM, { duration: 0.6 });\n return;\n }\n toast({\n title: t('healthybowl.fieldMap.toast.noFieldLocation.title', 'No field location set'),\n description: t(\n 'healthybowl.fieldMap.toast.noFieldLocation.description',\n 'Draw a boundary or save GPS coordinates for this field first.'\n ),\n variant: 'warning',\n });\n }, [t, toast]);\n\n const handleLocateMe = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n if (typeof navigator === 'undefined' || !navigator.geolocation) {\n toast({\n title: t('healthybowl.fieldMap.toast.locationUnsupported.title', 'Location unavailable'),\n description: t(\n 'healthybowl.fieldMap.toast.locationUnsupported.description',\n 'This browser does not support device location.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n setLocating(true);\n navigator.geolocation.getCurrentPosition(\n (position) => {\n const latlng: L.LatLngExpression = [position.coords.latitude, position.coords.longitude];\n clearUserLocation();\n userAccuracyCircleRef.current = L.circle(latlng, {\n radius: Math.max(10, position.coords.accuracy || 0),\n color: '#2563eb',\n fillColor: '#3b82f6',\n fillOpacity: 0.12,\n opacity: 0.45,\n weight: 1,\n }).addTo(map);\n userLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 7,\n color: '#ffffff',\n weight: 2,\n fillColor: '#2563eb',\n fillOpacity: 1,\n }).addTo(map);\n map.flyTo(latlng, Math.max(map.getZoom(), USER_VIEW_ZOOM), { duration: 0.75 });\n showFieldLocationCandidate({\n lat: position.coords.latitude,\n lng: position.coords.longitude,\n label: t('healthybowl.fieldMap.location.currentLabel', 'My current location'),\n });\n setLocating(false);\n toast({\n title: t('healthybowl.fieldMap.toast.locationReady.title', 'Location ready'),\n description: t(\n 'healthybowl.fieldMap.toast.locationReady.description',\n 'Save to store this as the field GPS location.'\n ),\n variant: 'success',\n });\n },\n (error) => {\n const blocked = error.code === error.PERMISSION_DENIED;\n toast({\n title: blocked\n ? t('healthybowl.fieldMap.toast.locationBlocked.title', 'Location blocked')\n : t('healthybowl.fieldMap.toast.locationFailed.title', 'Could not get location'),\n description: blocked\n ? t(\n 'healthybowl.fieldMap.toast.locationBlocked.description',\n 'Allow location access in the browser, then try again.'\n )\n : t(\n 'healthybowl.fieldMap.toast.locationFailed.description',\n 'Make sure GPS is enabled and the page is open over HTTPS.'\n ),\n variant: 'warning',\n });\n setLocating(false);\n },\n { enableHighAccuracy: true, timeout: 12000, maximumAge: 60000 }\n );\n }, [clearUserLocation, showFieldLocationCandidate, t, toast]);\n\n const handleSearchPlace = useCallback(\n async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n const place = searchQuery.trim();\n if (!place) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchRequired.title', 'Place required'),\n description: t(\n 'healthybowl.fieldMap.toast.searchRequired.description',\n 'Enter a village, city, region, or coordinates.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const coordinateCandidate = parseCoordinateSearch(place);\n if (coordinateCandidate) {\n showFieldLocationCandidate(coordinateCandidate);\n return;\n }\n\n setSearching(true);\n try {\n const hit = await geocodePlace(place);\n if (!hit) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchNotFound.title', 'Place not found'),\n description: t(\n 'healthybowl.fieldMap.toast.searchNotFound.description',\n 'Try a more specific location, such as village, district, and state.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const label = [hit.name, hit.admin1, hit.country].filter(Boolean).join(', ') || place;\n showFieldLocationCandidate({ lat: hit.latitude, lng: hit.longitude, label });\n } catch (err) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchFailed.title', 'Search failed'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setSearching(false);\n }\n },\n [searchQuery, showFieldLocationCandidate, t, toast]\n );\n\n // ── Draw mode ───────────────────────────────────────────────────────────────\n const redrawDraft = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n const pts = draftVerticesRef.current;\n if (draftPolyRef.current) map.removeLayer(draftPolyRef.current);\n if (pts.length >= 2) {\n draftPolyRef.current = L.polygon(pts, DRAFT_STYLE).addTo(map);\n } else {\n draftPolyRef.current = null;\n }\n }, []);\n\n const finishDraw = useCallback(() => {\n if (draftVerticesRef.current.length < 3) {\n toast({\n title: t('healthybowl.fieldMap.toast.needPoints.title', 'Need at least 3 points'),\n description: t(\n 'healthybowl.fieldMap.toast.needPoints.description',\n 'Click on the map to add more boundary corners.'\n ),\n variant: 'warning',\n });\n return;\n }\n const polygon = ringToPolygon(draftVerticesRef.current.map((p) => ({ lat: p.lat, lng: p.lng })));\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n if (polygon) {\n showBoundary(polygon, false);\n setBoundaryDirty(true);\n }\n }, [clearDraft, showBoundary, t, toast]);\n\n const handleMapClick = useCallback(\n (e: L.LeafletMouseEvent) => {\n if (modeRef.current !== 'draw') return;\n const map = mapRef.current;\n if (!map) return;\n draftVerticesRef.current.push(e.latlng);\n const isFirst = draftVerticesRef.current.length === 1;\n const marker = L.circleMarker(e.latlng, {\n radius: isFirst ? 7 : 5,\n color: '#fff',\n weight: 2,\n fillColor: isFirst ? '#16a34a' : '#f59e0b',\n fillOpacity: 1,\n }).addTo(map);\n if (isFirst) {\n // Clicking the first vertex again closes the ring.\n marker.on('click', (ev) => {\n L.DomEvent.stopPropagation(ev);\n finishDraw();\n });\n }\n vertexMarkersRef.current.push(marker);\n setVertexCount(draftVerticesRef.current.length);\n redrawDraft();\n },\n [finishDraw, redrawDraft]\n );\n\n const startDraw = useCallback(() => {\n removeBoundary();\n clearDraft();\n modeRef.current = 'draw';\n setMode('draw');\n setBoundaryDirty(true);\n }, [clearDraft, removeBoundary]);\n\n const cancelDraw = useCallback(() => {\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n }, [clearDraft]);\n\n const handleClear = useCallback(() => {\n clearDraft();\n removeBoundary();\n modeRef.current = 'view';\n setMode('view');\n setBoundaryDirty(true);\n }, [clearDraft, removeBoundary]);\n\n // ── Import ──────────────────────────────────────────────────────────────────\n const handleImportFile = useCallback(\n async (file: File) => {\n try {\n const text = await file.text();\n const parsed: unknown = JSON.parse(text);\n if (!isValidPolygon(parsed)) {\n toast({\n title: t('healthybowl.fieldMap.toast.importInvalid.title', 'No polygon found'),\n description: t(\n 'healthybowl.fieldMap.toast.importInvalid.description',\n 'The file must contain a GeoJSON Polygon (Feature, FeatureCollection or geometry).'\n ),\n variant: 'error',\n });\n return;\n }\n const polygon = extractPolygon(parsed) as GeoJsonPolygon;\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n showBoundary(polygon, true);\n setBoundaryDirty(true);\n toast({\n title: t('healthybowl.fieldMap.toast.imported.title', 'Boundary imported'),\n description: t(\n 'healthybowl.fieldMap.toast.imported.description',\n 'Review it on the map, then Save to persist.'\n ),\n variant: 'success',\n });\n } catch {\n toast({\n title: t('healthybowl.fieldMap.toast.importFailed.title', 'Could not read file'),\n description: t(\n 'healthybowl.fieldMap.toast.importFailed.description',\n 'Make sure it is a valid GeoJSON (.json / .geojson) file.'\n ),\n variant: 'error',\n });\n }\n },\n [clearDraft, showBoundary, t, toast]\n );\n\n // ── Save ────────────────────────────────────────────────────────────────────\n const handleSave = useCallback(async () => {\n setSaving(true);\n try {\n const polygon = currentBoundaryRef.current;\n const nextArea = polygon ? polygonAreaInUnit(polygon, unit) : undefined;\n const nextLocation = pendingFieldLocation\n ? { lat: pendingFieldLocation.lat, lng: pendingFieldLocation.lng }\n : undefined;\n await updateBoundary({\n variables: {\n input: {\n id: fieldId,\n boundary: polygon,\n ...(nextArea != null ? { area: nextArea } : {}),\n ...(nextLocation ? { location: nextLocation } : {}),\n context: { workspaceId },\n },\n },\n });\n if (nextLocation) savedCenterRef.current = nextLocation;\n setBoundaryDirty(false);\n setLocationDirty(false);\n setPendingFieldLocation(null);\n onSaved?.();\n toast({\n title: t('healthybowl.fieldMap.toast.saved.title', 'Map saved'),\n description: nextLocation\n ? t('healthybowl.fieldMap.toast.savedLocation.description', 'Field GPS location updated.')\n : polygon\n ? t('healthybowl.fieldMap.toast.saved.description', 'Field area updated to {{area}} {{unit}}.', {\n area: String(nextArea ?? ''),\n unit,\n })\n : t('healthybowl.fieldMap.toast.savedCleared.description', 'Boundary removed from this field.'),\n variant: 'success',\n });\n } catch (err) {\n toast({\n title: t('healthybowl.fieldMap.toast.saveFailed.title', 'Save failed'),\n description: String(err),\n variant: 'error',\n });\n } finally {\n setSaving(false);\n }\n }, [fieldId, onSaved, pendingFieldLocation, t, toast, unit, updateBoundary, workspaceId]);\n\n // ── Map init (once) ──────────────────────────────────────────────────────────\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return undefined;\n ensureLeafletCss();\n\n const satellite = L.tileLayer(ESRI_IMAGERY, { attribution: ESRI_ATTR, maxZoom: 19 });\n const terrain = L.tileLayer(TOPO_URL, { attribution: TOPO_ATTR, maxZoom: 17 });\n // TODO soil WMS URL: no reliable keyless soil WMS is confidently known, so the\n // \"Soil\" overlay is wired to a clearly-labelled OpenTopoMap placeholder for now.\n // Swap this for an OpenLandMap / SoilGrids WMS once a stable endpoint is confirmed.\n const soilPlaceholder = L.tileLayer(TOPO_URL, { attribution: TOPO_ATTR, maxZoom: 17, opacity: 0.6 });\n const streets = L.tileLayer(OSM_URL, { attribution: '© OpenStreetMap contributors', maxZoom: 19 });\n\n const map = L.map(el, { center: [20, 0], zoom: 2, scrollWheelZoom: true, layers: [satellite] });\n mapRef.current = map;\n\n L.control\n .layers(\n { [t('healthybowl.fieldMap.layers.satellite', 'Satellite (Esri)')]: satellite },\n {\n [t('healthybowl.fieldMap.layers.terrain', 'Terrain (OpenTopoMap)')]: terrain,\n [t('healthybowl.fieldMap.layers.soil', 'Soil (placeholder)')]: soilPlaceholder,\n [t('healthybowl.fieldMap.layers.streets', 'Streets (OSM)')]: streets,\n },\n { collapsed: false }\n )\n .addTo(map);\n\n map.on('click', handleMapClick);\n\n // Initial view: existing boundary → fit; else field centre; else world.\n const existing = extractPolygon(initialBoundary);\n if (existing && isValidPolygon(existing)) {\n showBoundary(existing, true);\n } else if (isUsableCoordinate(center)) {\n map.setView([center.lat, center.lng], FIELD_VIEW_ZOOM);\n }\n\n setStatus('ready');\n window.setTimeout(() => map.invalidateSize(), 80);\n\n return () => {\n map.off('click', handleMapClick);\n map.remove();\n mapRef.current = null;\n boundaryLayerRef.current = null;\n draftPolyRef.current = null;\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n fieldLocationMarkerRef.current = null;\n vertexMarkersRef.current = [];\n draftVerticesRef.current = [];\n currentBoundaryRef.current = null;\n };\n // Init once; handlers are stable via useCallback and read the latest state through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className=\"relative\">\n <div className=\"mb-3 flex flex-wrap items-center gap-2\">\n {mode === 'view' ? (\n <>\n <Button variant=\"outline\" size=\"sm\" onClick={startDraw}>\n <Pencil className=\"h-4 w-4\" />{' '}\n {hasBoundary\n ? t('healthybowl.fieldMap.actions.redraw', 'Redraw')\n : t('healthybowl.fieldMap.actions.draw', 'Draw boundary')}\n </Button>\n <Button variant=\"outline\" size=\"sm\" onClick={() => fileInputRef.current?.click()}>\n <Upload className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.import', 'Import GeoJSON')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={focusField}\n title={t('healthybowl.fieldMap.actions.focusField.title', 'Fit map to this field')}\n aria-label={t('healthybowl.fieldMap.actions.focusField.title', 'Fit map to this field')}\n >\n <MapPinned className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.focusField', 'Field')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={handleLocateMe}\n disabled={locating}\n title={t('healthybowl.fieldMap.actions.locateMe.title', 'Go to my current location')}\n aria-label={t('healthybowl.fieldMap.actions.locateMe.title', 'Go to my current location')}\n >\n <LocateFixed className=\"h-4 w-4\" />{' '}\n {locating\n ? t('healthybowl.fieldMap.actions.locating', 'Locating...')\n : t('healthybowl.fieldMap.actions.locateMe', 'My location')}\n </Button>\n {hasBoundary && (\n <Button variant=\"outline\" size=\"sm\" onClick={handleClear}>\n <Trash2 className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.clear', 'Clear')}\n </Button>\n )}\n </>\n ) : (\n <>\n <Button variant=\"default\" size=\"sm\" onClick={finishDraw}>\n <Check className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.finish', 'Finish')}\n </Button>\n <Button variant=\"outline\" size=\"sm\" onClick={cancelDraw}>\n <X className=\"h-4 w-4\" /> {t('healthybowl.common.cancel', 'Cancel')}\n </Button>\n <span className=\"text-xs text-text-secondary\">\n {t(\n 'healthybowl.fieldMap.draftHint',\n 'Click the map to add corners ({{count}} placed) — click the first point or Finish to close.',\n {\n count: String(vertexCount),\n }\n )}\n </span>\n </>\n )}\n <div className=\"ml-auto flex items-center gap-3\">\n {area != null && (\n <span className=\"text-xs text-text-secondary\">\n {t('healthybowl.fieldMap.computedArea', 'Area: {{area}} {{unit}}', { area: String(area), unit })}\n </span>\n )}\n <Button variant=\"default\" size=\"sm\" onClick={handleSave} disabled={!dirty || saving || mode === 'draw'}>\n <Save className=\"h-4 w-4\" />{' '}\n {saving\n ? t('healthybowl.fieldMap.actions.saving', 'Saving…')\n : t('healthybowl.fieldMap.actions.save', 'Save')}\n </Button>\n </div>\n </div>\n\n {mode === 'view' && (\n <div className=\"mb-3 space-y-2\">\n <form className=\"flex flex-col gap-2 sm:flex-row\" onSubmit={handleSearchPlace}>\n <div className=\"relative min-w-0 flex-1\">\n <Search className=\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-text-secondary\" />\n <input\n type=\"search\"\n value={searchQuery}\n onChange={(event) => setSearchQuery(event.target.value)}\n disabled={status !== 'ready' || searching}\n placeholder={t(\n 'healthybowl.fieldMap.search.placeholder',\n 'Search village, city, region, or lat,lng...'\n )}\n aria-label={t('healthybowl.fieldMap.search.label', 'Search field map by place or coordinates')}\n className=\"h-9 w-full rounded-md border border-border-subtle bg-bg-surface py-2 pl-9 pr-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <Button type=\"submit\" variant=\"outline\" size=\"sm\" disabled={status !== 'ready' || searching}>\n <Search className=\"h-4 w-4\" />{' '}\n {searching\n ? t('healthybowl.fieldMap.search.searching', 'Searching...')\n : t('healthybowl.fieldMap.search.action', 'Search')}\n </Button>\n {pendingFieldLocation && (\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={clearFieldLocationCandidate}>\n <X className=\"h-4 w-4\" /> {t('healthybowl.common.clear', 'Clear')}\n </Button>\n )}\n </form>\n {pendingFieldLocation && (\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n <span className=\"inline-flex min-w-0 items-center gap-1.5 rounded-full border border-border-subtle bg-bg-sunken/70 px-2.5 py-1\">\n <MapPin className=\"h-3.5 w-3.5 shrink-0 text-success\" />\n <span className=\"truncate\">\n {t('healthybowl.fieldMap.search.pendingLocation', 'Unsaved field GPS: {{place}}', {\n place: pendingFieldLocation.label,\n })}\n </span>\n </span>\n </div>\n )}\n </div>\n )}\n\n <input\n ref={fileInputRef}\n type=\"file\"\n accept=\".json,.geojson,application/geo+json,application/json\"\n className=\"hidden\"\n onChange={(e) => {\n const file = e.target.files?.[0];\n if (file) void handleImportFile(file);\n e.target.value = '';\n }}\n />\n\n <div className=\"relative\">\n <div\n ref={containerRef}\n className=\"h-[60vh] max-h-[520px] w-full overflow-hidden rounded-md border border-border-subtle bg-bg-sunken\"\n />\n {status === 'loading' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/60 text-sm text-text-secondary\">\n {t('healthybowl.fieldMap.loading', 'Loading map…')}\n </div>\n )}\n {status === 'error' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/80 px-4 text-center text-sm text-text-secondary\">\n {t('healthybowl.fieldMap.error', 'The map needs an internet connection and couldn’t load.')}\n </div>\n )}\n {status === 'ready' && !hasBoundary && mode === 'view' && (\n <div className=\"pointer-events-none absolute left-1/2 top-3 z-[400] -translate-x-1/2 rounded-full bg-bg-surface/90 px-3 py-1.5 text-xs text-text-secondary shadow-sm\">\n <span className=\"inline-flex items-center gap-1.5\">\n <MapPin className=\"h-3.5 w-3.5\" />{' '}\n {t('healthybowl.fieldMap.empty', 'No boundary set — draw or import one.')}\n </span>\n </div>\n )}\n </div>\n\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.fieldMap.attribution',\n 'Imagery © Esri, Maxar, Earthstar Geographics · overlays © OpenTopoMap / OpenStreetMap'\n )}\n </p>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;mCAwBM,KAA4B,CAAG;;;;;;;;;GA6C/B,KAAe,iGACf,KA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IAAD,EAAG,WAAU,WAAY,CAAA;;QAAE,EAAE,4BAA4B,QAAQ;QAC1D;;MAEN;QACN,KACC,kBAAC,OAAD;KAAK,WAAU;eACb,kBAAC,QAAD;MAAM,WAAU;gBAAhB,CACE,kBAAC,GAAD,EAAQ,WAAU,qCAAsC,CAAA,EACxD,kBAAC,QAAD;OAAM,WAAU;iBACb,EAAE,+CAA+C,gCAAgC,EAChF,OAAO,EAAqB,OAC7B,CAAC;OACG,CAAA,CACF;;KACH,CAAA,CAEJ;;GAGR,kBAAC,SAAD;IACE,KAAK;IACL,MAAK;IACL,QAAO;IACP,WAAU;IACV,WAAW,MAAM;KACf,IAAM,IAAO,EAAE,OAAO,QAAQ;AAE9B,KADI,KAAW,GAAiB,EAAK,EACrC,EAAE,OAAO,QAAQ;;IAEnB,CAAA;GAEF,kBAAC,OAAD;IAAK,WAAU;cAAf;KACE,kBAAC,OAAD;MACE,KAAK;MACL,WAAU;MACV,CAAA;KACD,MAAW,aACV,kBAAC,OAAD;MAAK,WAAU;gBACZ,EAAE,gCAAgC,eAAe;MAC9C,CAAA;KAEP,MAAW,WACV,kBAAC,OAAD;MAAK,WAAU;gBACZ,EAAE,8BAA8B,0DAA0D;MACvF,CAAA;KAEP,MAAW,WAAW,CAAC,KAAe,MAAS,UAC9C,kBAAC,OAAD;MAAK,WAAU;gBACb,kBAAC,QAAD;OAAM,WAAU;iBAAhB;QACE,kBAAC,GAAD,EAAQ,WAAU,eAAgB,CAAA;QAAC;QAClC,EAAE,8BAA8B,wCAAwC;QACpE;;MACH,CAAA;KAEJ;;GAEN,kBAAC,KAAD;IAAG,WAAU;cACV,EACC,oCACA,wFACD;IACC,CAAA;GAEJ,kBAAC,GAAD;IAAwB;IAAQ,WAAW;IAAW,CAAA;GAClD"}
|
|
1
|
+
{"version":3,"file":"FieldMap.js","names":[],"sources":["../../../src/healthybowl/components/FieldMap.tsx"],"sourcesContent":["import { type FC, type FormEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport L from 'leaflet';\nimport { gql } from '@apollo/client';\nimport { useMutation } from '@apollo/client/react';\nimport { Pencil, Trash2, Save, Upload, Check, X, MapPin, LocateFixed, MapPinned, Search } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport { useToast } from '../hooks/useToast';\nimport { ToastContainer } from './Toast';\nimport { geocodePlace } from '../utils/geocode';\nimport {\n ensureLeafletCss,\n extractPolygon,\n isValidPolygon,\n polygonAreaInUnit,\n ringToPolygon,\n type GeoJsonPolygon,\n} from '../utils';\n\n// The service schema (wspace-healthybowl-svc) ships `boundary: JSON` on Field\n// and both field inputs. Until a connected-env `schema:pull` + `codegen` runs,\n// the generated hooks don't type `boundary`, so we persist it via a raw gql\n// document — mirroring the existing raw-gql pattern in useHealthyBowlData.ts.\nconst UPDATE_FIELD_BOUNDARY_DOC = gql`\n mutation UpdateHealthyBowlFieldBoundary($input: UpdateHealthyBowlFieldInput!) {\n updateHealthyBowlField(input: $input) {\n id\n area\n boundary\n location\n }\n }\n`;\n\ninterface UpdateFieldBoundaryVars {\n input: {\n id: string;\n boundary: GeoJsonPolygon | null;\n area?: number;\n location?: { lat: number; lng: number };\n context: { workspaceId: string };\n };\n}\n\ninterface PendingFieldLocation {\n lat: number;\n lng: number;\n label: string;\n}\n\ninterface FieldMapProps {\n fieldId: string;\n /** Field measurement unit — the computed area is written back in this unit. */\n unit: 'acres' | 'hectares';\n /** Approximate field centre (from Field.location); used only for the initial view. */\n center?: { lat: number; lng: number } | null;\n /** Existing boundary (Field.boundary) to render on load, if any. */\n initialBoundary?: unknown;\n /** Called after a successful save so the parent can refetch. */\n onSaved?: () => void;\n /**\n * Emits the live boundary area (in `unit`) whenever it changes — as the user\n * draws, imports, or clears a boundary. Lets the parent drive planting-capacity\n * planning off the drawn boundary before it is even saved. `null` when no boundary.\n */\n onAreaChange?: (area: number | null) => void;\n}\n\nconst ESRI_IMAGERY = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';\nconst ESRI_ATTR = 'Esri, Maxar, Earthstar Geographics';\nconst TOPO_URL = 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png';\nconst TOPO_ATTR = '© OpenTopoMap (CC-BY-SA) · © OpenStreetMap contributors';\nconst OSM_URL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';\n\nconst BOUNDARY_STYLE: L.PathOptions = { color: '#16a34a', weight: 2, fillColor: '#16a34a', fillOpacity: 0.25 };\nconst DRAFT_STYLE: L.PathOptions = {\n color: '#f59e0b',\n weight: 2,\n dashArray: '6 4',\n fillColor: '#f59e0b',\n fillOpacity: 0.15,\n};\nconst FIELD_VIEW_ZOOM = 16;\nconst USER_VIEW_ZOOM = 17;\n\nconst isUsableCoordinate = (value?: { lat: number; lng: number } | null): value is { lat: number; lng: number } =>\n Boolean(\n value &&\n Number.isFinite(value.lat) &&\n Number.isFinite(value.lng) &&\n value.lat >= -90 &&\n value.lat <= 90 &&\n value.lng >= -180 &&\n value.lng <= 180 &&\n (value.lat !== 0 || value.lng !== 0)\n );\n\nconst parseCoordinateSearch = (query: string): PendingFieldLocation | null => {\n const match = query.trim().match(/^(-?\\d+(?:\\.\\d+)?)\\s*,\\s*(-?\\d+(?:\\.\\d+)?)$/);\n if (!match) return null;\n const lat = Number(match[1]);\n const lng = Number(match[2]);\n if (!isUsableCoordinate({ lat, lng })) return null;\n return { lat, lng, label: `${lat.toFixed(6)}, ${lng.toFixed(6)}` };\n};\n\nexport const FieldMap: FC<FieldMapProps> = ({ fieldId, unit, center, initialBoundary, onSaved, onAreaChange }) => {\n const { t } = useI18n();\n const { workspaceId } = useHealthyBowl();\n const { toasts, toast, dismiss } = useToast();\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const containerRef = useRef<HTMLDivElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const boundaryLayerRef = useRef<L.GeoJSON | null>(null);\n const draftPolyRef = useRef<L.Polygon | null>(null);\n const userLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const userAccuracyCircleRef = useRef<L.Circle | null>(null);\n const fieldLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const savedCenterRef = useRef<{ lat: number; lng: number } | null>(center ?? null);\n const vertexMarkersRef = useRef<L.CircleMarker[]>([]);\n const draftVerticesRef = useRef<L.LatLng[]>([]);\n const currentBoundaryRef = useRef<GeoJsonPolygon | null>(null);\n const modeRef = useRef<'view' | 'draw'>('view');\n\n const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');\n const [mode, setMode] = useState<'view' | 'draw'>('view');\n const [hasBoundary, setHasBoundary] = useState(false);\n const [area, setArea] = useState<number | null>(null);\n const [vertexCount, setVertexCount] = useState(0);\n const [boundaryDirty, setBoundaryDirty] = useState(false);\n const [locationDirty, setLocationDirty] = useState(false);\n const [saving, setSaving] = useState(false);\n const [locating, setLocating] = useState(false);\n const [searchQuery, setSearchQuery] = useState('');\n const [searching, setSearching] = useState(false);\n const [pendingFieldLocation, setPendingFieldLocation] = useState<PendingFieldLocation | null>(null);\n const dirty = boundaryDirty || locationDirty;\n\n const [updateBoundary] = useMutation<{ updateHealthyBowlField: { id: string } }, UpdateFieldBoundaryVars>(\n UPDATE_FIELD_BOUNDARY_DOC\n );\n\n useEffect(() => {\n savedCenterRef.current = center ?? null;\n }, [center]);\n\n // Surface the live boundary area so the parent can drive planting capacity off\n // the drawn boundary (not just the stored field area).\n useEffect(() => {\n onAreaChange?.(area);\n }, [area, onAreaChange]);\n\n // ── Render helpers ──────────────────────────────────────────────────────────\n const clearDraft = useCallback(() => {\n const map = mapRef.current;\n if (draftPolyRef.current && map) map.removeLayer(draftPolyRef.current);\n draftPolyRef.current = null;\n vertexMarkersRef.current.forEach((m) => map?.removeLayer(m));\n vertexMarkersRef.current = [];\n draftVerticesRef.current = [];\n setVertexCount(0);\n }, []);\n\n const showBoundary = useCallback(\n (polygon: GeoJsonPolygon, fit: boolean) => {\n const map = mapRef.current;\n if (!map) return;\n if (boundaryLayerRef.current) map.removeLayer(boundaryLayerRef.current);\n const layer = L.geoJSON(polygon, { style: () => BOUNDARY_STYLE }).addTo(map);\n boundaryLayerRef.current = layer;\n currentBoundaryRef.current = polygon;\n setHasBoundary(true);\n setArea(polygonAreaInUnit(polygon, unit));\n if (fit) {\n try {\n map.fitBounds(layer.getBounds(), { padding: [24, 24], maxZoom: 18 });\n } catch {\n /* empty bounds — ignore */\n }\n }\n },\n [unit]\n );\n\n const removeBoundary = useCallback(() => {\n const map = mapRef.current;\n if (boundaryLayerRef.current && map) map.removeLayer(boundaryLayerRef.current);\n boundaryLayerRef.current = null;\n currentBoundaryRef.current = null;\n setHasBoundary(false);\n setArea(null);\n }, []);\n\n const clearUserLocation = useCallback(() => {\n const map = mapRef.current;\n if (userLocationMarkerRef.current && map) map.removeLayer(userLocationMarkerRef.current);\n if (userAccuracyCircleRef.current && map) map.removeLayer(userAccuracyCircleRef.current);\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n }, []);\n\n const clearFieldLocationCandidate = useCallback(() => {\n const map = mapRef.current;\n if (fieldLocationMarkerRef.current && map) map.removeLayer(fieldLocationMarkerRef.current);\n fieldLocationMarkerRef.current = null;\n setPendingFieldLocation(null);\n setLocationDirty(false);\n }, []);\n\n const showFieldLocationCandidate = useCallback((candidate: PendingFieldLocation) => {\n const map = mapRef.current;\n if (!map) return;\n if (fieldLocationMarkerRef.current) map.removeLayer(fieldLocationMarkerRef.current);\n\n const latlng: L.LatLngExpression = [candidate.lat, candidate.lng];\n const popupEl = document.createElement('span');\n popupEl.textContent = candidate.label;\n fieldLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 8,\n color: '#ffffff',\n weight: 2,\n fillColor: '#16a34a',\n fillOpacity: 1,\n })\n .addTo(map)\n .bindPopup(popupEl)\n .openPopup();\n map.flyTo(latlng, Math.max(map.getZoom(), USER_VIEW_ZOOM), { duration: 0.75 });\n setPendingFieldLocation(candidate);\n setLocationDirty(true);\n }, []);\n\n const focusField = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n const boundaryLayer = boundaryLayerRef.current;\n if (boundaryLayer) {\n try {\n const bounds = boundaryLayer.getBounds();\n if (bounds.isValid()) {\n map.fitBounds(bounds, { padding: [24, 24], maxZoom: 18 });\n return;\n }\n } catch {\n /* empty bounds — fall back to field location */\n }\n }\n const savedCenter = savedCenterRef.current;\n if (isUsableCoordinate(savedCenter)) {\n map.flyTo([savedCenter.lat, savedCenter.lng], FIELD_VIEW_ZOOM, { duration: 0.6 });\n return;\n }\n toast({\n title: t('healthybowl.fieldMap.toast.noFieldLocation.title', 'No field location set'),\n description: t(\n 'healthybowl.fieldMap.toast.noFieldLocation.description',\n 'Draw a boundary or save GPS coordinates for this field first.'\n ),\n variant: 'warning',\n });\n }, [t, toast]);\n\n const handleLocateMe = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n if (typeof navigator === 'undefined' || !navigator.geolocation) {\n toast({\n title: t('healthybowl.fieldMap.toast.locationUnsupported.title', 'Location unavailable'),\n description: t(\n 'healthybowl.fieldMap.toast.locationUnsupported.description',\n 'This browser does not support device location.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n setLocating(true);\n navigator.geolocation.getCurrentPosition(\n (position) => {\n const latlng: L.LatLngExpression = [position.coords.latitude, position.coords.longitude];\n clearUserLocation();\n userAccuracyCircleRef.current = L.circle(latlng, {\n radius: Math.max(10, position.coords.accuracy || 0),\n color: '#2563eb',\n fillColor: '#3b82f6',\n fillOpacity: 0.12,\n opacity: 0.45,\n weight: 1,\n }).addTo(map);\n userLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 7,\n color: '#ffffff',\n weight: 2,\n fillColor: '#2563eb',\n fillOpacity: 1,\n }).addTo(map);\n map.flyTo(latlng, Math.max(map.getZoom(), USER_VIEW_ZOOM), { duration: 0.75 });\n showFieldLocationCandidate({\n lat: position.coords.latitude,\n lng: position.coords.longitude,\n label: t('healthybowl.fieldMap.location.currentLabel', 'My current location'),\n });\n setLocating(false);\n toast({\n title: t('healthybowl.fieldMap.toast.locationReady.title', 'Location ready'),\n description: t(\n 'healthybowl.fieldMap.toast.locationReady.description',\n 'Save to store this as the field GPS location.'\n ),\n variant: 'success',\n });\n },\n (error) => {\n const blocked = error.code === error.PERMISSION_DENIED;\n toast({\n title: blocked\n ? t('healthybowl.fieldMap.toast.locationBlocked.title', 'Location blocked')\n : t('healthybowl.fieldMap.toast.locationFailed.title', 'Could not get location'),\n description: blocked\n ? t(\n 'healthybowl.fieldMap.toast.locationBlocked.description',\n 'Allow location access in the browser, then try again.'\n )\n : t(\n 'healthybowl.fieldMap.toast.locationFailed.description',\n 'Make sure GPS is enabled and the page is open over HTTPS.'\n ),\n variant: 'warning',\n });\n setLocating(false);\n },\n { enableHighAccuracy: true, timeout: 12000, maximumAge: 60000 }\n );\n }, [clearUserLocation, showFieldLocationCandidate, t, toast]);\n\n const handleSearchPlace = useCallback(\n async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n const place = searchQuery.trim();\n if (!place) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchRequired.title', 'Place required'),\n description: t(\n 'healthybowl.fieldMap.toast.searchRequired.description',\n 'Enter a village, city, region, or coordinates.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const coordinateCandidate = parseCoordinateSearch(place);\n if (coordinateCandidate) {\n showFieldLocationCandidate(coordinateCandidate);\n return;\n }\n\n setSearching(true);\n try {\n const hit = await geocodePlace(place);\n if (!hit) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchNotFound.title', 'Place not found'),\n description: t(\n 'healthybowl.fieldMap.toast.searchNotFound.description',\n 'Try a more specific location, such as village, district, and state.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const label = [hit.name, hit.admin1, hit.country].filter(Boolean).join(', ') || place;\n showFieldLocationCandidate({ lat: hit.latitude, lng: hit.longitude, label });\n } catch (err) {\n toast({\n title: t('healthybowl.fieldMap.toast.searchFailed.title', 'Search failed'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setSearching(false);\n }\n },\n [searchQuery, showFieldLocationCandidate, t, toast]\n );\n\n // ── Draw mode ───────────────────────────────────────────────────────────────\n const redrawDraft = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n const pts = draftVerticesRef.current;\n if (draftPolyRef.current) map.removeLayer(draftPolyRef.current);\n if (pts.length >= 2) {\n draftPolyRef.current = L.polygon(pts, DRAFT_STYLE).addTo(map);\n } else {\n draftPolyRef.current = null;\n }\n }, []);\n\n const finishDraw = useCallback(() => {\n if (draftVerticesRef.current.length < 3) {\n toast({\n title: t('healthybowl.fieldMap.toast.needPoints.title', 'Need at least 3 points'),\n description: t(\n 'healthybowl.fieldMap.toast.needPoints.description',\n 'Click on the map to add more boundary corners.'\n ),\n variant: 'warning',\n });\n return;\n }\n const polygon = ringToPolygon(draftVerticesRef.current.map((p) => ({ lat: p.lat, lng: p.lng })));\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n if (polygon) {\n showBoundary(polygon, false);\n setBoundaryDirty(true);\n }\n }, [clearDraft, showBoundary, t, toast]);\n\n const handleMapClick = useCallback(\n (e: L.LeafletMouseEvent) => {\n if (modeRef.current !== 'draw') return;\n const map = mapRef.current;\n if (!map) return;\n draftVerticesRef.current.push(e.latlng);\n const isFirst = draftVerticesRef.current.length === 1;\n const marker = L.circleMarker(e.latlng, {\n radius: isFirst ? 7 : 5,\n color: '#fff',\n weight: 2,\n fillColor: isFirst ? '#16a34a' : '#f59e0b',\n fillOpacity: 1,\n }).addTo(map);\n if (isFirst) {\n // Clicking the first vertex again closes the ring.\n marker.on('click', (ev) => {\n L.DomEvent.stopPropagation(ev);\n finishDraw();\n });\n }\n vertexMarkersRef.current.push(marker);\n setVertexCount(draftVerticesRef.current.length);\n redrawDraft();\n },\n [finishDraw, redrawDraft]\n );\n\n const startDraw = useCallback(() => {\n removeBoundary();\n clearDraft();\n modeRef.current = 'draw';\n setMode('draw');\n setBoundaryDirty(true);\n }, [clearDraft, removeBoundary]);\n\n const cancelDraw = useCallback(() => {\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n }, [clearDraft]);\n\n const handleClear = useCallback(() => {\n clearDraft();\n removeBoundary();\n modeRef.current = 'view';\n setMode('view');\n setBoundaryDirty(true);\n }, [clearDraft, removeBoundary]);\n\n // ── Import ──────────────────────────────────────────────────────────────────\n const handleImportFile = useCallback(\n async (file: File) => {\n try {\n const text = await file.text();\n const parsed: unknown = JSON.parse(text);\n if (!isValidPolygon(parsed)) {\n toast({\n title: t('healthybowl.fieldMap.toast.importInvalid.title', 'No polygon found'),\n description: t(\n 'healthybowl.fieldMap.toast.importInvalid.description',\n 'The file must contain a GeoJSON Polygon (Feature, FeatureCollection or geometry).'\n ),\n variant: 'error',\n });\n return;\n }\n const polygon = extractPolygon(parsed) as GeoJsonPolygon;\n clearDraft();\n modeRef.current = 'view';\n setMode('view');\n showBoundary(polygon, true);\n setBoundaryDirty(true);\n toast({\n title: t('healthybowl.fieldMap.toast.imported.title', 'Boundary imported'),\n description: t(\n 'healthybowl.fieldMap.toast.imported.description',\n 'Review it on the map, then Save to persist.'\n ),\n variant: 'success',\n });\n } catch {\n toast({\n title: t('healthybowl.fieldMap.toast.importFailed.title', 'Could not read file'),\n description: t(\n 'healthybowl.fieldMap.toast.importFailed.description',\n 'Make sure it is a valid GeoJSON (.json / .geojson) file.'\n ),\n variant: 'error',\n });\n }\n },\n [clearDraft, showBoundary, t, toast]\n );\n\n // ── Save ────────────────────────────────────────────────────────────────────\n const handleSave = useCallback(async () => {\n setSaving(true);\n try {\n const polygon = currentBoundaryRef.current;\n const nextArea = polygon ? polygonAreaInUnit(polygon, unit) : undefined;\n const nextLocation = pendingFieldLocation\n ? { lat: pendingFieldLocation.lat, lng: pendingFieldLocation.lng }\n : undefined;\n await updateBoundary({\n variables: {\n input: {\n id: fieldId,\n boundary: polygon,\n ...(nextArea != null ? { area: nextArea } : {}),\n ...(nextLocation ? { location: nextLocation } : {}),\n context: { workspaceId },\n },\n },\n });\n if (nextLocation) savedCenterRef.current = nextLocation;\n setBoundaryDirty(false);\n setLocationDirty(false);\n setPendingFieldLocation(null);\n onSaved?.();\n toast({\n title: t('healthybowl.fieldMap.toast.saved.title', 'Map saved'),\n description: nextLocation\n ? t('healthybowl.fieldMap.toast.savedLocation.description', 'Field GPS location updated.')\n : polygon\n ? t('healthybowl.fieldMap.toast.saved.description', 'Field area updated to {{area}} {{unit}}.', {\n area: String(nextArea ?? ''),\n unit,\n })\n : t('healthybowl.fieldMap.toast.savedCleared.description', 'Boundary removed from this field.'),\n variant: 'success',\n });\n } catch (err) {\n toast({\n title: t('healthybowl.fieldMap.toast.saveFailed.title', 'Save failed'),\n description: String(err),\n variant: 'error',\n });\n } finally {\n setSaving(false);\n }\n }, [fieldId, onSaved, pendingFieldLocation, t, toast, unit, updateBoundary, workspaceId]);\n\n // ── Map init (once) ──────────────────────────────────────────────────────────\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return undefined;\n ensureLeafletCss();\n\n // Allow zooming in to 21, but cap NATIVE tile requests at each source's real\n // coverage and let Leaflet UP-SCALE beyond it. Without maxNativeZoom, rural /\n // village areas (thin Esri imagery past ~z18) return a gray \"Map data not yet\n // available\" placeholder (HTTP 200) instead of a usable image — the reported\n // \"no map data when I zoom in\" bug. Upscaling a slightly-soft tile beats blank.\n const MAX_ZOOM = 21;\n const satellite = L.tileLayer(ESRI_IMAGERY, { attribution: ESRI_ATTR, maxZoom: MAX_ZOOM, maxNativeZoom: 18 });\n const terrain = L.tileLayer(TOPO_URL, { attribution: TOPO_ATTR, maxZoom: MAX_ZOOM, maxNativeZoom: 17 });\n // TODO soil WMS URL: no reliable keyless soil WMS is confidently known, so the\n // \"Soil\" overlay is wired to a clearly-labelled OpenTopoMap placeholder for now.\n // Swap this for an OpenLandMap / SoilGrids WMS once a stable endpoint is confirmed.\n const soilPlaceholder = L.tileLayer(TOPO_URL, {\n attribution: TOPO_ATTR,\n maxZoom: MAX_ZOOM,\n maxNativeZoom: 17,\n opacity: 0.6,\n });\n const streets = L.tileLayer(OSM_URL, {\n attribution: '© OpenStreetMap contributors',\n maxZoom: MAX_ZOOM,\n maxNativeZoom: 19,\n });\n\n const map = L.map(el, { center: [20, 0], zoom: 2, scrollWheelZoom: true, maxZoom: MAX_ZOOM, layers: [satellite] });\n mapRef.current = map;\n\n L.control\n .layers(\n { [t('healthybowl.fieldMap.layers.satellite', 'Satellite (Esri)')]: satellite },\n {\n [t('healthybowl.fieldMap.layers.terrain', 'Terrain (OpenTopoMap)')]: terrain,\n [t('healthybowl.fieldMap.layers.soil', 'Soil (placeholder)')]: soilPlaceholder,\n [t('healthybowl.fieldMap.layers.streets', 'Streets (OSM)')]: streets,\n },\n { collapsed: false }\n )\n .addTo(map);\n\n map.on('click', handleMapClick);\n\n // Initial view: existing boundary → fit; else field centre; else world.\n const existing = extractPolygon(initialBoundary);\n if (existing && isValidPolygon(existing)) {\n showBoundary(existing, true);\n } else if (isUsableCoordinate(center)) {\n map.setView([center.lat, center.lng], FIELD_VIEW_ZOOM);\n }\n\n setStatus('ready');\n window.setTimeout(() => map.invalidateSize(), 80);\n\n return () => {\n map.off('click', handleMapClick);\n map.remove();\n mapRef.current = null;\n boundaryLayerRef.current = null;\n draftPolyRef.current = null;\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n fieldLocationMarkerRef.current = null;\n vertexMarkersRef.current = [];\n draftVerticesRef.current = [];\n currentBoundaryRef.current = null;\n };\n // Init once; handlers are stable via useCallback and read the latest state through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className=\"relative\">\n <div className=\"mb-3 flex flex-wrap items-center gap-2\">\n {mode === 'view' ? (\n <>\n <Button variant=\"outline\" size=\"sm\" onClick={startDraw}>\n <Pencil className=\"h-4 w-4\" />{' '}\n {hasBoundary\n ? t('healthybowl.fieldMap.actions.redraw', 'Redraw')\n : t('healthybowl.fieldMap.actions.draw', 'Draw boundary')}\n </Button>\n <Button variant=\"outline\" size=\"sm\" onClick={() => fileInputRef.current?.click()}>\n <Upload className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.import', 'Import GeoJSON')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={focusField}\n title={t('healthybowl.fieldMap.actions.focusField.title', 'Fit map to this field')}\n aria-label={t('healthybowl.fieldMap.actions.focusField.title', 'Fit map to this field')}\n >\n <MapPinned className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.focusField', 'Field')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={handleLocateMe}\n disabled={locating}\n title={t('healthybowl.fieldMap.actions.locateMe.title', 'Go to my current location')}\n aria-label={t('healthybowl.fieldMap.actions.locateMe.title', 'Go to my current location')}\n >\n <LocateFixed className=\"h-4 w-4\" />{' '}\n {locating\n ? t('healthybowl.fieldMap.actions.locating', 'Locating...')\n : t('healthybowl.fieldMap.actions.locateMe', 'My location')}\n </Button>\n {hasBoundary && (\n <Button variant=\"outline\" size=\"sm\" onClick={handleClear}>\n <Trash2 className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.clear', 'Clear')}\n </Button>\n )}\n </>\n ) : (\n <>\n <Button variant=\"default\" size=\"sm\" onClick={finishDraw}>\n <Check className=\"h-4 w-4\" /> {t('healthybowl.fieldMap.actions.finish', 'Finish')}\n </Button>\n <Button variant=\"outline\" size=\"sm\" onClick={cancelDraw}>\n <X className=\"h-4 w-4\" /> {t('healthybowl.common.cancel', 'Cancel')}\n </Button>\n <span className=\"text-xs text-text-secondary\">\n {t(\n 'healthybowl.fieldMap.draftHint',\n 'Click the map to add corners ({{count}} placed) — click the first point or Finish to close.',\n {\n count: String(vertexCount),\n }\n )}\n </span>\n </>\n )}\n <div className=\"ml-auto flex items-center gap-3\">\n {area != null && (\n <span className=\"text-xs text-text-secondary\">\n {t('healthybowl.fieldMap.computedArea', 'Area: {{area}} {{unit}}', { area: String(area), unit })}\n </span>\n )}\n <Button variant=\"default\" size=\"sm\" onClick={handleSave} disabled={!dirty || saving || mode === 'draw'}>\n <Save className=\"h-4 w-4\" />{' '}\n {saving\n ? t('healthybowl.fieldMap.actions.saving', 'Saving…')\n : t('healthybowl.fieldMap.actions.save', 'Save')}\n </Button>\n </div>\n </div>\n\n {mode === 'view' && (\n <div className=\"mb-3 space-y-2\">\n <form className=\"flex flex-col gap-2 sm:flex-row\" onSubmit={handleSearchPlace}>\n <div className=\"relative min-w-0 flex-1\">\n <Search className=\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-text-secondary\" />\n <input\n type=\"search\"\n value={searchQuery}\n onChange={(event) => setSearchQuery(event.target.value)}\n disabled={status !== 'ready' || searching}\n placeholder={t(\n 'healthybowl.fieldMap.search.placeholder',\n 'Search village, city, region, or lat,lng...'\n )}\n aria-label={t('healthybowl.fieldMap.search.label', 'Search field map by place or coordinates')}\n className=\"h-9 w-full rounded-md border border-border-subtle bg-bg-surface py-2 pl-9 pr-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <Button type=\"submit\" variant=\"outline\" size=\"sm\" disabled={status !== 'ready' || searching}>\n <Search className=\"h-4 w-4\" />{' '}\n {searching\n ? t('healthybowl.fieldMap.search.searching', 'Searching...')\n : t('healthybowl.fieldMap.search.action', 'Search')}\n </Button>\n {pendingFieldLocation && (\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={clearFieldLocationCandidate}>\n <X className=\"h-4 w-4\" /> {t('healthybowl.common.clear', 'Clear')}\n </Button>\n )}\n </form>\n {pendingFieldLocation && (\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n <span className=\"inline-flex min-w-0 items-center gap-1.5 rounded-full border border-border-subtle bg-bg-sunken/70 px-2.5 py-1\">\n <MapPin className=\"h-3.5 w-3.5 shrink-0 text-success\" />\n <span className=\"truncate\">\n {t('healthybowl.fieldMap.search.pendingLocation', 'Unsaved field GPS: {{place}}', {\n place: pendingFieldLocation.label,\n })}\n </span>\n </span>\n </div>\n )}\n </div>\n )}\n\n <input\n ref={fileInputRef}\n type=\"file\"\n accept=\".json,.geojson,application/geo+json,application/json\"\n className=\"hidden\"\n onChange={(e) => {\n const file = e.target.files?.[0];\n if (file) void handleImportFile(file);\n e.target.value = '';\n }}\n />\n\n <div className=\"relative\">\n <div\n ref={containerRef}\n className=\"h-[60vh] max-h-[520px] w-full overflow-hidden rounded-md border border-border-subtle bg-bg-sunken\"\n />\n {status === 'loading' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/60 text-sm text-text-secondary\">\n {t('healthybowl.fieldMap.loading', 'Loading map…')}\n </div>\n )}\n {status === 'error' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/80 px-4 text-center text-sm text-text-secondary\">\n {t('healthybowl.fieldMap.error', 'The map needs an internet connection and couldn’t load.')}\n </div>\n )}\n {status === 'ready' && !hasBoundary && mode === 'view' && (\n <div className=\"pointer-events-none absolute left-1/2 top-3 z-[400] -translate-x-1/2 rounded-full bg-bg-surface/90 px-3 py-1.5 text-xs text-text-secondary shadow-sm\">\n <span className=\"inline-flex items-center gap-1.5\">\n <MapPin className=\"h-3.5 w-3.5\" />{' '}\n {t('healthybowl.fieldMap.empty', 'No boundary set — draw or import one.')}\n </span>\n </div>\n )}\n </div>\n\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.fieldMap.attribution',\n 'Imagery © Esri, Maxar, Earthstar Geographics · overlays © OpenTopoMap / OpenStreetMap'\n )}\n </p>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;mCAwBM,KAA4B,CAAG;;;;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virtual/_rolldown/runtime.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { geocodePlace as t } from "../utils/geocode.js";
|
|
3
|
+
import { ToastContainer as n } from "./Toast.js";
|
|
4
|
+
import { require_leaflet_src as r } from "../../node_modules/leaflet/dist/leaflet-src.js";
|
|
5
5
|
import { useToast as i } from "../hooks/useToast.js";
|
|
6
6
|
import { useCallback as a, useEffect as o, useRef as s, useState as c } from "react";
|
|
7
7
|
import { useI18n as l } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
@@ -9,14 +9,14 @@ import { LocateFixed as u, MapPinned as d, Search as f, X as p } from "lucide-re
|
|
|
9
9
|
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
10
10
|
import { Button as g } from "@burdenoff/fe-libs/ui";
|
|
11
11
|
//#region src/healthybowl/components/WeatherMap.tsx
|
|
12
|
-
var _ = /* @__PURE__ */ e(
|
|
13
|
-
function
|
|
12
|
+
var _ = /* @__PURE__ */ e(r(), 1), v = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css", y = "sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=", b = 7, x = 10, S = 10, C = (e) => !!(e && Number.isFinite(e.lat) && Number.isFinite(e.lng) && e.lat >= -90 && e.lat <= 90 && e.lng >= -180 && e.lng <= 180 && (e.lat !== 0 || e.lng !== 0));
|
|
13
|
+
function ee() {
|
|
14
14
|
if (document.getElementById("leaflet-css")) return;
|
|
15
15
|
let e = document.createElement("link");
|
|
16
16
|
e.id = "leaflet-css", e.rel = "stylesheet", e.href = v, e.integrity = y, e.crossOrigin = "anonymous", document.head.appendChild(e);
|
|
17
17
|
}
|
|
18
|
-
var
|
|
19
|
-
let { t: v } = l(), { toasts: y, toast:
|
|
18
|
+
var w = ({ location: e, center: r }) => {
|
|
19
|
+
let { t: v } = l(), { toasts: y, toast: w, dismiss: T } = i(), E = s(null), D = s(null), O = s(null), k = s(null), A = s(null), j = s(null), [M, N] = c("loading"), [P, F] = c(!1), [I, L] = c(!1), [R, z] = c(""), [B, V] = c(!1), [H, U] = c(null), [W, G] = c(null), K = v("healthybowl.weather.map.layers.streets", "Streets"), q = v("healthybowl.weather.map.layers.terrain", "Terrain"), J = v("healthybowl.weather.map.layers.radar", "Live radar"), Y = C(r) ? r : null, X = Y ? Y.lat : null, Z = Y ? Y.lng : null, Q = a(() => {
|
|
20
20
|
let e = D.current;
|
|
21
21
|
k.current && e && e.removeLayer(k.current), A.current && e && e.removeLayer(A.current), k.current = null, A.current = null;
|
|
22
22
|
}, []), $ = a(() => {
|
|
@@ -31,7 +31,7 @@ var T = ({ location: e, center: n }) => {
|
|
|
31
31
|
let e = D.current;
|
|
32
32
|
if (e) {
|
|
33
33
|
if (typeof navigator > "u" || !navigator.geolocation) {
|
|
34
|
-
|
|
34
|
+
w({
|
|
35
35
|
title: v("healthybowl.weather.map.toast.locationUnsupported.title", "Location unavailable"),
|
|
36
36
|
description: v("healthybowl.weather.map.toast.locationUnsupported.description", "This browser does not support device location."),
|
|
37
37
|
variant: "warning"
|
|
@@ -56,7 +56,7 @@ var T = ({ location: e, center: n }) => {
|
|
|
56
56
|
}).addTo(e), e.flyTo(n, Math.max(e.getZoom(), x), { duration: .75 }), L(!1);
|
|
57
57
|
}, (e) => {
|
|
58
58
|
let t = e.code === e.PERMISSION_DENIED;
|
|
59
|
-
|
|
59
|
+
w({
|
|
60
60
|
title: t ? v("healthybowl.weather.map.toast.locationBlocked.title", "Location blocked") : v("healthybowl.weather.map.toast.locationFailed.title", "Could not get location"),
|
|
61
61
|
description: t ? v("healthybowl.weather.map.toast.locationBlocked.description", "Allow location access in the browser, then try again.") : v("healthybowl.weather.map.toast.locationFailed.description", "Make sure GPS is enabled and the page is open over HTTPS."),
|
|
62
62
|
variant: "warning"
|
|
@@ -70,24 +70,24 @@ var T = ({ location: e, center: n }) => {
|
|
|
70
70
|
}, [
|
|
71
71
|
Q,
|
|
72
72
|
v,
|
|
73
|
-
|
|
73
|
+
w
|
|
74
74
|
]), ie = a(async (e) => {
|
|
75
75
|
e.preventDefault();
|
|
76
|
-
let
|
|
77
|
-
if (!
|
|
78
|
-
|
|
76
|
+
let n = D.current, r = R.trim();
|
|
77
|
+
if (!r) {
|
|
78
|
+
w({
|
|
79
79
|
title: v("healthybowl.weather.map.toast.searchRequired.title", "Place required"),
|
|
80
80
|
description: v("healthybowl.weather.map.toast.searchRequired.description", "Enter a city, village, district, or region to view it on the map."),
|
|
81
81
|
variant: "warning"
|
|
82
82
|
});
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
85
|
+
if (n) {
|
|
86
86
|
V(!0);
|
|
87
87
|
try {
|
|
88
|
-
let e = await r
|
|
88
|
+
let e = await t(r);
|
|
89
89
|
if (!e) {
|
|
90
|
-
|
|
90
|
+
w({
|
|
91
91
|
title: v("healthybowl.weather.map.toast.searchNotFound.title", "Place not found"),
|
|
92
92
|
description: v("healthybowl.weather.map.toast.searchNotFound.description", "Try a more specific location name, such as city and state."),
|
|
93
93
|
variant: "warning"
|
|
@@ -98,7 +98,7 @@ var T = ({ location: e, center: n }) => {
|
|
|
98
98
|
e.name,
|
|
99
99
|
e.admin1,
|
|
100
100
|
e.country
|
|
101
|
-
].filter(Boolean).join(", ") ||
|
|
101
|
+
].filter(Boolean).join(", ") || r, a = [e.latitude, e.longitude];
|
|
102
102
|
$();
|
|
103
103
|
let o = document.createElement("span");
|
|
104
104
|
o.textContent = i, j.current = _.default.circleMarker(a, {
|
|
@@ -107,9 +107,9 @@ var T = ({ location: e, center: n }) => {
|
|
|
107
107
|
weight: 2,
|
|
108
108
|
fillColor: "#0ea5e9",
|
|
109
109
|
fillOpacity: 1
|
|
110
|
-
}).addTo(
|
|
110
|
+
}).addTo(n).bindPopup(o).openPopup(), n.flyTo(a, Math.max(n.getZoom(), S), { duration: .75 }), U(i);
|
|
111
111
|
} catch (e) {
|
|
112
|
-
|
|
112
|
+
w({
|
|
113
113
|
title: v("healthybowl.weather.map.toast.searchFailed.title", "Search failed"),
|
|
114
114
|
description: e instanceof Error ? e.message : String(e),
|
|
115
115
|
variant: "error"
|
|
@@ -122,21 +122,21 @@ var T = ({ location: e, center: n }) => {
|
|
|
122
122
|
$,
|
|
123
123
|
R,
|
|
124
124
|
v,
|
|
125
|
-
|
|
125
|
+
w
|
|
126
126
|
]);
|
|
127
127
|
return o(() => {
|
|
128
|
-
let
|
|
129
|
-
if (!
|
|
130
|
-
|
|
131
|
-
let
|
|
128
|
+
let n = E.current;
|
|
129
|
+
if (!n) return;
|
|
130
|
+
ee();
|
|
131
|
+
let r = new AbortController(), i, a = !1;
|
|
132
132
|
return N("loading"), F(!1), G(null), U(null), O.current = null, (async () => {
|
|
133
133
|
let o = X !== null && Z !== null ? {
|
|
134
134
|
lat: X,
|
|
135
135
|
lng: Z
|
|
136
|
-
} : null, s = o ? null : await
|
|
136
|
+
} : null, s = o ? null : await t(e, r.signal), c = o ? [o.lat, o.lng] : s ? [s.latitude, s.longitude] : null;
|
|
137
137
|
if (a || !E.current) return;
|
|
138
138
|
let l = c ?? [20, 0], u = c ? b : 2;
|
|
139
|
-
O.current = c ? _.default.latLng(c[0], c[1]) : null, F(!!c), i = _.default.map(
|
|
139
|
+
O.current = c ? _.default.latLng(c[0], c[1]) : null, F(!!c), i = _.default.map(n, {
|
|
140
140
|
center: l,
|
|
141
141
|
zoom: u,
|
|
142
142
|
scrollWheelZoom: !0
|
|
@@ -163,21 +163,21 @@ var T = ({ location: e, center: n }) => {
|
|
|
163
163
|
n.textContent = e || "Your farm", _.default.marker(l, { icon: t }).addTo(i).bindPopup(n);
|
|
164
164
|
}
|
|
165
165
|
try {
|
|
166
|
-
let e = await (await fetch("https://api.rainviewer.com/public/weather-maps.json", { signal:
|
|
167
|
-
if (!a && i && e.host &&
|
|
168
|
-
let t = _.default.tileLayer(`${e.host}${
|
|
166
|
+
let e = await (await fetch("https://api.rainviewer.com/public/weather-maps.json", { signal: r.signal })).json(), t = e.radar?.past ?? [], n = t[t.length - 1];
|
|
167
|
+
if (!a && i && e.host && n?.path) {
|
|
168
|
+
let t = _.default.tileLayer(`${e.host}${n.path}/256/{z}/{x}/{y}/4/1_1.png`, {
|
|
169
169
|
opacity: .55,
|
|
170
170
|
maxZoom: 18,
|
|
171
171
|
maxNativeZoom: 7
|
|
172
172
|
}).addTo(i);
|
|
173
|
-
p.addOverlay(t, J), typeof
|
|
173
|
+
p.addOverlay(t, J), typeof n.time == "number" && G(/* @__PURE__ */ new Date(n.time * 1e3));
|
|
174
174
|
}
|
|
175
175
|
} catch {}
|
|
176
176
|
a || (N("ready"), window.setTimeout(() => i?.invalidateSize(), 80));
|
|
177
177
|
})().catch(() => {
|
|
178
178
|
a || N("error");
|
|
179
179
|
}), () => {
|
|
180
|
-
a = !0,
|
|
180
|
+
a = !0, r.abort(), Q(), $(), i?.remove(), D.current = null, O.current = null;
|
|
181
181
|
};
|
|
182
182
|
}, [
|
|
183
183
|
X,
|
|
@@ -288,14 +288,14 @@ var T = ({ location: e, center: n }) => {
|
|
|
288
288
|
})}` : ""
|
|
289
289
|
]
|
|
290
290
|
}),
|
|
291
|
-
/* @__PURE__ */ m(
|
|
291
|
+
/* @__PURE__ */ m(n, {
|
|
292
292
|
toasts: y,
|
|
293
|
-
onDismiss:
|
|
293
|
+
onDismiss: T
|
|
294
294
|
})
|
|
295
295
|
]
|
|
296
296
|
});
|
|
297
297
|
};
|
|
298
298
|
//#endregion
|
|
299
|
-
export {
|
|
299
|
+
export { w as WeatherMap };
|
|
300
300
|
|
|
301
301
|
//# sourceMappingURL=WeatherMap.js.map
|