Skip to content

Commit b4bf7cd

Browse files
committed
Organic carbon relation added
1 parent 47aee13 commit b4bf7cd

5 files changed

Lines changed: 147 additions & 5 deletions

File tree

SedimentDataExplorer.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ <h2>Select Chemicals</h2>
203203
<label for="relationhc">Total hydrocarbons</label>
204204
<input type="checkbox" id="relationtotalsolids" checked>
205205
<label for="relationtotalsolids">Total solids</label>
206+
<input type="checkbox" id="relationorganiccarbon" checked>
207+
<label for="relationorganiccarbon">Organic Carbon</label>
206208
</div>
207209
<div>
208210
Resuspension -
@@ -287,6 +289,14 @@ <h2>Select Chemicals</h2>
287289
<button onclick="importLocations()">Import Locations</button>
288290
</div>
289291

292+
<div>
293+
Shape files -
294+
<input type="file" id="fileShapes" multiple> <!-- Allow multiple file selection -->
295+
<input type="text" id="urlShapes" placeholder="Enter comma-separated URLs">
296+
<!-- Accept comma-separated URLs -->
297+
<button onclick="importShapes()">Import shape files (kml)</button>
298+
</div>
299+
290300
<div>
291301
ChemInfo files
292302
<input type="file" id="fileChemInfo" multiple> <!-- Allow multiple file selection -->

SedimentDataExplorer.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let testOne = {};
22
let radarPlot = "None";
33
let resuspensionSize = 0;
4+
let kmlLayers = {};
45
// import {parse, stringify, toJSON, fromJSON} from 'flatted';
56
const autocolors = window['chartjs-plugin-autocolors'];
67
Chart.register(autocolors);
@@ -61,7 +62,7 @@
6162
completeSheet[sheetName] = true;
6263
})*/
6364
subChartNames = ['samplegroup','chemicalgroup','positionplace','gorhamtest','totalhc','pahratios','ringfractions','eparatios','simpleratios','congenertest',
64-
'relationareadensity','relationhc','relationtotalsolids'];
65+
'relationareadensity','relationhc','relationtotalsolids','relationorganiccarbon'];
6566
// relationNames = ['relationareadensity','relationhc','relationtotalsolids'];
6667
subsToDisplay = {};
6768
for (i = 0; i < subChartNames.length; i++) {
@@ -77,7 +78,7 @@
7778
...subChartNames.filter(option => option.includes('pah') || option.includes('hc') || option.includes('gorham') || option.includes('ratios')
7879
|| option.includes('ring') || option.includes('totalhc'))];
7980
sortButtonGroups['Physical Data'] = [...sortingOptions.filter(option => option.includes('silt') || option.includes('sand') || option.includes('area') || option.includes('gravel')),
80-
...subChartNames.filter(option => option.includes('area') || option.includes('solid'))];
81+
...subChartNames.filter(option => option.includes('area') || option.includes('solid') || option.includes('organic'))];
8182
// ...relationNames.filter(option => option.includes('area') || option.includes('solid'))];
8283
for (group in sortButtonGroups) {
8384
//console.log(group);
@@ -545,6 +546,74 @@ console.log('importChemInfo');
545546
urlInput.value = '';
546547
}
547548

