Skip to content

Commit

Permalink
cleanup commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrigby committed May 17, 2022
1 parent 01d1d70 commit dcb51a8
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 1,288 deletions.
52 changes: 0 additions & 52 deletions js/Superseeded code.txt

This file was deleted.

141 changes: 8 additions & 133 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,28 @@ import { populateTable, cleanHru, getHru, updateHru, getHruData } from "/js/modu
import { getPlantOptions, cleanPlant, newPlantType, getSwatPlantList, getPlantData } from "/js/modules/plantFunctions.js";
import { cleanLanduse, getLanduseTypes, landuseTypes, getConsPractice, getCurveNumer, getManN, getUrbanList, getTileDrain, getSepticData, getFilterStrip, getGrassedWw } from "/js/modules/landuseFunctions.js";
import { updateTooltips, makeSatelliteMap, shpToGeoJSON, makeStreetMap, onMapSelection, makeOutdoorsMap, makeOsMap } from "/js/modules/mapFunctions.js";
import { hydrograph, scenarioOptions, getHydrographOptions, getHydrographOutputOptions} from "/js/modules/outputVisFunctions.js";
import { hydrograph, scenarioOptions, getHydrographOptions, getHydrographOutputOptions } from "/js/modules/outputVisFunctions.js";
// import { timeSim, printPrt } from "/js/modules/modelFunctions.js";
import { choropleth, getChoroplethOptions } from "/js/modules/choroplethFunctions.js";
import { getLanduseData } from "/js/modules/landuseFunctions.js";

const dev = new URL(window.location).searchParams.get('dev') === '1';
export const HOST = dev ? 'localhost' : '5.67.118.6';
//run for dev with ?dev=1
//if ipv4 chnage change value
// console.log('test');

