-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapv2.html
566 lines (501 loc) · 16.3 KB
/
mapv2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
User
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HydroMatic</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Include Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Include Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<style>
/* Global Styles */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
color: #333;
margin: 0;
overflow-x: hidden;
}
h1, h3 {
margin-top: 0px;
margin-bottom: 0px;
font-size: 20px;
}
/* Header Styles */
header {
background-color: #343a40;
color: #ffffff;
padding: 5px 5px 5px 5px;
height: 5vh;
}
/* Existing sidebar styles */
.sidebar {
background-color: #343a40;
height: 100vh;
padding: 20px;
color: #ffffff;
width: 70px;
transition: width 0.3s ease-in-out, opacity 0.3s ease-in-out; /* Added opacity transition */
overflow: hidden;
}
.sidebar:hover {
width: 10vw;
overflow: auto;
}
/* Add the following lines to hide all child elements when the sidebar is collapsed */
.sidebar > * {
opacity: 0; /* Sets the opacity of all child elements to zero */
transition: opacity 0.3s ease-in-out; /* Smooth transition */
}
.sidebar:hover > * {
opacity: 1; /* Sets the opacity of all child elements to 1 on hover */
}
/* Custom Input Style */
.custom-input {
background-color: #343a40;
color: #ffffff;
border: 1px solid #454d55;
width: 5vw;
height: 4vh;
}
.custom-input:hover {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); /* Added hover effect */
}
/* Project Management Elements */
.project-management {
margin-top: 30px;
display: flex;
flex-direction: column;
}
.project-management h4 {
margin: 0;
padding: 5px;
font-size: 1.2rem;
font-weight: bold;
}
.project-list {
margin-top: 10px;
list-style-type: none;
padding: 0;
}
.project-list-item {
margin: 5px 0;
padding: 5px;
background-color: #454d55;
border-radius: 4px;
cursor: pointer;
}
.project-list-item:hover {
background-color: #343a40;
color: #ffffff;
}
/* Map and Chart Styles */
#map {
width: 100%;
height: 100%;
}
#plotDiv {
width: 100%;
height: 100%;
}
/* Adjust Plot Size */
.plot-container {
height: 50vh;
width: 100%;
margin-top: 1px;
}
/* Map, Plot, and Table Layout */
.map-plot-table {
display: flex;
height: 100vh;
}
.map {
flex: 2; /* Increase the flex value to make map wider */
height: 99vh;
width: 60vw; /* Changed from fixed width to auto */
padding: 1%;
}
.plot-table-column {
flex: 1; /* Decrease the flex value to reduce space */
display: flex;
flex-direction: column;
}
.plot, .table-container {
flex: 1;
padding-left: 1px;
}
/* Additional Spacing and Scroll */
.plot {
margin-bottom: 30px; /* Added space between plot and table */
padding-bottom: 30px;
}
.table-container {
height: 20px;
overflow-y: auto; /* Added vertical scroll */
margin-bottom: 30px; /* Added space between plot and table */
padding-bottom: 10px; /* Added space between plot and table */
}
/* Responsive Design */
@media (max-width: 768px) {
.map-plot-table {
flex-direction: column;
}
.map, .plot-table-column {
flex: none;
width: 100%;
}
}
/* Add this CSS to make the editable cells smaller */
.table input[type="text"].wellid,
.table input[type="number"].elevation {
width: 70px; /* Adjust the width as needed */
height: 30px; /* Adjust the height as needed */
}
/* Inline Form Container */
.contour-form-inline {
display: flex;
align-items: center;
background-color: #343a40; /* Same as sidebar for cohesion */
padding:1%;
border-radius: 4px;
}
/* Inline Form Label */
.form-label-inline {
color: #ffffff; /* White color to match existing design */
margin-right: 19px;
font-size: 1rem;
flex-shrink: 0; /* Prevent shrinking */
}
/* Inline Form Control */
.form-control-inline.custom-input {
flex-grow: 1; /* Allow it to take available space */
transition: all 0.2s ease-in-out;
width: 10vw; /* Auto width based on flex-grow */
height: 4vh;
border-radius: 4px;
}
.form-control-inline.custom-input:hover {
box-shadow: 0 0 5px rgba(255, 255, 255, 0.5); /* Slight glow effect on hover */
}
</style>
<!-- Include Leaflet and Plotly JS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script>
// Add your JavaScript code here
function animateMapMarker() {
// Add code for marker animation
}
</script>
</head>
<body>
<!-- Header -->
<header class="text-center">
<h1>Hydr-O-Matic!</h1>
</header>
<!-- Main content -->
<div class="container-fluid">
<div class="row">
<!-- Sidebar (Left Column) -->
<nav class="col-lg-3 sidebar">
<!-- Project and Map Selection Dropdowns -->
<div class="mb-3">
<label for="projectSelect" class="form-label-inline">Project:</label>
<select id="projectSelect" class="form-control-inline custom-input">
<!-- Options for selecting a project will be added dynamically -->
</select>
</div>
<div class="mb-3">
<label for="mapSelect" class="form-label-inline">Map:</label>
<select id="mapSelect" class="form-control-inline custom-input">
<!-- Options for selecting a map will be added dynamically -->
</select>
</div>
<!-- Project and Map Management Buttons -->
<div class="mb-3">
<button id="createProjectBtn" class="btn btn-primary">New Project</button>
<button id="createMapBtn" class="btn btn-primary">New Map</button>
<button id="saveDataBtn" class="btn btn-success">Save/export</button>
</div>
</nav>
<!-- Main Content (Middle Column) -->
<main class="col-lg-9">
<!-- Map, Plot, and Table layout -->
<div class="map-plot-table">
<!-- Large Map (Left Half) -->
<div class="map">
<h3></h3>
<div id="map"></div>
</div>
<!-- Plot and Table Column (Right Half) -->
<div class="plot-table-column">
<!-- Plotly Contour Plot (Top) -->
<div class="plot">
<h3>
<div class="contour-form-inline">
<label for="contourStep" class="form-label-inline">Contour Step:</label>
<input type="number" id="contourStep" value="0.25" class="form-control-inline custom-input">
</div>
</h3>
<div id="plotDiv" class="plot-container"></div>
</div>
<!-- Table (Bottom) -->
<div class="table-container">
<div class="mb-3">
<!-- Additional content related to the table can be added here -->
</div>
<table id="dataTable" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Elevation</th>
<th></th> <!-- Added a new column for the "Delete" button -->
</tr>
</thead>
<tbody>
<!-- Add table data dynamically using JavaScript -->
</tbody>
</table>
</div>
</div>
</div>
<pre id="jsonDisplay"></pre>
</main>
</div>
</div>
<script>
Object.defineProperty(window, 'storage', {
set: function (value) {
_storage = value;
updateJSONDisplay();
},
get: function () {
return _storage;
}
});
// Initialize the _storage variable and update the JSON display
var _storage = {
"mapMarkers": {},
"data": [] // Combine plot and table data into a single array
};
// Initialize Leaflet map
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Initialize data table
var dataTable = document.getElementById('dataTable');
// Function to update the JSON display
function updateJSONDisplay() {
var jsonDisplay = document.getElementById('jsonDisplay');
jsonDisplay.textContent = JSON.stringify(storage, null, 2); // Pretty-print with 2-space indentation
}
// Function to update the plot and table data based on changes
function updateDataAndPlot() {
// Update the Contour Plot
updatePlotBasedOnMapView();
// Update the JSON display
updateJSONDisplay();
}
// Function to delete a map marker
function deleteMapMarker(markerKey) {
if (markerKey in storage.mapMarkers) {
map.removeLayer(storage.mapMarkers[markerKey]);
delete storage.mapMarkers[markerKey];
}
}
// Function to delete a row and corresponding marker and plot data
function deleteTableRow(index) {
dataTable.deleteRow(index + 1);
// Remove the map marker
let markerKey = Object.keys(storage.mapMarkers).find(key => {
let marker = storage.mapMarkers[key];
return marker.lat === storage.data[index][0] && marker.lng === storage.data[index][1];
});
if (markerKey !== undefined) {
deleteMapMarker(markerKey); // Call the deleteMapMarker function
}
// Remove the data from storage.data
storage.data.splice(index, 1);
// Update the plot and table data
updateDataAndPlot();
}
// Function to check if a Well ID already exists
function wellIdExists(wellId) {
return Object.values(storage.mapMarkers).some(marker => marker.wellId === wellId);
}
// Event listener for clicking on the map
map.on('click', function(e) {
// New point clicked
var lat = e.latlng.lat;
var lng = e.latlng.lng;
var wellId = "";
while (wellId.trim() === "") {
wellId = prompt('Enter Well ID:');
if (wellId === null) return; // User canceled
}
// Check if a marker with the same Well ID already exists
if (wellIdExists(wellId)) {
alert('A marker with the same Well ID already exists. Please enter a unique Well ID.');
return;
}
var elevation = null;
while (isNaN(elevation)) {
var elevationStr = prompt('Enter Elevation:');
if (elevationStr === null) return; // User canceled
elevation = parseFloat(elevationStr);
}
// Add marker to the map and to storage.mapMarkers
let markerKey = wellId; // Use wellId as the key
storage.mapMarkers[markerKey] = { "lat": lat, "lng": lng, "wellId": wellId, "elevation": elevation };
L.marker([lat, lng])
.addTo(map)
.bindPopup('Well ID: ' + wellId + '<br>Latitude: ' + lat + '<br>Longitude: ' + lng)
.openPopup();
// Add data to storage.data
storage.data.push([lat, lng, elevation]);
// Update the map marker JSON display immediately
updateJSONDisplay();
// Populate the table with the new row
var row = dataTable.insertRow(-1);
var cell1 = row.insertCell(0); // Well ID
var cell2 = row.insertCell(1); // Latitude
var cell3 = row.insertCell(2); // Longitude
var cell4 = row.insertCell(3); // Elevation
var cell5 = row.insertCell(4); // Action (Delete button)
// Add Well ID, Latitude, Longitude, and Elevation to the table
cell1.innerHTML = '<input type="text" class="wellid" contenteditable="true" value="' + wellId + '">';
cell2.innerHTML = lat;
cell3.innerHTML = lng;
cell4.innerHTML = '<input type="number" class="elevation" value="' + elevation + '">';
cell5.innerHTML = '<button class="btn btn-danger delete-btn">Delete</button>';
// Event listener for editing Well ID
cell1.querySelector('.wellid').addEventListener('input', function() {
// Get the updated Well ID value
var updatedWellId = this.value.trim();
if (updatedWellId === "") {
alert('Well ID cannot be empty. Please enter a valid Well ID.');
this.value = wellId; // Reset the input to the original Well ID
return;
}
// Check if a marker with the same Well ID already exists
if (updatedWellId !== wellId && wellIdExists(updatedWellId)) {
alert('A marker with the same Well ID already exists. Please enter a unique Well ID.');
this.value = wellId; // Reset the input to the original Well ID
return;
}
// Update storage.mapMarkers with the new Well ID
let rowIndex = this.closest('tr').rowIndex - 1; // Subtract 1 to account for the header row
let markerKey = Object.keys(storage.mapMarkers).find(key => {
let marker = storage.mapMarkers[key];
return marker.lat === storage.data[rowIndex][0] && marker.lng === storage.data[rowIndex][1];
});
storage.mapMarkers[markerKey].wellId = updatedWellId;
// Update the plot and table data
updateDataAndPlot();
});
// Event listener for entering Elevation
cell4.querySelector('.elevation').addEventListener('change', function() {
var updatedElevation = parseFloat(this.value);
let rowIndex = this.closest('tr').rowIndex - 1; // Subtract 1 to account for the header row
storage.data[rowIndex][2] = updatedElevation;
// Update the plot and table data
updateDataAndPlot();
});
// Event listener for deleting a row
cell5.querySelector('.delete-btn').addEventListener('click', function() {
const rowIndex = this.closest('tr').rowIndex - 1; // Subtract 1 to account for the header row
if (rowIndex >= 0) { // Verify it's not a header row
deleteTableRow(rowIndex);
}
});
});
// Function to update a table row and corresponding marker and plot data
function updateTableRow(rowIndex, updatedWellId, updatedElevation) {
// Update storage.mapMarkers
let markerKey = Object.keys(storage.mapMarkers).find(key => {
let marker = storage.mapMarkers[key];
return marker.lat === storage.data[rowIndex][0] && marker.lng === storage.data[rowIndex][1];
});
storage.mapMarkers[markerKey].wellId = updatedWellId;
storage.mapMarkers[markerKey].elevation = updatedElevation;
// Update storage.data
storage.data[rowIndex][2] = updatedElevation;
// Update the plot and table data
updateDataAndPlot();
}
// Initialize the plot
var plotDiv = document.getElementById('plotDiv');
function updatePlotBasedOnMapView() {
var bounds = map.getBounds();
var maxLat = bounds.getNorth();
var minLat = bounds.getSouth();
var maxLng = bounds.getEast();
var minLng = bounds.getWest();
var contourStep = parseFloat(document.getElementById('contourStep').value);
var zMin = Math.min(...storage.data.map(d => d[2]));
var zMax = Math.max(...storage.data.map(d => d[2]));
var contourStart = Math.ceil(zMin / contourStep) * contourStep;
var contourEnd = Math.floor(zMax / contourStep) * contourStep;
if (contourStep <= 0 || contourStart > contourEnd) {
return;
}
var contourTrace = {
type: 'contour',
z: storage.data.map(d => d[2]),
x: storage.data.map(d => d[1]), // Switched to Longitude
y: storage.data.map(d => d[0]), // Switched to Latitude
contours: {
start: contourStart,
end: contourEnd,
size: contourStep
},
text: storage.data.map(d => 'Elevation: ' + d[2]), // Labels for contour lines
};
var pointTrace = {
type: 'scatter',
mode: 'markers',
x: storage.data.map(d => d[1]), // Switched to Longitude
y: storage.data.map(d => d[0]), // Switched to Latitude
marker: { color: 'red', size: 10 },
name: 'Points'
};
var layout = {
xaxis: {
range: [minLng, maxLng],
title: 'Longitude',
showgrid: true, // Show gridlines
showline: true, // Show axis line
showticklabels: true, // Show tick labels
ticks: 'outside' // Place ticks outside the axis
},
yaxis: {
range: [minLat, maxLat],
title: 'Latitude',
showgrid: true, // Show gridlines
showline: true, // Show axis line
showticklabels: true, // Show tick labels
ticks: 'outside' // Place ticks outside the axis
},
paper_bgcolor: 'transparent', // Set the plot paper background color to transparent
plot_bgcolor: 'transparent', // Set the plot background color to transparent
margin: {
t: 5, // Top margin
l: 58, // Left margin
r: 5, // Right margin
b: 40 // Bottom margin
}
};
Plotly.newPlot(plotDiv, [contourTrace, pointTrace], layout);
}
map.on('moveend', updatePlotBasedOnMapView);
// Initialize the plot initially
updatePlotBasedOnMapView();
updateJSONDisplay();
</script>
</body>
</html>