From c7252a30d0489bff6cdf6984dc90b5d29ce9f520 Mon Sep 17 00:00:00 2001
From: Lene Wasskog <lene.wasskog@nibio.no>
Date: Tue, 22 Oct 2024 14:51:32 +0200
Subject: [PATCH] feat: Ensure that changes in coordinate input fields are
 reflected in map

---
 .../barleynetblotchform.html                  | 37 +++++++++++--------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html b/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html
index 03f5b297..efa1bea5 100755
--- a/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html
+++ b/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html
@@ -211,22 +211,6 @@
 			inputLatitudeElement.value = selectedLatitude;
 			inputLongitudeElement.value = selectedLongitude;
 		}
-
-		selectedPoint = 1;
-        selectedFeature = { 
-			"type": "FeatureCollection", "features": [
-				{
-					"type": "Feature",
-					"geometry": {
-						"type": "Point",
-						"coordinates": [selectedLongitude, selectedLatitude]
-					},
-					"properties": {
-						"pointOfInterestId": selectedPoint,
-						"pointOfInterestName": coordinatesData.name,
-					}
-		        }]
-		};
 	}
 
 	function selectPoi(poiData) {
@@ -244,6 +228,27 @@
 	}
 
 	window.openCoordinatesMap = () => {
+		if (inputLatitudeElement.value && inputLongitudeElement.value) {
+			selectedPoint = 1;
+			selectedFeature = { 
+				"type": "FeatureCollection", "features": [
+					{
+						"type": "Feature",
+						"geometry": {
+							"type": "Point",
+							"coordinates": [parseFloat(inputLongitudeElement.value), parseFloat(inputLatitudeElement.value)]
+						},
+						"properties": {
+							"pointOfInterestId": selectedPoint,
+							"pointOfInterestName": "Punkt",
+						}
+					}]
+			};
+		} else {
+			selectedPoint = undefined;
+			selectedFeature = undefined;
+		}
+
 		const coordinatesMapInstance = new MapModal('coordinates-map', {}, selectedFeature, 'nb', true, selectCoordinates);
 		coordinatesMapInstance.openModal(selectedPoint);
 	}
-- 
GitLab