rajkhanke commited on
Commit
6edf2b5
·
verified ·
1 Parent(s): 435b886

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +37 -3
templates/index.html CHANGED
@@ -123,6 +123,14 @@
123
  </div>
124
  </div>
125
 
 
 
 
 
 
 
 
 
126
  <!-- Additional Agricultural Inputs -->
127
  <div class="form-section">
128
  <h4 class="text-2xl font-semibold mb-4">Additional Agricultural Inputs</h4>
@@ -234,8 +242,10 @@
234
  attribution: 'Tiles © Esri',
235
  maxZoom: 18,
236
  }).addTo(map);
 
237
  // Explicitly define the geocoder provider using Nominatim
238
  var geocoder = L.Control.Geocoder.nominatim();
 
239
  // Add geocoder (search bar) to the map with the provider
240
  L.Control.geocoder({
241
  geocoder: geocoder,
@@ -248,6 +258,7 @@
248
  setMarker(center);
249
  })
250
  .addTo(map);
 
251
  var marker;
252
  function setMarker(latlng) {
253
  if (marker) {
@@ -260,13 +271,16 @@
260
  document.getElementById('longitude').value = latlng.lng.toFixed(6);
261
  document.getElementById('manual_lat').value = latlng.lat.toFixed(6);
262
  document.getElementById('manual_lon').value = latlng.lng.toFixed(6);
 
263
  // Fetch weather and soil data
264
  fetchWeatherData(latlng.lat, latlng.lng);
265
  fetchSoilProperties(latlng.lat, latlng.lng);
266
  }
 
267
  map.on('click', function(e) {
268
  setMarker(e.latlng);
269
  });
 
270
  // Update location using manual input
271
  document.getElementById('updateLocationBtn').addEventListener('click', function(){
272
  const lat = parseFloat(document.getElementById('manual_lat').value);
@@ -279,9 +293,10 @@
279
  alert("Please enter valid latitude and longitude values.");
280
  }
281
  });
 
282
  // Fetch weather data from backend (/get_weather_data)
283
  function fetchWeatherData(lat, lng) {
284
- fetch(/get_weather_data?lat=${lat}&lon=${lng})
285
  .then(response => response.json())
286
  .then(data => {
287
  // Update the weather card container
@@ -320,6 +335,7 @@
320
  <div>${data.cloud_cover !== null ? data.cloud_cover.toFixed(1) + " %" : "Not available"}</div>
321
  </div>
322
  `;
 
323
  // Also store these values in hidden fields so they pass to Gemini
324
  document.getElementById('max_temp_hidden').value = data.max_temp ?? "";
325
  document.getElementById('min_temp_hidden').value = data.min_temp ?? "";
@@ -332,7 +348,25 @@
332
  })
333
  .catch(error => console.error('Error fetching weather data:', error));
334
  }
335
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  </script>
337
  </body>
338
- </html>
 
123
  </div>
124
  </div>
125
 
126
+ <!-- Soil Data Section -->
127
+ <div class="form-section" id="soilPropertiesTable">
128
+ <h4 class="text-2xl font-semibold mb-4">Soil Nutrient Parameters</h4>
129
+ <div id="soilTableContainer">
130
+ <p class="text-center text-gray-600">Fetching soil data...</p>
131
+ </div>
132
+ </div>
133
+
134
  <!-- Additional Agricultural Inputs -->
135
  <div class="form-section">
136
  <h4 class="text-2xl font-semibold mb-4">Additional Agricultural Inputs</h4>
 
242
  attribution: 'Tiles © Esri',
243
  maxZoom: 18,
244
  }).addTo(map);
245
+
246
  // Explicitly define the geocoder provider using Nominatim
247
  var geocoder = L.Control.Geocoder.nominatim();
248
+
249
  // Add geocoder (search bar) to the map with the provider
250
  L.Control.geocoder({
251
  geocoder: geocoder,
 
258
  setMarker(center);
259
  })
260
  .addTo(map);
261
+
262
  var marker;
263
  function setMarker(latlng) {
264
  if (marker) {
 
271
  document.getElementById('longitude').value = latlng.lng.toFixed(6);
272
  document.getElementById('manual_lat').value = latlng.lat.toFixed(6);
273
  document.getElementById('manual_lon').value = latlng.lng.toFixed(6);
274
+
275
  // Fetch weather and soil data
276
  fetchWeatherData(latlng.lat, latlng.lng);
277
  fetchSoilProperties(latlng.lat, latlng.lng);
278
  }
279
+
280
  map.on('click', function(e) {
281
  setMarker(e.latlng);
282
  });
283
+
284
  // Update location using manual input
285
  document.getElementById('updateLocationBtn').addEventListener('click', function(){
286
  const lat = parseFloat(document.getElementById('manual_lat').value);
 
293
  alert("Please enter valid latitude and longitude values.");
294
  }
295
  });
296
+
297
  // Fetch weather data from backend (/get_weather_data)
298
  function fetchWeatherData(lat, lng) {
299
+ fetch(`/get_weather_data?lat=${lat}&lon=${lng}`)
300
  .then(response => response.json())
301
  .then(data => {
302
  // Update the weather card container
 
335
  <div>${data.cloud_cover !== null ? data.cloud_cover.toFixed(1) + " %" : "Not available"}</div>
336
  </div>
337
  `;
338
+
339
  // Also store these values in hidden fields so they pass to Gemini
340
  document.getElementById('max_temp_hidden').value = data.max_temp ?? "";
341
  document.getElementById('min_temp_hidden').value = data.min_temp ?? "";
 
348
  })
349
  .catch(error => console.error('Error fetching weather data:', error));
350
  }
351
+
352
+ // Fetch soil properties from backend (/get_soil_properties)
353
+ function fetchSoilProperties(lat, lng) {
354
+ fetch(`/get_soil_properties?lat=${lat}&lon=${lng}`)
355
+ .then(response => response.json())
356
+ .then(data => {
357
+ if(data.soil_properties) {
358
+ let tableHTML = "<table><thead><tr><th>Parameter</th><th>Value</th><th>Unit</th></tr></thead><tbody>";
359
+ data.soil_properties.forEach(function(item) {
360
+ tableHTML += `<tr><td>${item[0]}</td><td>${item[1]}</td><td>${item[2]}</td></tr>`;
361
+ });
362
+ tableHTML += "</tbody></table>";
363
+ document.getElementById("soilTableContainer").innerHTML = tableHTML;
364
+ } else {
365
+ document.getElementById("soilTableContainer").innerHTML = "<p class='text-center text-gray-600'>No soil data available.</p>";
366
+ }
367
+ })
368
+ .catch(error => console.error('Error fetching soil properties:', error));
369
+ }
370
  </script>
371
  </body>
372
+ </html>