549+
function importShapes() {
550+
urls = {};
551+
if (firstTime) {
552+
firstTime = false;
553+
files = {};
554+
// Get the current URL
555+
const currentURL = window.location.href;
556+
557+
// Parse the URL to get the search parameters
558+
const suppliedParams = new URLSearchParams(window.location.search);
559+
560+
// Get the value of the 'locations' parameter
561+
const shapesParam = suppliedParams.get('shapes');
562+
if (!shapesParam) {
563+
return;
564+
} else {
565+
urls = shapesParam.split(',').map(url => url.trim()); // Split comma-separated URLs
566+
}
567+
} else {
568+
const fileInput = document.getElementById('fileShapes');
569+
const urlInput = document.getElementById('urlShapes');
570+
const files = fileInput.files; // Files is now a FileList object containing multiple files
571+
urls = urlInput.value.trim().split(',').map(url => url.trim()); // Split comma-separated URLs
572+
573+
if (files.length === 0 && urls.length === 0) {
574+
alert('Please select files or enter URLs.');
575+
return;
576+
}
577+
// Process files
578+
for (let i = 0; i < files.length; i++) {
579+
filename = files[i].name;
580+
const reader = new FileReader();
581+
reader.onload = function (e) {
582+
const data = new Uint8Array(e.target.result);
583+
processExcelLocations(data,filename);
584+
};
585+
reader.readAsArrayBuffer(files[i]);
586+
}
587+
}
588+
// Process URLs only if URLs are supplied
589+
if (urls.length > 0) {
590+
urls.forEach(url => {
591+
// Check if the URL is a valid URL before fetching
592+
if (!/^https?:\/\//i.test(url)) {
593+
console.error('Invalid URL:', url);
594+
return;
595+
}
596+
const filename = url.split('/').pop();
597+
console.log(filename); // Output: MLA_2015_00088-LOCATIONS.kml
598+
//"https://northeastfc.uk/RiverTees/Planning/MLA_2015_00088/MLA_2015_00088-LOCATIONS.kml"
599+
// kmlLayers[filename] = new L.KML(url, {async: true});
600+
kmlLayers[filename] = url;
601+
602+
/* fetch(url)
603+
.then(response => response.arrayBuffer())
604+
.then(data => {
605+
processExcelLocations(new Uint8Array(data),url);
606+
})
607+
.catch(error => {
608+
console.error('Error fetching the locations file:', error);
609+
});*/
610+
});
611+
}
612+
// Clear the input field after reading locations
613+
fileInput.value = '';
614+
urlInput.value = '';
615+
}
616+
548617
function processExcelLocations(data,url) {
549618
// Based on simple Excel data in first sheet
550619
// row 1 column titles

sdeCalcs4Charts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ function dataForTotalScatterCharting(sheetName, chartType) {
350350
xValue = sampleMeasurements[ds]['Physical Data'].samples[s]['Total solids (% total sediment)'];
351351
break;
352352

353+
case "organicCarbon":
354+
xValue = sampleMeasurements[ds]['Physical Data'].samples[s]['Organic matter (total organic carbon)'];
355+
break;
356+
353357
default:
354358
console.error(`Unknown chart type: ${chartType}`);
355359
return;

sdeCharts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ fred=selectedMeas;
282282
'chartContainer',
283283
instanceNo
284284
);
285+
286+
instanceNo = displayScatterCharts(sheetName,
287+
{ key: 'organicCarbon', sheetKey: 'Physical Data' },
288+
'relationorganiccarbon',
289+
'Organic Carbon %',
290+
'Concentration',
291+
'chartContainer',
292+
instanceNo
293+
);
294+
295+
296+
285297
// }
286298

287299
if (sheetName == 'PAH data' && Object.keys(chemInfo).length != 0) {

sdeMaps.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,12 @@ console.log(dateSampled,markerLayers[dateSampled]);
346346
//console.log(markerLayer,markerLayers);
347347

348348

349-
var kmlLayer = new L.KML("https://northeastfc.uk/RiverTees/Planning/MLA_2015_00088/MLA_2015_00088-LOCATIONS.kml", {async: true});
350-
//console.log(kmlLayer);
349+
/* var kmlLayer = new L.KML("https://northeastfc.uk/RiverTees/Planning/MLA_2015_00088/MLA_2015_00088-LOCATIONS.kml", {async: true});
350+
console.log(kmlLayer);
351+
for (filename in kmlLayers) {
352+
kmlLayer = kmlLayers[filename];
353+
}
354+
console.log(kmlLayer);
351355
kmlLayer.on("loaded", function(e) {
352356
map.fitBounds(e.target.getBounds());
353357
fred = kmlLayer;
@@ -369,10 +373,53 @@ fred = kmlLayer;
369373
}
370374
});
371375
//console.log(markers,markerLayers);
372-
var shapeOverlay = {'MLA/2015/00088' : kmlLayer};
376+
// var shapeOverlay = {'MLA/2015/00088' : kmlLayer};
377+
var shapeOverlay = {'MLA_2015_00088-LOCATIONS.kml' : kmlLayer};
378+
datesSampled.forEach(dateSampled => {
379+
shapeOverlay[dateSampled] = markerLayer[dateSampled];
380+
});*/
381+
382+
var shapeOverlay = {};
383+
let kmlColors = [];
384+
kmlColors[0] = '#FF0000';
385+
kmlColors[1] = '#00FF00';
386+
kmlColors[2] = '#0000FF';
387+
colorNo = 0;
388+
389+
for (filename in kmlLayers) {
390+
url = kmlLayers[filename];
391+
kmlLayer = new L.KML(url, {async: true});
392+
kmlLayer.on("loaded", function (e) {
393+
// map.fitBounds(e.target.getBounds());
394+
// Access nested layers and apply styles
395+
const mainLayer = Object.values(e.target._layers)[0];
396+
if (mainLayer && mainLayer._layers) {
397+
Object.values(mainLayer._layers).forEach(function (layer) {
398+
if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
399+
layer.setStyle({
400+
color: kmlColors[colorNo], // Set line color to red
401+
weight: 2, // Set line thickness
402+
opacity: 0.5, // Set line opacity
403+
fillColor: kmlColors[colorNo], // Set fill color to red
404+
fillOpacity: 0.2 // Set fill opacity for polygons
405+
});
406+
}
407+
});
408+
}
409+
if (colorNo < 2) {
410+
colorNo += 1;
411+
} else {
412+
colorNo = 0;
413+
}
414+
});
415+
shapeOverlay[filename] = kmlLayer;
416+
}
373417
datesSampled.forEach(dateSampled => {
374418
shapeOverlay[dateSampled] = markerLayer[dateSampled];
375419
});
420+
421+
422+
376423
//console.log(shapeOverlay,mapLayers);
377424
if (noLocations > 0) {
378425
const centreLat = latSum / noLocations;

0 commit comments

Comments
 (0)