(async () => {
console.log('domcontent loaded')


// TRYING TO ZIP SHAPE FILES----- UNFINISHED

// async function downloadButton(data, fileName) {
// var myFile = new Blob([data], { type: 'blob' });
// document.getElementById('downloadLanduse').setAttribute('href', window.URL.createObjectURL(myFile));
// document.getElementById('downloadLanduse').setAttribute('download', fileName);
// }

// const hru2Shp = '/data/hru2/hrus2.shp';
// // Fetch the image and parse the response stream as a blob
// const hru2ShpBlob = fetch(hru2Shp).then(response => response.blob());

// // create a new file from the blob object
// const hru2ShpFile = new File([hru2ShpBlob], "hrus2.shp");

// let zip = new JSZip();
// let hruFolder = zip.folder('hru2');
// hruFolder.file( "hru2.shp",hru2ShpFile);
// console.log(hruFolder)


// // hruFolder.generateAsync({ type: "blob" }).then(content => saveAs(content, "files"));

// downloadButton(hruFolder, "hru2")


//import upload from "/js/modules/upload.js";

// Has the page loaded fully yet?
window.init = false;

// printPrt()
// timeSim()
await getHydrographOutputOptions()
await getHydrographOutputOptions()
await getHydrographOptions()
await getChoroplethOptions()
await scenarioOptions()

await getPlantData('Default')
await getLanduseData('Default')

// graphTab()
await choropleth('Default')
await getSwatPlantList('Default')
await getUrbanList('Default')
Expand All @@ -72,65 +37,9 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
await getGrassedWw('Default')

await hydrograph('Default')

//hides the hruTable by default
document.getElementById("hruTable").style.display = "none";
// getLanduseData(window.currentScenario)
// getPlantData(window.currentScenario)
// // graphTab()
// choropleth(window.currentScenario)
// getSwatPlantList(window.currentScenario)
// getSwatUrbanPlantList(window.currentScenario)
// getConsPractice(window.currentScenario)
// getCurveNumer(window.currentScenario)
// getManN(window.currentScenario)




// hru-data.hru:
// Fetch unclean dataset...

// fetchData('/catchment/Scenarios/Default/TxtInOut/hru-data.hru')
// .then(data => {
// // Clean the dataset...
// const cleanHruData = cleanHru(data);

// // Saving a copy of the dataset
// const cleanHruDataCopy = [...cleanHruData];

// // Replace this with a state management solution
// window.catchmentData = [...cleanHruData];
// console.log(window.catchmentData)
// });



// landuse.lum:
// Fetch unclean dataset...
// fetchData('/catchment/Scenarios/Default/TxtInOut/landuse.lum')
// .then(data => {
// const cleanLanduseData = cleanLanduse(data);
// const cleanLanduseDataCopy = [...cleanLanduseData];
// const landuseTypes = getLanduseTypes(cleanLanduseData);
// window.catchmentLanduse = [...landuseTypes];
// window.catchmentLanduseEdit = [...cleanLanduseData];

// });



// // plant.ini:
// // Fetch unclean dataset...
// fetchData('/catchment/Scenarios/Default/TxtInOut/plant.ini')
// .then(data => {
// const cleanPlantData = cleanPlant(data);
// const cleanPlantDataCopy = [...cleanPlantData];
// window.catchmentPlant = [...cleanPlantData];

// });




var rivers = await shpToGeoJSON('catchment/Watershed/Shapes/rivs1.zip')
Expand All @@ -140,7 +49,6 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
//gets the coordinates of hru1 and returns it to use as the starting center for leaflet map
const coordinates = await shp('catchment/Watershed/Shapes/hrus2.zip')
const HRU1Coordinates = coordinates.features[0].geometry.bbox.slice(1, 3)
// console.log(HRU1Coordinates)



Expand All @@ -150,14 +58,9 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
var satellite = makeSatelliteMap();
var streets = makeStreetMap().addTo(map);
var outdoors = makeOutdoorsMap()
// var os = makeOsMap()
//calling function from mapFunctions.js to convert the ziped shape files into geoJSON files
// only add HRUs2 (1 is 'Actual HRUs')

await getHruData('Default')



function shpStyles() {
hrus.setStyle({ color: '#b0c4de', weight: 1 });
rivers.setStyle({ color: '#0068C1' });
Expand Down Expand Up @@ -200,12 +103,6 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
"Sub-Basins": subBasins
};


// hrus.on('layeradd', function (e) {
// var latLong = e.layer.getLatLng()
// console.log(latLong)
// })

//leaflets.js function to add layers to map with a drop down selection list
L.control.layers(baseMaps, overlayMaps).addTo(map);

Expand Down Expand Up @@ -252,21 +149,19 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';

layers.forEach(layer => {
if (layer.feature?.properties?.HRUS) {
if (layer instanceof L.Marker) {
layer.setIcon(new L.Icon.Default({ className: 'selected ' }));
} else if (layer instanceof L.Path) {
layer.setStyle({ color: '#ff4620' });
if (layer instanceof L.Marker) {
layer.setIcon(new L.Icon.Default({ className: 'selected ' }));
} else if (layer instanceof L.Path) {
layer.setStyle({ color: '#ff4620' });
}
}
}
});

var hrus = onMapSelection(layers)


await populateTable(hrus)
document.getElementById("hruTable").style.display = "block";
//console.log(hrus)
//lassoResult.innerHTML = layers.length ? `Selected ${layers.length} layers` : '';
}


Expand All @@ -292,13 +187,6 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
});


// const lulcEditButtons = document.querySelectorAll(".lulc-edit-button");

// lulcEditButtons.forEach((el, i, arr) => {
// el.addEventListener("click", () => {
// updateTooltips()
// })
// })
document.getElementById("link").addEventListener('click', () => {
console.log(document.getElementById("myFile").value)
}
Expand All @@ -310,7 +198,6 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';


//creats the upload popup
// document.getElementById("uploadButton").onmousedown = openUploadForm;
document.getElementById("popupClose").onmousedown = closeUploadForm;
function openUploadForm() {
document.getElementById("upload").style.display = "block";
Expand All @@ -320,16 +207,6 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';
}



//populatePlantTypeForm()


// Scenario Management
// window.currentScenario = "Default";




updateCurrentScenario('Default');


Expand Down Expand Up @@ -388,13 +265,11 @@ export const HOST = dev ? 'localhost' : '5.67.118.6';

const createNewScenarioButton = document.getElementById("createNewScenario");
createNewScenarioButton.addEventListener("click", async function (e) {
// console.log(window.currentScenarioVersion)
e.preventDefault();
let newScenarioVersion = window.currentScenarioVersion;
console.log(newScenarioVersion)
let newScenario = prompt("Enter name of new scenario", "Scenario " + `${newScenarioVersion}`);

// Escape hatch
if (newScenario === null) return;

let scenarioList = null;
Expand Down
Loading

0 comments on commit dcb51a8

Please sign in to comment.