-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcont5.html
1443 lines (1251 loc) · 43.9 KB
/
cont5.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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>HydroMatic-Ground Water Contour Mappere</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
/* Base Styles */
:root {
--background-color: #222;
--text-color: #fff;
--primary-color: #007BFF;
--secondary-color: #0056b3;
--navbar-background: #333;
--button-background: #444;
}
/* Global Styles */
body, button, input, select {
font-family: 'Roboto', sans-serif;
font-size: 16px;
margin: 0;
padding: 0;
background-color: var(--background-color);
color: var(--text-color);
}
/* Accessibility */
[role="button"], [role="menuitem"] {
cursor: pointer;
}
/* Navbar Styles */
#navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: var(--navbar-background);
color: var(--text-color);
padding: 16px 32px;
width: 100%;
}
#navbar .nav-logo {
cursor: pointer;
flex-grow: 1;
}
#navbar .nav-links {
list-style: none;
display: flex;
align-items: center;
gap: 5px;
margin-left: auto;
}
#navbar .nav-links li {
margin: 0 8px;
}
#navbar .nav-links a {
color: var(--text-color);
text-decoration: none;
font-size: 18px;
padding: 8px 16px;
}
#navbar .menu-toggle {
display: none;
}
#navbar .bar {
background-color: var(--text-color);
margin: 3px 0;
width: 25px;
height: 3px;
}
/* Responsive Design for Mobile */
@media screen and (max-width: 768px) {
#navbar {
flex-direction: column;
text-align: center;
}
#navbar .nav-links {
margin-left: 0;
margin-top: 16px;
}
#navbar .menu-toggle {
display: block;
margin-top: 16px;
}
}
/* Styles for Popup Input Fields */
.popup-input {
width: 100%;
padding: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 14px;
}
/* Styles for Popup Buttons */
.popup-button,
#signInButton,
#openSignUp,
#signUpButton {
background-color: var(--primary-color);
color: var(--text-color);
border: none;
padding: 8px 16px;
margin: 5px 0;
width: auto;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
/* Style for Modal Input Fields and Buttons */
.modal-input-button {
margin-bottom: 10px;
}
/* If you want to have a different margin for the last item to reduce the space above the buttons */
.modal-body > :last-child {
margin-bottom: 0;
}
/* Styles for Popup Buttons on Hover */
.popup-button:hover,
#signInButton:hover,
#openSignUp:hover,
#signUpButton:hover {
background-color: var(--secondary-color);
}
/* Style for the "Show Contour Plot" Button */
#showContourPlotBtn {
background-color: var(--primary-color);
color: var(--text-color);
padding: 8px 16px;
}
/* Style for the "Show Contour Plot" Button on Hover */
.show-contour-plot-button:hover {
background-color: var(--secondary-color);
}
/* Updated Style for the Map Layer Toggle Switch */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 30px;
margin-right: 10px;
vertical-align: middle;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 2px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: var(--primary-color);
}
input:checked + .slider:before {
transform: translateX(30px);
}
/* Style for the Label Next to the Toggle Switch */
.toggle-label {
display: inline-block;
color: var(--text-color);
font-size: 16px;
vertical-align: middle;
}
/* Sidebar Styles */
#sidebar {
display: flex;
flex-direction: column;
background-color: #333;
color: #fff;
padding: 16px;
text-align: center;
min-width: 250px;
transition: width 0.3s;
margin: 3vh 10px; /* Updated margin to create space around the sidebar */
}
/* Input Controls Section Styles */
#inputControls {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 16px;
height: 80vh;
width: 250px;
margin: 3vh 1px 0 1px;
background-color: #333;
}
#inputControls button,
#inputControls input,
#inputControls select {
background-color: var(--button-background);
color: #fff;
border: none;
padding: 8px 16px;
margin: 3vh 0;
width: 100%;
}
/* Left Side Container Styles */
#left-side {
flex-direction: column;
align-items: flex-start;
}
/* Main Application Container Styles */
#app-container {
display: flex;
align-items: stretch;
margin: 0 0px 0 10px; /* Updated margin to create space on the right side */
min-height: 100vh;
overflow-y: scroll;
}
/* Map Area Styles */
#map {
display: flex;
flex-direction: column;
align-items: flex-end;
flex: 2;
margin: 0 10px 0 0; /* Updated margin to create space on the right side */
width: calc(80vw - 10px); /* Adjusted width to account for the margin */
height: 60vh;
}
/* Table for Markers Styles */
#markerTable {
border-collapse: collapse;
width: calc(20vw - 10px); /* Adjusted width to account for the margin */
max-height: 60vh; /* Match the height to the map */
width: 80vw; /* Match the width to the map */
overflow-y: auto;
margin: 0 10px 0 10px; /* Updated margin to create space on the left side */
}
#markerTable thead {
background-color: #f2f2f2;
}
#markerTable thead th {
padding: 16px;
text-align: left;
border-bottom: 1px solid #ddd;
}
#markerTable tbody td {
text-align: left;
color: #fff;
overflow-y: auto;
}
/* General Modal Styles */
.modal,
.modal1 {
display: none;
position: fixed;
z-index: 9999;
left: 50%;
top: 50%;
pointer-events: auto;
transform: translate(-50%, -50%);
}
/* Specific Modal Background Colors */
.modal {
background-color: transparent;
}
.modal1 {
background-color: grey;
}
/* Modal Content Styles */
.modal-content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #2c2c2c;
color: #fff;
padding: 16px;
border: 1px solid #444;
width: 35vw;
height: 45vh;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
position: relative;
}
/* Modal Header Styles */
.modal-header {
max-width: 80%;
cursor: move;
padding: 16px;
background-color: #333;
color: #fff;
text-align: center;
font-size: 1.5rem;
margin-bottom: 16px;
}
/* Modal Body Styles */
.modal-body {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}
/* Other Modal Elements Styles */
.modal-open,
.close {
pointer-events: auto;
}
.close {
position: absolute;
top: 8px;
right: 8px;
font-size: 24px;
color: #fff;
cursor: pointer;
}
/* Updated Modal Body Styles */
.modal-body {
display: flex;
flex-direction: column;
align-items: center;
max-width: 80%;
padding: 10px;
}
@media screen and (max-width: 600px) {
.modal-content {
width: 90%;
height: 90%;
}
}
/* Existing Sidebar Elements Styles */
#projectList,
#inputControls input,
#inputControls button,
#inputControls select {
width: 100%;
margin-top: 10px;
}
/* Splash Overlay Styles */
#splash-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}
/* Keyframes for the fadeIn Animation */
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/* Prevent Text Selection for Some Elements */
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Style for the "Add Marker" Button */
.add-marker-button {
background-color: #28a745;
color: white;
border: none;
padding: 8px 16px;
margin: 5px 0;
width: 100%;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
/* Style for the "Add Marker" Button on Hover */
.add-marker-button:hover {
background-color: #218838;
}
/* Contour Plot Modal Styles */
#contourPlotModal {
display: none;
position: fixed;
z-index: 9999;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: grey;
border: 1px solid #444;
width: 35vw;
height: 45vh;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
pointer-events: auto;
overflow: hidden;
}
#contourPlotContainer {
width: 100%;
height: 100%;
background-color: #2c2c2c;
overflow: hidden;
}
/* Add this style to set the colorscale text to white */
.colorbar-title-text {
fill: white !important;
}
</style>
</head>
<!-- Splash Overlay -->
<div id="splash-overlay">
<img src="https://github.com/Latticeworks1/Hydro-Matic/blob/main/splash.png?raw=true" alt="Splash Image">
</div>
<!-- Navigation -->
<nav id="navbar">
<div class="nav-logo">
<img src="https://github.com/Latticeworks1/Hydro-Matic/blob/main/hydromaticlogo_inverted.png?raw=true" alt="Company Logo" style="height:40px;">
</div>
<ul class="nav-links">
<li>
<div id="mapToggle" class="switch">
<input type="checkbox" id="mapToggleCheckbox" checked>
<label for="mapToggleCheckbox" class="slider round larger-slider"></label>
<span class="toggle-label">Satellite</span>
</div>
</li>
<li>
<button id="showContourPlotBtn" class="show-contour-plot-button">Show Contour Plot</button>
</li>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li>
<button id="authBtn">Sign-in/up</button>
<input type="file" id="uploadProjectFile" accept=".json" class="hide">
</li>
</ul>
<div class="menu-toggle" id="mobile-menu">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
</nav>
</head>
<body>
<div id="app-container">
<!-- Sidebar -->
<aside>
<div id="inputControls">
<!-- User Info Section -->
<div id="userInfo" style="display: none;">
<p>Welcome, <span id="usernameDisplay"></span>!</p>
</div>
<!-- Feedback Container -->
<div id="feedbackContainer" style="display: none;">
<p id="feedbackMessage"></p>
</div>
<!-- Buttons -->
<button id="createProjectBtn">Create New Project</button>
<button id="loadMapDataBtn">Load Data</button>
<button id="exportMapDataBtn">Save Map</button>
<!-- Modals -->
<div id="contourPlotModal" class="modal">
<div class="modal-content" id="draggableModal">
<span class="close" id="closeContourPlot">×</span>
<div id="contourPlotContainer">
<div id="contourPlot"></div>
</div>
</div>
</div>
<div id="scatter3DPlotModal" class="modal">
<div class="modal-content">
<span class="close" id="closeScatter3DPlot">×</span>
<div id="scatter3DPlot"></div>
</div>
</div>
<!-- Project Controls -->
<label for="projectList">Project List:</label>
<select id="projectList"></select>
<label for="projectNumberInput">Project Number:</label>
<input type="text" id="projectNumberInput" placeholder="Project Number">
<label for="projectNameInput">Project Name:</label>
<input type="text" id="projectNameInput" placeholder="Project Name">
<label for="mapNameInput">Map ID:</label>
<input type="text" id="mapNameInput" placeholder="Map ID">
</div>
</aside>
<!-- Main Content -->
<main id="left-side">
<div id="map"></div>
<table id="markerTable" class="table table-striped">
<thead>
<tr>
<th>Well ID</th>
<th>Elevation</th>
<th>Latitude</th>
<th>Longitude</th>
<th></th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
</main>
<!-- Right Side Content -->
<div id="right-side" class="flex-item">
<!-- Add your content here -->
</div>
</div>
</body>
</html>
<!-- Sign-in Modal -->
<div id="signInModal" class="modal1 noselect">
<div class="modal-content">
<div class="modal-header">
<span class="close" id="closeSignIn">×</span>
<h2>Sign In</h2>
</div>
<div class="modal-body">
<label for="signInUsername">Username:</label>
<input type="text" id="signInUsername" placeholder="Enter your username">
<p id="signInError" style="color:red;"></p>
<label for="signInPassword">Password:</label>
<input type="password" id="signInPassword" placeholder="Enter your password">
<button id="signInButton">Sign In</button>
<button id="openSignUp">Sign Up</button>
</div>
</div>
</div>
<!-- Sign-up Modal -->
<div id="signUpModal" class="modal1 noselect">
<div class="modal-content">
<div class="modal-header">
<span class="close" id="closeSignUp">×</span>
<h2>Sign Up</h2>
</div>
<div class="modal-body">
<label for="signUpUsername">Username:</label>
<input type="text" id="signUpUsername" placeholder="Choose a username">
<p id="signUpError" style="color:red;"></p>
<label for="signUpPassword">Password:</label>
<input type="password" id="signUpPassword" placeholder="Choose a password">
<button id="signUpButton">Sign Up</button>
</div>
</div>
</div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script>
class Authentication {
async sendRequest(action, username, password) {
try {
const response = await fetch('https://neftyartstudio.com/auth_master.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `action=${action}&username=${username}&password=${password}`
});
return await response.json();
} catch (error) {
return { status: 'error', message: 'Error connecting to the server.' };
}
}
displayFeedback(message, type, feedbackMessage, feedbackContainer) {
if (type === 'signIn') {
document.getElementById("signInError").textContent = message;
} else if (type === 'signUp') {
document.getElementById("signUpError").textContent = message;
} else {
feedbackMessage.textContent = message;
feedbackContainer.style.display = "block";
setTimeout(() => {
feedbackContainer.style.display = "none";
feedbackMessage.textContent = "";
}, 5000);
}
}
}
document.addEventListener('DOMContentLoaded', () => {
const auth = new Authentication();
const signInModal = document.getElementById("signInModal");
const signUpModal = document.getElementById("signUpModal");
const signInUsername = document.getElementById("signInUsername");
const signInPassword = document.getElementById("signInPassword");
const signUpUsername = document.getElementById("signUpUsername");
const signUpPassword = document.getElementById("signUpPassword");
const feedbackContainer = document.getElementById("feedbackContainer");
const feedbackMessage = document.getElementById("feedbackMessage");
// Check if the user is already logged in
const loggedInUser = localStorage.getItem('loggedInUser');
if (loggedInUser) {
document.getElementById("userInfo").style.display = "block"; // Display the user info section
document.getElementById("usernameDisplay").textContent = loggedInUser; // Update the username display
}
localStorage.setItem('loggedInUser', signInUsername.value); // for login
localStorage.setItem('loggedInUser', signUpUsername.value); // for sign-up
localStorage.removeItem('loggedInUser');
// Function to send requests to the PHP endpoint
async function sendRequest(action, username, password) {
try {
const response = await fetch('https://neftyartstudio.com/auth_master.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `action=${action}&username=${username}&password=${password}`
});
return await response.json();
} catch (error) {
return { status: 'error', message: 'Error connecting to the server.' };
}
}
function displayFeedback(message, type) {
if (type === 'signIn') {
document.getElementById("signInError").textContent = message;
} else if (type === 'signUp') {
document.getElementById("signUpError").textContent = message;
} else {
feedbackMessage.textContent = message;
feedbackContainer.style.display = "block";
setTimeout(() => {
feedbackContainer.style.display = "none";
feedbackMessage.textContent = "";
}, 5000);
}
}
document.getElementById("signInButton").addEventListener("click", async () => {
const response = await auth.sendRequest('login', signInUsername.value, signInPassword.value);
auth.displayFeedback(response.message, response.status === 'success' ? null : 'signIn', feedbackMessage, feedbackContainer);
if (response.status === 'success') {
signInModal.style.display = "none";
document.getElementById("userInfo").style.display = "block"; // Display the user info section
document.getElementById("usernameDisplay").textContent = signInUsername.value; // Update the username display
}
});
document.getElementById("signUpButton").addEventListener("click", async () => {
if (signUpUsername.value.trim() === "" || signUpPassword.value.trim() === "") {
displayFeedback("Please enter a valid username and password.", 'signUp');
return;
}
const response = await auth.sendRequest('register', signUpUsername.value, signUpPassword.value);
auth.displayFeedback(response.message, response.status === 'success' ? null : 'signUp', feedbackMessage, feedbackContainer);
if (response.status === 'success') {
signUpModal.style.display = "none";
document.getElementById("userInfo").style.display = "block";
document.getElementById("usernameDisplay").textContent = signUpUsername.value;
localStorage.setItem('loggedInUser', signUpUsername.value); // Store the username in local storage
}
});
document.getElementById("authBtn").addEventListener("click", () => { signInModal.style.display = "block"; });
document.getElementById("openSignUp").addEventListener("click", () => {
signInModal.style.display = "none";
signUpModal.style.display = "block";
});
document.getElementById("closeSignIn").addEventListener("click", () => { signInModal.style.display = "none"; });
document.getElementById("closeSignUp").addEventListener("click", () => { signUpModal.style.display = "none"; });
});
// Draggable functionality
function makeDraggable(modal) {
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
const header = modal.querySelector('.modal-header'); // Only the header is draggable
header.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
let newTop = modal.offsetTop - pos2;
let newLeft = modal.offsetLeft - pos1;
newTop = Math.max(newTop, 0);
newTop = Math.min(newTop, window.innerHeight - modal.offsetHeight);
newLeft = Math.max(newLeft, 0);
newLeft = Math.min(newLeft, window.innerWidth - modal.offsetWidth);
modal.style.top = newTop + "px";
modal.style.left = newLeft + "px";
}
}
makeDraggable(signInModal);
makeDraggable(signUpModal);
// Function to hide the splash overlay after a delay or when the page is fully loaded
setTimeout(function () {
var splashOverlay = document.getElementById("splash-overlay");
if (splashOverlay) {
splashOverlay.style.opacity = "0";
setTimeout(function(){
splashOverlay.style.display = "none";
}, 750); // Match the duration of the fade-out with the one specified in CSS
}
}, 1000); // 3000 milliseconds = 3 seconds
function exportMapData() {
console.log("Export button clicked"); // Debugging line
// Get project details
const projectNumber = document.getElementById("projectNumberInput").value;
const projectName = document.getElementById("projectNameInput").value;
const mapName = document.getElementById("mapNameInput").value;
// Combine project details with marker data
const exportData = {
projectNumber: projectNumber,
projectName: projectName,
mapName: mapName,
markerData: markerData // Assuming markerData is your existing array
};
// Check if marker data is available
if (markerData && markerData.length > 0) {
// Create a Blob with the combined data as JSON
const blob = new Blob([JSON.stringify(exportData)], { type: 'application/json' });
// Create a download link
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${projectNumber}_${mapName}.json`;
// Trigger a click event to download the file
a.click();
} else {
console.log("markerData is empty or not initialized");
}
}
// Declare global variables for map, markers, and modal state
let map;
let markerData = [];
let markers = [];
let modalOpen = false;
// Initialize application after window load
window.addEventListener("load", initialize);
/**
* Main Initialization Function
*/
function initialize() {
// Initialize map and load markers
map = initializeMap();
markerData = loadMarkersFromLocalStorage();
markers = [];
// Add existing markers to map
markerData.forEach(coord => addMarker(coord));
// Attach the event listener for the export button
document.getElementById("exportMapDataBtn").addEventListener("click", exportMapData);
// Attach event handlers
map.on('click', handleMapClick);
document.getElementById("showContourPlotBtn").addEventListener("click", showContourPlot);
document.getElementById("closeContourPlot").addEventListener("click", hideContourPlot);
// Make contour plot modal draggable
dragElement(document.getElementById("draggableModal"));
// Listen to map zoom and move events to update contour plot
map.on('moveend zoomend', function() {
if (modalOpen) {
drawContourPlot();
}
});
// Initialize the table with marker data
updateTable();
}
/**
* Initialize the Leaflet map.
* @returns {object} Initialized map object.
*/
function initializeMap() {
// Initialize Leaflet map and set view
const map = L.map('map').setView([51.505, -0.09], 13);
// Define the tile layers for the street map and Esri satellite imagery
const streetMapLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
const esriSatelliteLayer = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
});
// Create an object with the available tile layers
const baseLayers = {
"Street Map": streetMapLayer,
"Esri Satellite": esriSatelliteLayer
};
// Add the Esri satellite layer as the default layer
esriSatelliteLayer.addTo(map);
// Add a layer control to the map, allowing users to switch between layers
L.control.layers(baseLayers).addTo(map);
// Initialize the map toggle checkbox and event listener
const mapToggleCheckbox = document.getElementById("mapToggleCheckbox");
mapToggleCheckbox.checked = true; // Initialize checkbox to checked (Satellite ON)
mapToggleCheckbox.addEventListener("change", function () {
if (mapToggleCheckbox.checked) {
// Switch to the Esri satellite layer
map.removeLayer(streetMapLayer);
esriSatelliteLayer.addTo(map);
} else {
// Switch back to the street map layer
map.removeLayer(esriSatelliteLayer);
streetMapLayer.addTo(map);
}
});
return map;
}
/**
* Handle click events on the map to add new markers.
* @param {Event} e - Leaflet click event object.
*/
function handleMapClick(e) {
const wellIDInput = document.createElement("input");
wellIDInput.type = "text";
wellIDInput.placeholder = "Enter Well ID";
wellIDInput.className = "popup-input"; // Add a class for styling
const elevationInput = document.createElement("input");
elevationInput.type = "number";
elevationInput.placeholder = "Enter Elevation";
elevationInput.className = "popup-input"; // Add a class for styling
const addButton = document.createElement("button");
addButton.textContent = "Add Marker";
addButton.className = "add-marker-button"; // Use the new class for styling
addButton.addEventListener("click", () => {
const wellID = wellIDInput.value.trim();
const elevation = parseFloat(elevationInput.value.trim());
if (wellID === "") {
alert("Please enter a Well ID.");
return;
}
// Process coordinates and add marker with Well ID and elevation
const coord = { lat: e.latlng.lat, lng: e.latlng.lng, elevation: elevation, wellID: wellID };
addMarker(coord);
markerData.push(coord);
saveMarkersToLocalStorage();
updateTable();
});
// Create a popup with input fields for Well ID and elevation
const popupContent = document.createElement("div");
popupContent.appendChild(wellIDInput);
popupContent.appendChild(elevationInput);
popupContent.appendChild(addButton);
L.popup()
.setLatLng(e.latlng)
.setContent(popupContent)
.openOn(map);
}
// Function to add a new marker to the map
function addMarker(coord) {
// Create a custom popup content with the new format
const popupContent = document.createElement("div");
popupContent.innerHTML = `
<p><strong>Well ID:</strong> ${coord.wellID}</p>
<p><strong>Coordinates:</strong> ${coord.lat}, ${coord.lng}</p>
<p><strong>Elevation:</strong> ${coord.elevation}</p>
`;
// Create and add marker to the map with the custom popup content
const marker = L.marker([coord.lat, coord.lng])
.addTo(map)
.bindPopup(popupContent)
.openPopup();
// Add right-click event listener to remove marker
marker.on('contextmenu', function (e) {
const index = markers.indexOf(this);
removeMarker(index);
});
// Add marker to the global markers array
markers.push(marker);
}
// Function to load markers data from local storage
function loadMarkersFromLocalStorage() {
// Fetch saved markers from local storage and parse the JSON data
const savedData = localStorage.getItem("markerData");
return savedData ? JSON.parse(savedData) : [];
}
// Function to save current markers data to local storage
function saveMarkersToLocalStorage() {
// Convert markers data to JSON and save to local storage
localStorage.setItem("markerData", JSON.stringify(markerData));
}
// Event listener for the "Load Map Data" button
document.getElementById("loadMapDataBtn").addEventListener("click", () => {
// Trigger the file input click event when the "Load Data" button is clicked