-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Modularization and UI changes #4
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
swe_site/ | ||
│ | ||
├── src/ | ||
│ ├── index.html # Main HTML file | ||
│ ├── styles/ # CSS files | ||
│ │ ├── styles.css # Main stylesheet | ||
│ ├── scripts/ # JavaScript logic and modules | ||
│ │ ├── index.js # Main entry point (initialization logic) | ||
│ │ ├── utils.js # Utility functions (e.g., copyCoordinates, helpers) | ||
│ │ ├── map.js # MapHandler class and map-related logic | ||
│ │ ├── datepicker.js # Functions for setting up the datepicker | ||
│ │ ├── geotiff.js # Logic for adding GeoTIFF layers to the map | ||
│ │ ├── legend.js # Logic for adding a map legend | ||
│ │ ├── events.js # Event listeners for buttons and map interactions | ||
│ | ||
├── data/ # Data files | ||
│ ├── us-states.json # GeoJSON data for state boundaries | ||
│ ├── date_list.csv # CSV file containing available dates |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>SWE Forecast Map</title> | ||
<!-- Leaflet CSS --> | ||
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> | ||
<!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | ||
<!-- Bootstrap Datepicker CSS --> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css"> | ||
<!-- Custom CSS --> | ||
<link rel="stylesheet" href="./styles/styles.css"> | ||
</head> | ||
<body> | ||
<!-- Header Section --> | ||
<header class="header"> | ||
<h3>Snow Water Equivalent Estimation Map</h3> | ||
<p class="subtitle">A Project by the SnowSource Team</p> | ||
</header> | ||
<p>hello world!!</p> | ||
|
||
<!-- Control Panel --> | ||
<div id="control-panel" class="control-panel-horizontal"> | ||
<div class="form-group"> | ||
<label id ="datepicker" for="datepicker">Select Date:</label> | ||
<input type="text" id="datepicker"> | ||
<button id="load_swe_to_map" class="btn btn-primary">Load SWE Prediction</button> | ||
<button id="download_swe_geotiff" class="btn btn-secondary">Download SWE Prediction (GeoTiff)</button> | ||
</div> | ||
<div class="map-views"> | ||
<button type="button" class="btn btn-outline-primary">single map</button> | ||
<button type="button" class="btn btn-outline-primary">swipe map</button> | ||
<button type="button" class="btn btn-outline-primary">dual map</button> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
<!-- Map Container --> | ||
<div id="map"></div> | ||
|
||
|
||
|
||
<!-- Leaflet JS --> | ||
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> | ||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script> | ||
<script src="./scripts/index.js" type="module"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function setup_datepicker(dateArray){ | ||
$('#datepicker').datepicker({ | ||
format: 'yyyy-mm-dd', | ||
todayHighlight: true, | ||
timeZone: 'America/Los_Angeles', | ||
autoclose: true, | ||
beforeShowDay: function(date) { | ||
// Convert date to yyyy-mm-dd format | ||
var formattedDate = date.getFullYear() + '-' + | ||
('0' + (date.getMonth() + 1)).slice(-2) + '-' + | ||
('0' + date.getDate()).slice(-2); | ||
|
||
// Check if the date is in the dateArray | ||
return dateArray.includes(formattedDate); | ||
} | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function setupEventListeners(map, layerControl) { | ||
// Listener for SWE map loading button | ||
$("#load_swe_to_map").on("click", function () { | ||
const selectedDate = $("#datepicker").datepicker("getFormattedDate"); | ||
console.log(`Loading SWE prediction for: ${selectedDate}`); | ||
addGeoTIFF(map, layerControl, selectedDate); | ||
}); | ||
|
||
// Listener for SWE GeoTIFF download button | ||
$("#download_swe_geotiff").on("click", function () { | ||
const selectedDate = $("#datepicker").datepicker("getFormattedDate"); | ||
console.log(`Downloading GeoTIFF for: ${selectedDate}`); | ||
window.open(`../swe_forecasting/output/swe_predicted_${selectedDate}.tif`, "_blank"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function add_swe_predicted_geotiff(map, layerControl, date) { | ||
if (!date) { | ||
console.error("Date is required to load GeoTIFF."); | ||
return; | ||
} | ||
|
||
const wmslayer = L.tileLayer.wms( | ||
`http://geobrain.csiss.gmu.edu/cgi-bin/mapserv?map=/var/www/html/swe_forecasting/map/swe_predicted_${date}.tif.map&`, | ||
{ | ||
layers: "swemap", | ||
format: "image/png", | ||
transparent: true, | ||
} | ||
); | ||
|
||
wmslayer.addTo(map); | ||
layerControl.addOverlay(wmslayer, `Predicted SWE ${date}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { refreshCalendar} from "./utils.js"; | ||
import { MapHandler } from "./map.js"; | ||
import { addLegend } from "./legend.js"; | ||
import { setupEventListeners } from "./events.js"; | ||
import { setup_datepicker } from "./datepicker.js"; | ||
import { add_swe_predicted_geotiff } from "./geotiff.js"; | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
// Initialize the map | ||
const mapHandler = new MapHandler(); | ||
mapHandler.initializeMap(); | ||
|
||
// Load available dates into the datepicker | ||
refreshCalendar((dateArray) => { | ||
setup_datepicker(dateArray, (selectedDate) => { | ||
console.log(`Date selected: ${selectedDate}`); | ||
// Load SWE GeoTIFF prediction for the selected date | ||
add_swe_predicted_geotiff( | ||
mapHandler.map, | ||
mapHandler.layerControl, | ||
selectedDate | ||
); | ||
}); | ||
}); | ||
|
||
// Set up event listeners for map and buttons | ||
setupEventListeners(mapHandler.map, mapHandler.layerControl); | ||
|
||
// Add a legend to the map | ||
addLegend(mapHandler.map); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function addLegend(map) { | ||
const legend = L.control({ position: "bottomright" }); | ||
|
||
legend.onAdd = function () { | ||
const div = L.DomUtil.create("div", "info legend"); | ||
div.style.backgroundColor = "white"; | ||
div.style.padding = "10px"; | ||
|
||
const grades = [0, 5, 10, 15, 20, 25, 30, 35, 40]; | ||
const colors = [ | ||
"#003366", | ||
"#336699", | ||
"#6699CC", | ||
"#99CCFF", | ||
"#99FFFF", | ||
"#CCFFFF", | ||
"#FFFFCC", | ||
"#FFFF99", | ||
"#FFFF33", | ||
]; | ||
|
||
grades.forEach((grade, i) => { | ||
div.innerHTML += ` | ||
<i style="background:${colors[i]}; width: 20px; height: 15px; display: inline-block;"></i> | ||
${grade}${grades[i + 1] ? `–${grades[i + 1]}` : "+"}<br> | ||
`; | ||
}); | ||
|
||
return div; | ||
}; | ||
|
||
legend.addTo(map); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved to index.html into src file