-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
635 lines (544 loc) · 23.7 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title>Land Cover Client</title>
<!-- Core CSS -->
<link href="css/leaflet.css" rel="stylesheet" />
<link href="css/leaflet-slider.css" rel="stylesheet" />
<link href="css/leaflet-sidebar.css" rel="stylesheet" />
<link href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<style type="text/css">
html, body {
height: 100%;
height: 100%;
}
body {
padding: 0;
margin: 0;
}
body.waiting * {
cursor: wait;
}
#map {
width: 100%;
height: 100%;
min-height: 100%;
}
.leaflet-control-slider{
border-radius: 2px;
}
#inputNAIP{
width: 125px;
height: 125px;
margin: 10px;
}
.exampleImage{
width: 125px;
height: 125px;
margin: 10px;
}
.exampleImage.active{
border: 2px solid red;
}
.leaflet-image-layer.gray{
filter: grayscale(66%);
}
.slider{
height: 25px;
width: 100%;
}
input[type=button] {
color: #ccc;
background-color: #595959;
border: solid 3px #6e6e6e;
width: 85%;
height: 40px;
}
input[type=button]:hover{
cursor: pointer;
cursor: hand;
text-decoration: none;
color: #fff;
}
a.leaflet-control-slider-toggle {
width: 171px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="sidebar" class="sidebar collapsed">
<!-- Nav tabs -->
<div class="sidebar-tabs">
<ul role="tablist">
<li>
<a href="#home" role="tab">
<i class="fa fa-bars"></i>
</a>
</li>
</ul>
<ul role="tablist">
<li>
<a href="#settings" role="tab">
<i class="fa fa-gear"></i>
</a>
</li>
</ul>
</div>
<!-- Tab panes -->
<div class="sidebar-content">
<div class="sidebar-pane" id="home">
<h1 class="sidebar-header">
Land Cover Training
<span class="sidebar-close">
<i class="fa fa-caret-right"></i>
</span>
</h1>
<div style="text-align: center; margin-bottom:10px;" id="inputImages">
<h3>NAIP Input</h3>
<img id="inputNAIP">
</div>
<div style="text-align: center; margin-bottom:10px; width:100%;" id="exampleImages">
<h3>Land Cover Predictions</h3>
<div id="exampleImageList">
</div>
</div>
<div style="text-align: center; margin-bottom:10px;" id="classAdjustments">
<h3>Change Class Weights</h3>
<table style="width:100%;">
<tr>
<td style="text-align: center;">Water</td>
<td>
<img src="css/images/Water.png" />
</td>
<td style="width:30px;" id="waterVal">25</td>
<td>
<input type="range" min="1" max="100" value="25" class="slider" id="waterRange">
</td>
</tr>
<tr>
<td style="text-align: center;">Forest</td>
<td>
<img src="css/images/Forest.png" />
</td>
<td style="width:30px;" id="forestVal">25</td>
<td>
<input type="range" min="1" max="100" value="25" class="slider" id="forestRange">
</td>
</tr>
<tr>
<td style="text-align: center;">Field</td>
<td>
<img src="css/images/Field.png" />
</td>
<td style="width:30px;" id="fieldVal">25</td>
<td>
<input type="range" min="1" max="100" value="25" class="slider" id="fieldRange">
</td>
</tr>
<tr>
<td style="text-align: center;">Built</td>
<td>
<img src="css/images/Built.png" />
</td>
<td style="width:30px;" id="builtVal">25</td>
<td>
<input type="range" min="1" max="100" value="25" class="slider" id="builtRange">
</td>
</tr>
</table>
</div>
</div> <!-- End of "home" tab -->
<div class="sidebar-pane" id="settings">
<h1 class="sidebar-header">Settings
<span class="sidebar-close">
<i class="fa fa-caret-right"></i>
</span>
</h1>
</div>
</div>
</div>
<!-- Core JavaScript
================================================== -->
<script src="js/jquery-3.3.1.min.js"></script>
<!-- Leaflet JavaScript
================================================== -->
<script src="js/leaflet.js" type="text/javascript"></script>
<script src="js/leaflet-slider.js" type="text/javascript"></script>
<script src="js/leaflet-sidebar.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.js" type="text/javascript"></script>
<!-- List of backend URLS to query
================================================== -->
<script src="endpoints.js" type="text/javascript"></script>
<script type="text/javascript">
var processingServiceURL = ENDPOINTS[0]["url"];
var START_CENTER = [38, -94]; // lat, lon
var START_ZOOM = 4;
var SELECTION_SIZE = 200; // in meters, probably
var selectionBox = null;
var currentSelection = null;
var exampleImgsList = [];
var currentPatches = [];
var currentPatchSrcs = [];
var currentPatchModelIDs = [];
var soft0_hard1 = 1;
var active_im_id = 0;
var weights = [0.25, 0.25, 0.25, 0.25];
var requestPatches = function(polygon, weights_save, map){
// Request input image from the first server we know about
requestInputPatch(polygon, ENDPOINTS[0]["url"]);
// Setup placeholders for the predictions from the current click to be saved to
currentPatches.push(null);
currentPatchSrcs.push(Object());
currentPatchModelIDs.push(Object());
var idx = currentPatches.length-1;
for(var i=0; i<ENDPOINTS.length; i++){
//console.debug("Running requestPatch on " + ENDPOINTS[i]["url"]);
currentPatchSrcs[idx][i] = null;
currentPatchModelIDs[idx][i] = null;
requestPatch(polygon, weights_save, map, idx, i, ENDPOINTS[i]["url"]);
}
};
var requestInputPatch = function(polygon, serviceURL){
var topleft = L.latLng(polygon[0][0], polygon[0][1]);
var topleftProjected = L.CRS.EPSG3857.project(topleft);
var bottomright = L.latLng(polygon[2][0], polygon[2][1]);
var bottomrightProjected = L.CRS.EPSG3857.project(bottomright);
var request = {
"extent": {
"xmax": bottomrightProjected.x,
"xmin": topleftProjected.x,
"ymax": topleftProjected.y,
"ymin": bottomrightProjected.y,
"spatialReference": {
"latestWkid": 3857
}
},
};
$.ajax({
type: "POST",
url: serviceURL + "getInput",
data: JSON.stringify(request),
success: function(data, textStatus, jqXHR){
var resp = data;
$("#inputNAIP").attr("src", "data:image/png;base64," + resp.input_naip);
},
error: function(jqXHR, textStatus, errorThrown){
var response = $.parseJSON(jqXHR.responseText);
console.log("Error in processing server: " + response.error);
},
dataType: "json",
contentType: "application/json"
});
};
var requestPatch = function(polygon, weights_save, map, requestIdx, patchId, serviceURL=processingServiceURL){
var topleft = L.latLng(polygon[0][0], polygon[0][1]);
var topleftProjected = L.CRS.EPSG3857.project(topleft);
var bottomright = L.latLng(polygon[2][0], polygon[2][1]);
var bottomrightProjected = L.CRS.EPSG3857.project(bottomright);
var request = {
"extent": {
"xmax": bottomrightProjected.x,
"xmin": topleftProjected.x,
"ymax": topleftProjected.y,
"ymin": bottomrightProjected.y,
"spatialReference": {
"latestWkid": 3857
}
},
"weights": weights_save,
};
$.ajax({
type: "POST",
url: serviceURL + "predPatch",
data: JSON.stringify(request),
success: function(data, textStatus, jqXHR){
var resp = data;
var srcs = [
"data:image/png;base64," + resp.output_soft,
"data:image/png;base64," + resp.output_hard,
];
var img = $("#exampleImage_"+patchId);
if (patchId == active_im_id) {
img.addClass("active");
}
img.attr("src", srcs[soft0_hard1]);
img.attr("data-name", resp.model_name);
img.attr("data-weights", JSON.stringify(resp.weights));
exampleImgsList[patchId] = img;
if(patchId == active_im_id){
var imageLayer = L.imageOverlay(srcs[soft0_hard1],
L.polygon(polygon).getBounds()).addTo(map);
currentPatches[requestIdx] = imageLayer;
}
currentPatchSrcs[requestIdx][patchId] = srcs;
currentPatchModelIDs[requestIdx] = active_im_id;
},
error: function(jqXHR, textStatus, errorThrown){
var response = $.parseJSON(jqXHR.responseText);
console.log("Error in processing server: " + response.error);
},
dataType: "json",
contentType: "application/json"
});
};
var getPolyAround = function(latlon, radius){
// We convert the input lat/lon into the EPSG3857 projection,
// define our square, then re-convert to lat/lon
var latlonProjected = L.CRS.EPSG3857.project(latlon);
var x = latlonProjected.x;
var y = latlonProjected.y;
var top = y + radius/2;
var bottom = y - radius/2;
var left = x - radius/2;
var right = x + radius/2;
top = Math.round(top);
bottom = Math.round(bottom);
left = Math.round(left);
right = Math.round(right);
// left/right are "x" points while top/bottom are the "y" points
var topleft = L.CRS.EPSG3857.unproject(L.point(left, top));
var bottomright = L.CRS.EPSG3857.unproject(L.point(right, bottom));
return [[topleft.lat, topleft.lng],
[topleft.lat, bottomright.lng],
[bottomright.lat, bottomright.lng],
[bottomright.lat, topleft.lng]];
};
$(document).ready(function(){
var sliderRanges = [
$("#waterRange"),
$("#forestRange"),
$("#fieldRange"),
$("#builtRange")
];
var sliderVals = [
$("#waterVal"),
$("#forestVal"),
$("#fieldVal"),
$("#builtVal")
];
//----------------------------------------------------------------------
// Setup map layers
//----------------------------------------------------------------------
var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var Esri_WorldImagery = 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'
});
var interesting_locations = [
L.marker([47.60, -122.15]).bindPopup('Bellevue, WA'),
L.marker([39.74, -104.99]).bindPopup('Denver, CO'),
L.marker([37.53, -77.44]).bindPopup('Richmond, VA'),
];
var cities = L.layerGroup(interesting_locations);
var map = L.map('map', {
zoomControl: false,
crs: L.CRS.EPSG3857, // this is a default, but I'm setting it to be explicit about what CRS we are in
center: START_CENTER,
zoom: START_ZOOM,
layers: [Esri_WorldImagery, cities]
});
//----------------------------------------------------------------------
// Setup leaflet-control-geocoder plugin
//----------------------------------------------------------------------
L.Control.geocoder({
collapsed: false,
position:'topleft',
defaultMarkGeocode: true
}).addTo(map);
//----------------------------------------------------------------------
// Custom initialization of the map zoom controls so that we can
// position it where we want
//----------------------------------------------------------------------
L.control.zoom({
position:'topleft'
}).addTo(map);
//----------------------------------------------------------------------
// Setup the leaflet-easybutton plugin to reset the map to its initial
// position
//----------------------------------------------------------------------
L.easyButton(
'fa-undo', function(btn, map) {
map.closePopup();
map.setView(START_CENTER, START_ZOOM);
},
).addTo(map);
//----------------------------------------------------------------------
// Setup layer picker and initialize the "interesting points" click
// handlers
//----------------------------------------------------------------------
var baseMaps = {
"OpenStreetMap Mapnik": OpenStreetMap_Mapnik,
"ESRI World Imagery": Esri_WorldImagery
};
var overlayMaps = {
"Interesting Points": cities
};
for(var i=0;i<interesting_locations.length;i++){
interesting_locations[i].on('click', function(e){
map.setView(e.latlng, 13);
});
}
L.control.layers(
baseMaps, overlayMaps, {
collapsed:false,
position:"bottomleft"
}
).addTo(map);
//----------------------------------------------------------------------
// Setup leaflet-slider plugin, we make two sliders to control opacity
// and selection window size
//----------------------------------------------------------------------
L.control.slider( // opacity slider
function(value){
map.getPane('overlayPane').style.opacity = value / 100.0;
}, {
position: 'bottomleft',
id: 'opacity_slider',
orientation: 'horizontal',
collapsed: true,
syncSlider: true,
min: 0,
max: 100,
value: 100,
logo: "Opacity",
size: "171px"
}
).addTo(map);
L.control.slider( // sharpness slider
function(value){
soft0_hard1 = value;
for(idx=0; idx<currentPatches.length; idx++){
active_im_id = currentPatchModelIDs[idx];
currentPatches[idx].setUrl(currentPatchSrcs[idx][active_im_id][soft0_hard1]);
}
if(currentPatchModelIDs.length>0){
last_idx = currentPatchSrcs.length-1;
for(idx=0; idx<exampleImgsList.length; idx++){
exampleImgsList[idx].attr("src",
currentPatchSrcs[last_idx][idx][soft0_hard1]);
}
}
}, {
position: 'bottomleft',
id: 'soft_hard_slider',
orientation: 'horizontal',
collapsed: true,
syncSlider: true,
min: 0,
max: 1,
value: 1,
logo: "Sharpness",
size: "171px"
}
).addTo(map);
L.control.slider( // window size slider
function(value){
SELECTION_SIZE = value;
}, {
position: 'bottomleft',
id: 'selection_size_slider',
orientation: 'horizontal',
collapsed: true,
syncSlider: true,
min: 50,
max: 700,
value: 500,
logo: "Patch Size",
size: "171px"
}
).addTo(map);
//----------------------------------------------------------------------
// Setup leaflet-sidebar-v2 and open the "#home" tab
//----------------------------------------------------------------------
var sidebar = L.control.sidebar(
'sidebar', {
position: 'right'
}
).addTo(map);
sidebar.open("home")
//----------------------------------------------------------------------
// Setup map selection handlers
//----------------------------------------------------------------------
map.addEventListener('mousemove', function(e){
curSelPoly = getPolyAround(e.latlng, SELECTION_SIZE)
if(selectionBox === null){
selectionBox = L.polygon(curSelPoly, {
color: "#000000",
fillColor: "#ffffff",
weight: 2
});
selectionBox.addTo(map);
}else{
selectionBox.setLatLngs(curSelPoly);
}
});
map.addEventListener('click', function(e){
curSelPoly = getPolyAround(e.latlng, SELECTION_SIZE);
if(currentSelection === null){ // This condition creates the red selection box on the first click
currentSelection = L.polygon(curSelPoly, {
color: "#ff0000",
fillColor: "#ffffff",
weight: 2
});
currentSelection.addTo(map);
}else{
currentSelection.setLatLngs(curSelPoly);
}
requestPatches(curSelPoly, weights, map);
});
//----------------------------------------------------------------------
// Setup adjustment sliders
//----------------------------------------------------------------------
var updateWeights = function(){
var sumVal = 0;
for(var j=0;j<sliderRanges.length;j++){
sumVal += parseFloat(sliderRanges[j].val());
}
for(var j=0;j<weights.length;j++){
weights[j] = parseFloat(sliderRanges[j].val()) / sumVal;
}
for(var j=0;j<weights.length;j++){
var value = Math.round((Math.round(weights[j]*100)/100)*100);
sliderRanges[j].val(value);
sliderVals[j].html(value);
}
}
for(var i=0;i<sliderRanges.length;i++){
sliderRanges[i].on("input", function(){
updateWeights();
});
}
//----------------------------------------------------------------------
// Setup the example images list
//----------------------------------------------------------------------
for(var i=0; i<ENDPOINTS.length; i++){
var img = $("<img class='exampleImage'>");
img.attr("im-id", i);
img.attr("id", "exampleImage_"+i);
$("#exampleImageList").append(img);
exampleImgsList.push(img);
}
$(".exampleImage").click(function(){
$(".exampleImage").removeClass("active");
$(this).addClass("active");
active_im_id = $(this).attr("im-id")
idx = currentPatches.length-1;
currentPatches[idx].setUrl(currentPatchSrcs[idx][active_im_id][soft0_hard1]);
$(this).attr("src", currentPatchSrcs[idx][active_im_id][soft0_hard1]);
currentPatchModelIDs[idx] = active_im_id;
});
});
</script>
</body>
</html>