Initial transfer of larger repo from git. IF full history and branches are needed must go to github at https://github.com/DulcisL/CCUCoding.git
This commit is contained in:
commit
c09ce40be0
4048 files changed
+603256
No files matched your search
@@ -0,0 +1,35 @@
|
||||
body
|
||||
{
|
||||
font: normal 16px Helvetica, Arial, sans-serif;
|
||||
margin: 15px;
|
||||
}
|
||||
|
||||
h1{text-align: center;}
|
||||
|
||||
nav span, nav a
|
||||
{
|
||||
margin: 5px;
|
||||
font-size: 20px;
|
||||
margin-right: 10px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
label{font-weight: bold;}
|
||||
|
||||
select, textarea {margin: 5px;}
|
||||
|
||||
footer
|
||||
{
|
||||
text-align: center;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.hidden{display: none;}
|
||||
|
||||
#label_yes, #label_no{font-weight: normal;}
|
||||
#color
|
||||
{
|
||||
padding: 1px 3px;
|
||||
text-align: right;
|
||||
float: right;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
:root
|
||||
{
|
||||
--light-teal: #ABEADB;
|
||||
--dark-teal: #003D2B;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<footer>
|
||||
<hr>
|
||||
<p>Copyright © Lucas Wedge, Alim Aminev,
|
||||
Jamal Wilson, Serkan Yildirim, Lakota Dolce @ Coastal Computing</p>
|
||||
<p>This project is for academic purposes only.</p>
|
||||
</footer>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI"
|
||||
crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="modeChange.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// allows me to see all the errors so they can be fixed
|
||||
// will be turned off in a prouction environment
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', "1");
|
||||
|
||||
$currentFile = basename($_SERVER['SCRIPT_FILENAME']);
|
||||
$pageName = pathinfo($currentFile, PATHINFO_FILENAME);
|
||||
$needsMapAssets = ($pageName === 'parking');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="author" content="Lucas Wedge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB"
|
||||
crossorigin="anonymous"
|
||||
>
|
||||
<link id="base" rel="stylesheet" href="base.css">
|
||||
<link id="mode" rel="stylesheet" href="lightMode.css">
|
||||
<?php if ($needsMapAssets): ?>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://unpkg.com/[email protected]/dist/leaflet.css"
|
||||
crossorigin=""
|
||||
>
|
||||
<style>
|
||||
#map {
|
||||
height: 70vh;
|
||||
min-height: 420px;
|
||||
width: 100%;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
|
||||
overflow: hidden;
|
||||
}
|
||||
.parking-map-wrapper {
|
||||
position: relative;
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
.parking-map-note {
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
color: #444;
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<title><?php echo ucfirst($pageName), PHP_EOL; ?></title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>CCU Commuting</h1>
|
||||
<nav>
|
||||
<span><?php echo ($currentFile === "parking.php") ? 'Parking' : '<a href="parking.php">Parking</a>'; ?></span>
|
||||
<span><?php echo ($currentFile === "stats.php") ? 'Stats' : '<a href="stats.php">Stats</a>'; ?></span>
|
||||
<button type="button" class="rounded" id="color">Change Color Mode</button>
|
||||
</nav>
|
||||
<hr>
|
||||
</header>
|
||||
@@ -0,0 +1,6 @@
|
||||
@import url("colorVariables.css");
|
||||
body
|
||||
{
|
||||
background-color: var(--dark-teal);
|
||||
color: var(--light-teal);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<select name="lots" id="lots">
|
||||
<option value="a">A Parking (circle by Wall Building)</option>
|
||||
<option value="aa">AA Parking (HTC Center)</option>
|
||||
<option value="b" class="fac_staff">B Parking (Penny Hall)</option>
|
||||
<option value="bb">BB Parking (Woods Residence Halls)</option>
|
||||
<option value="bbb">BBB Parking (Burroughs & Chapin Center)</option>
|
||||
<option value="c" class="fac_staff">C Parking (Penny Hall)</option>
|
||||
<option value="cc">CC Parking (road in front of Hicks Dining Hall)</option>
|
||||
<option value="ccc">CCC Parking (Burroughs & Chapin Center)</option>
|
||||
<option value="d" class="fac_staff">D Parking (Smith Building)</option>
|
||||
<option value="dd">DD Parking (behind Hicks Dining Hall)</option>
|
||||
<option value="ddd">DDD Parking (Coastal Science Center)</option>
|
||||
<option value="e">E Parking(LJSU/Spadoni Park)</option>
|
||||
<option value="ee">EE Parking (Woods Residence Halls)</option>
|
||||
<option value="fff">FFF Parking (Intermural Fields)</option>
|
||||
<option value="gg">GG Parking (across the way from LJSU)</option>
|
||||
<option value="ggg">GGG Parking (Atlantic Hall)</option>
|
||||
<option value="h">H Parking ()</option>
|
||||
<option value="hh" class="fac_staff">HH Parking (across road from Douglas and Swain)</option>
|
||||
<option value="hhh">HHH Parking (Soccer Stadium)</option>
|
||||
<option value="i">I Parking ()</option>
|
||||
<option value="ii">II Parking (Horry County Scholars Academy)</option>
|
||||
<option value="j">J Parking (by Atheneum Hall and Indigo Hall)</option>
|
||||
<option value="jjj">JJJ Parking</option>
|
||||
<option value="kk">KK Parking</option>
|
||||
<option value="ll">LL Parking</option>
|
||||
<option value="m">M Parking (Williams-Brice)</option>
|
||||
<option value="mm">MM Parking (Baxley Hall)</option>
|
||||
<option value="nn">NN Parking (Gardens Residence Halls)</option>
|
||||
<option value="o">O Parking (Hampton and Laurel Hall)</option>
|
||||
<option value="oo">OO Parking</option>
|
||||
<option value="p">P Parking (Edwards Building)</option>
|
||||
<option value="q">Q Parking (Edwards Building)</option>
|
||||
<option value="qq">QQ Parking (Brooks Stadium, Boni Belle Hitting Facility)</option>
|
||||
<option value="r">R Parking (Brittain Hall)</option>
|
||||
<option value="rr">RR Parking (University Place)</option>
|
||||
<option value="s">S Parking (Brittain Hall)</option>
|
||||
<option value="uu">UU Parking (near Arcadia Hall)</option>
|
||||
<option value="ww">WW Parking (Sands Hall)</option>
|
||||
<option value="yy">YY Parking (close to University Place)</option>
|
||||
</select>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
// Redirect root requests to the parking view so it behaves as the homepage.
|
||||
header('Location: parking.php');
|
||||
exit;
|
||||
@@ -0,0 +1,6 @@
|
||||
@import url("colorVariables.css");
|
||||
body
|
||||
{
|
||||
background-color: var(--light-teal);
|
||||
color: var(--dark-teal);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
let modeButton = document.getElementById("color");
|
||||
modeButton.addEventListener("click", changeMode);
|
||||
|
||||
function changeMode()
|
||||
{
|
||||
let colorCSS = document.getElementById("mode");
|
||||
if(colorCSS.href.endsWith("lightMode.css")){colorCSS.href = "darkMode.css";}
|
||||
else{colorCSS.href = "lightMode.css";}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php include "commheader.php"; ?>
|
||||
<main>
|
||||
<section class="parking-intro">
|
||||
<h2>Parking Statuses</h2>
|
||||
<p>
|
||||
Below you can see an interactive map showing the current status of each
|
||||
CCU parking lot.<br>Bus routes are included as well.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="parking-map-wrapper" aria-label="Interactive parking availability map">
|
||||
<div id="map"></div>
|
||||
<p class="parking-map-note">
|
||||
Lot colors shift from green (available) toward red as they fill. Planned events force a solid red overlay.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="parking-selector">
|
||||
<h2>Select A Parking Lot</h2>
|
||||
<p>
|
||||
Use the dropdown menu to see a specific parking lot's data.<br>
|
||||
To see a map of campus, click here:
|
||||
<a href="https://www.coastal.edu/map/" target="_blank" rel="noopener">Campus Map</a>
|
||||
</p>
|
||||
<?php include "dropdown.php"; ?>
|
||||
|
||||
<section class="hidden">
|
||||
<h3>A Parking Lot</h3>
|
||||
<ul>
|
||||
<li>Location: circle in front of the Wall College of Business</li>
|
||||
<li>Closest Shuttle Stop: (Brittain Hall)</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="hidden">
|
||||
<h3>AA Parking Lot</h3>
|
||||
<ul>
|
||||
<li>Location: Outside the HTC Center</li>
|
||||
<li>Closest Shuttle Stop: (Brittain Hall)</li>
|
||||
<li>Parking Type: Limited Time**</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="hidden">
|
||||
<h3>B Parking Lot</h3>
|
||||
<ul>
|
||||
<li>Location: Outside Penny Hall (formerly Academic Office 2)</li>
|
||||
<li>Closest Shuttle Stop: (Brittain Hall)</li>
|
||||
<li>Parking Type: </li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="hidden">
|
||||
<h3>BB Parking Lot</h3>
|
||||
<ul>
|
||||
<li>Location:</li>
|
||||
<li>Closest Shuttle Stop:</li>
|
||||
<li>Parking Type:</li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
<script
|
||||
src="https://unpkg.com/[email protected]/dist/leaflet.js"
|
||||
crossorigin=""
|
||||
></script>
|
||||
<script>
|
||||
window.ccuParkingApiBase = <?php echo json_encode(getenv('PARKING_API_BASE') ?: 'http://127.0.0.1:3000'); ?>;
|
||||
</script>
|
||||
<script>
|
||||
<?php include __DIR__ . '/../src/parkingStatus.js'; ?>
|
||||
</script>
|
||||
<?php include "commfooter.php"; ?>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php include "commheader.php"; ?>
|
||||
<main>
|
||||
<section>
|
||||
<h2>Submit Statistics</h2>
|
||||
<p>
|
||||
Use the form below to submit parking statistics.<br>
|
||||
This data might be used to continue developing this web app!
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<p>Note: The values with an asterisk (*) are required.</p>
|
||||
<form name="stats" id="stats" target="_blank" method="POST">
|
||||
<p>
|
||||
<label>First Name</label>
|
||||
<input type="text" id="first" name="first" placeholder="Jane">
|
||||
</p>
|
||||
<p>
|
||||
<label>Last Name</label>
|
||||
<input type="text" id="last" name="last" placeholder="Dough">
|
||||
</p>
|
||||
<p>
|
||||
<label>Email</label>
|
||||
<input type="text" id="email" name="email" placeholder="[email protected]">
|
||||
</p>
|
||||
<p>*insert interactive calendar and clock here*</p>
|
||||
<p>
|
||||
<label>Select A Parking Lot*</label>
|
||||
<?php include "dropdown.php"; ?>
|
||||
</p>
|
||||
<p>
|
||||
<label>Further Explanation</label>
|
||||
<textarea name="explain" rows=10 cols=30>Blah blah blah blah blah...</textarea>
|
||||
</p>
|
||||
<p><input type="submit" name="submit" id="submit" value="Submit"></p>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<?php include "commfooter.php"; ?>
|
||||
@@ -0,0 +1,87 @@
|
||||
//user story 1
|
||||
|
||||
const SEMESTER_BASE_MIN = { Fall: 34, Spring: 30, Summer: 24 };
|
||||
const WEEK_FACTOR = { 1: 1.15, 2: 1.05, 3: 1.00, 4: 1.00, 5: 0.98 };
|
||||
const DAY_FACTOR = { Mon: 1.15, Tue: 1.10, Wed: 1.10, Thu: 1.08, Fri: 1.05, Sat: 0.80, Sun: 0.75 };
|
||||
const WEATHER_FACTOR = { clear: 1.00, rain: 1.10, storm: 1.20 };
|
||||
|
||||
|
||||
function todFactor(hhmm) {
|
||||
const [h, m] = hhmm.split(":").map(Number);
|
||||
const t = h + m / 60;
|
||||
if (t >= 6 && t < 9) return 1.25;
|
||||
if (t >= 9 && t < 15) return 1.00;
|
||||
if (t >= 15 && t < 18) return 1.30;
|
||||
if (t >= 18 && t < 21) return 1.05;
|
||||
return 0.90;
|
||||
}
|
||||
|
||||
function jitterMinutes(key, spread = 3) {
|
||||
let h = 2166136261;
|
||||
for (const c of key) h = Math.imul(h ^ c.charCodeAt(0), 16777619);
|
||||
return ((h >>> 0) % (2 * spread + 1)) - spread;
|
||||
}
|
||||
|
||||
function estimateDriveMinutes({ semester, weekOfMonth, day, departTime, weather = "clear" }) {
|
||||
const base = SEMESTER_BASE_MIN[semester] ?? 30;
|
||||
const wf = WEEK_FACTOR[weekOfMonth] ?? 1.0;
|
||||
const df = DAY_FACTOR[day] ?? 1.0;
|
||||
const tf = todFactor(departTime);
|
||||
const wfz = WEATHER_FACTOR[weather] ?? 1.0;
|
||||
|
||||
const raw = base * wf * df * tf * wfz;
|
||||
const noise = jitterMinutes(`${semester}|${weekOfMonth}|${day}|${departTime}|${weather}`, 3);
|
||||
return Math.max(8, Math.round(raw + noise));
|
||||
}
|
||||
|
||||
|
||||
for (let w = 1; w <= 5; w++) {
|
||||
const mins = estimateDriveMinutes({ semester: "Fall", weekOfMonth: w, day: "Mon", departTime: "08:00", weather: "clear" });
|
||||
console.log(`Fall, week ${w}, Mon 08:00 → ~${mins} min`);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//user story 2
|
||||
|
||||
function toMinutes(hhmm) {
|
||||
const [h, m] = hhmm.split(":").map(Number);
|
||||
return h * 60 + m;
|
||||
}
|
||||
function fromMinutes(total) {
|
||||
const t = ((total % (24 * 60)) + 24 * 60) % (24 * 60);
|
||||
const h = Math.floor(t / 60), m = t % 60;
|
||||
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function whenToLeaveForClass({
|
||||
classStartHHMM,
|
||||
semester,
|
||||
weekOfMonth,
|
||||
day,
|
||||
weather = "clear",
|
||||
arriveEarlyMin = 20,
|
||||
parkingWalkBufferMin = 0,
|
||||
}) {
|
||||
const driveMin = estimateDriveMinutes({ semester, weekOfMonth, day, departTime: classStartHHMM, weather });
|
||||
const leaveAt = toMinutes(classStartHHMM) - arriveEarlyMin - parkingWalkBufferMin - driveMin;
|
||||
return {
|
||||
leaveHHMM: fromMinutes(leaveAt),
|
||||
driveMin,
|
||||
arriveBufferMin: arriveEarlyMin + parkingWalkBufferMin
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const plan = whenToLeaveForClass({
|
||||
classStartHHMM: "09:30",
|
||||
semester: "Fall",
|
||||
weekOfMonth: 1,
|
||||
day: "Mon",
|
||||
weather: "rain",
|
||||
arriveEarlyMin: 20,
|
||||
parkingWalkBufferMin: 5
|
||||
});
|
||||
|
||||
console.log(`Drive ≈ ${plan.driveMin} min, arrive buffer = ${plan.arriveBufferMin} min`);
|
||||
console.log(`Leave home at: ${plan.leaveHHMM}`);
|
||||
@@ -0,0 +1,241 @@
|
||||
/* parkingStatus file used for creating and updating the web page showing parking lot status.
|
||||
Desc: This will take the map and given data from SQL and change the parking lot color based on the
|
||||
current fill of the parking lot at the given time.
|
||||
|
||||
User Story: As a student I want to be able to see a visual reference of the current capacity
|
||||
of the parking lot to easily judge the parking across campus. An example would be a map with
|
||||
green, yellow, or red overlayed over the parking lots on campus.
|
||||
*/
|
||||
|
||||
// Map configuration + state
|
||||
const MAP_CENTER = [33.7935, -79.0106]; // Approximate CCU campus center
|
||||
const MAP_ZOOM = 15;
|
||||
const REFRESH_INTERVAL_MS = 600000; // 10 minutes
|
||||
|
||||
const API_BASE = (typeof window !== 'undefined' && window.ccuParkingApiBase)
|
||||
? String(window.ccuParkingApiBase).replace(/\/+$/, '')
|
||||
: '';
|
||||
|
||||
const DEFAULT_STYLE = {
|
||||
color: '#8593a3',
|
||||
weight: 1,
|
||||
fillOpacity: 0.25,
|
||||
opacity: 1
|
||||
};
|
||||
|
||||
const lotLayerById = new Map();
|
||||
let lotGeoJsonLayer = null;
|
||||
let mapInstance = null;
|
||||
|
||||
function buildApiUrl(path) {
|
||||
if (!API_BASE) return path;
|
||||
return `${API_BASE}${path.startsWith('/') ? path : `/${path}`}`;
|
||||
}
|
||||
|
||||
function ensureMap() {
|
||||
if (mapInstance) return mapInstance;
|
||||
|
||||
if (typeof L === 'undefined') {
|
||||
console.error('Leaflet not available; cannot render parking map.');
|
||||
return null;
|
||||
}
|
||||
|
||||
const container = document.getElementById('map');
|
||||
if (!container) {
|
||||
console.warn('Map container "#map" not found; parking map skipped.');
|
||||
return null;
|
||||
}
|
||||
|
||||
mapInstance = L.map(container, {
|
||||
preferCanvas: true // faster for many polygons
|
||||
}).setView(MAP_CENTER, MAP_ZOOM);
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© OpenStreetMap & friends'
|
||||
}).addTo(mapInstance);
|
||||
|
||||
return mapInstance;
|
||||
}
|
||||
|
||||
|
||||
//Helper functions
|
||||
function clamp255(n) { return Math.max(0, Math.min(255, Math.round(n))); }
|
||||
|
||||
function fillToColor(fill, isEvent) {
|
||||
const red = clamp255(255 * fill);
|
||||
const green = clamp255(255 * (1 - fill));
|
||||
return isEvent ? 'rgb(255,0,0)' : `rgb(${red},0,${green})`;
|
||||
}
|
||||
|
||||
|
||||
/*Lot
|
||||
Desc: Class that will be used to store the needed information after being pulled from database
|
||||
Variables:
|
||||
_id(int) : the private lot ID
|
||||
name (string) : the name of the parking lot
|
||||
capacity(int) : the capacity of the lot
|
||||
fill(float) : the percent filled of lot (between 0-1)
|
||||
location(geojson) : stores the polygon location information
|
||||
color(array) : the color based on the current fill of the parking lot
|
||||
|
||||
Helpers:
|
||||
setColor() : sets the color based on the fill of the parking lot
|
||||
|
||||
*/
|
||||
class Lot {
|
||||
constructor(lotId, lotName, lotCapacity, lotGeom, lotfill) {
|
||||
this._id = lotId;
|
||||
this.name = lotName;
|
||||
this.capacity = lotCapacity;
|
||||
this.fill = lotfill;
|
||||
this.geom = lotGeom
|
||||
//set color automatically
|
||||
this.color = this.setColor();
|
||||
this.event = false;
|
||||
}
|
||||
|
||||
setColor() {
|
||||
// Assuming fill will be a number between 0 and 1
|
||||
//Red and green will be inversely proportional
|
||||
var red = 255 * this.fill;
|
||||
var green = 255 * (1 - this.fill);
|
||||
//set color of polygon for lot
|
||||
if (this.event == false){
|
||||
this.color = (red, 0, green);
|
||||
}
|
||||
if (this.event == true){
|
||||
this.color = (255, 0, 0);
|
||||
}
|
||||
return this.color
|
||||
}
|
||||
|
||||
setEvent(bool){
|
||||
if (bool){
|
||||
this.event = bool;
|
||||
this.setColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*getLots()
|
||||
Desc: This will collect the information that is needed from the SQL database and return the lots
|
||||
in and array.
|
||||
Params: none
|
||||
Returns: lots(array) - will return the array of the lots with the needed information
|
||||
*/
|
||||
async function getLots() {
|
||||
const resp = await fetch(buildApiUrl('/api/lots'), { headers: { 'Accept': 'application/json' } });
|
||||
if (!resp.ok) throw new Error(`API error ${resp.status}`);
|
||||
const data = await resp.json();
|
||||
return Array.isArray(data) ? data : [];
|
||||
}
|
||||
|
||||
function lotsToFeatureCollection(lots) {
|
||||
return {
|
||||
type: 'FeatureCollection',
|
||||
features: (lots ?? []).filter(d => d && d.geom).map(d => ({
|
||||
type: 'Feature',
|
||||
geometry: d.geom, // <- your DB-provided GeoJSON geometry
|
||||
properties: {
|
||||
lotId: String(d.id),
|
||||
name: d.name ?? `Lot ${d.id}`,
|
||||
capacity: d.capacity ?? null,
|
||||
fill: Number(d.fill ?? 0),
|
||||
event: Boolean(d.event)
|
||||
}
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
function paintLayerFromProps(layer, props) {
|
||||
const color = fillToColor(props.fill, props.event);
|
||||
layer.setStyle({ fillColor: color, color: color, weight: 1, fillOpacity: 0.7, opacity: 1 });
|
||||
|
||||
const pct = isFinite(props.fill) ? Math.round(props.fill * 100) : 0;
|
||||
const cap = props.capacity ?? '?';
|
||||
const badge = props.event ? ' • Event' : '';
|
||||
layer.bindTooltip(`${props.name}${badge}\n${pct}% full (${cap} cap)`, { sticky: true });
|
||||
}
|
||||
|
||||
// First-time build of the layer and the id->layer map
|
||||
function buildGeoJsonLayer(featureCollection) {
|
||||
const map = ensureMap();
|
||||
if (!map) return;
|
||||
|
||||
lotLayerById.clear();
|
||||
lotGeoJsonLayer = L.geoJSON(featureCollection, {
|
||||
style: DEFAULT_STYLE,
|
||||
onEachFeature: (feature, layer) => {
|
||||
const id = feature.properties.lotId;
|
||||
lotLayerById.set(id, layer);
|
||||
|
||||
// hover highlight (optional)
|
||||
layer.on('mouseover', () => layer.setStyle({ weight: 2 }));
|
||||
layer.on('mouseout', () => layer.setStyle({ weight: 1 }));
|
||||
|
||||
paintLayerFromProps(layer, feature.properties);
|
||||
}
|
||||
}).addTo(map);
|
||||
|
||||
const bounds = lotGeoJsonLayer.getBounds();
|
||||
if (bounds.isValid()) {
|
||||
map.fitBounds(bounds, { padding: [20, 20] });
|
||||
}
|
||||
}
|
||||
|
||||
// If a new lot appears, add it; if one disappears, gray it out.
|
||||
function refreshStyles(featureCollection) {
|
||||
const map = ensureMap();
|
||||
if (!map) return;
|
||||
|
||||
const seen = new Set();
|
||||
|
||||
const features = featureCollection?.features ?? [];
|
||||
|
||||
for (const feature of features) {
|
||||
const id = feature.properties.lotId;
|
||||
let layer = lotLayerById.get(id);
|
||||
|
||||
if (layer) {
|
||||
// update existing
|
||||
paintLayerFromProps(layer, feature.properties);
|
||||
} else {
|
||||
// brand new lot—add it and track
|
||||
const group = L.geoJSON(feature, { style: DEFAULT_STYLE }).addTo(map);
|
||||
const newLayer = group.getLayers()[0] ?? group;
|
||||
lotLayerById.set(id, newLayer);
|
||||
paintLayerFromProps(newLayer, feature.properties);
|
||||
}
|
||||
seen.add(id);
|
||||
}
|
||||
|
||||
// Any polygon we didn’t see this cycle gets greyed out
|
||||
for (const [id, layer] of lotLayerById.entries()) {
|
||||
if (!seen.has(id)) layer.setStyle(DEFAULT_STYLE);
|
||||
}
|
||||
}
|
||||
async function main() {
|
||||
try {
|
||||
if (!ensureMap()) return;
|
||||
|
||||
const lots = await getLots();
|
||||
const fc = lotsToFeatureCollection(lots);
|
||||
|
||||
if (!lotGeoJsonLayer) {
|
||||
buildGeoJsonLayer(fc); // first run
|
||||
} else {
|
||||
refreshStyles(fc); // subsequent runs
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load/paint lots:', e);
|
||||
}
|
||||
}
|
||||
|
||||
//Set to refresh ever N seconds
|
||||
function boot() {
|
||||
if (!ensureMap()) return;
|
||||
|
||||
main();
|
||||
setInterval(main, REFRESH_INTERVAL_MS);
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', boot);
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Leaflet Map Example</title>
|
||||
|
||||
<!-- Leaflet CSS -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://unpkg.com/[email protected]/dist/leaflet.css"
|
||||
integrity="sha512-sA+z0W4jI/JiQxqX3vXJ1P4Z1wT+kUlQ2zqFiHVsn57fDU8KXekK8kQH5rF3pDPIa5dKZOYvB0wBf8v6/9p3Vg=="
|
||||
crossorigin=""
|
||||
/>
|
||||
|
||||
<style>
|
||||
/* The map must have a size or it will not appear */
|
||||
#map {
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
|
||||
<!-- Leaflet JS -->
|
||||
<script
|
||||
src="https://unpkg.com/[email protected]/dist/leaflet.js"
|
||||
integrity="sha512-mbKjFJ50N13cS0s8fXjRA7j6+yW1A8v+qHcK5TfWbTfG5dJNYy0M2ahJ6Sdnh9AYz9sFaJrzwPJ0VMSvJz5qFA=="
|
||||
crossorigin="">
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Initialize the map and set its view (latitude, longitude, zoom)
|
||||
const map = L.map('map').setView([33.8360034, -79.0478143], 13); // San Francisco
|
||||
|
||||
// Add OpenStreetMap tiles
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© OpenStreetMap contributors'
|
||||
}).addTo(map);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user