forked from OpenDroneMap/UAVArena
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
262 lines (237 loc) · 8.2 KB
/
main.js
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
$(function(){
// To add new datasets:
// 1. Add the necessary folders in the repository
// 2. Add the proper entries below
var datasets = [
{
id: 'aukerman',
label: "Aukerman",
center: new L.LatLng(41.30442, -81.75232)
},
{
id: 'brighton_beach',
label: "Brighton Beach",
center: new L.LatLng(46.84261, -91.99402)
},
{
id: 'sand_key',
label: "Sand Key",
center: new L.LatLng(27.95864, -82.83185)
},
];
var engines = [
{
id: "odm-0.9.9",
label: "ODM 0.9.9",
},
{
id: "odm-2.1.1",
label: "ODM 2.1.1"
},
{
id: "odm-2.4.7",
label: "ODM 2.4.7",
},
{
id: "odm-2.8.0",
label: "ODM 2.8.0",
},
{
id: "odm-3.0.0",
label: "ODM 3.0.0",
rightStart: true
},
{
id: "dronedeploy-2.59.0",
label: "Drone Deploy 2.59.0",
leftStart: true
},
{
id: "metashape-1.5.2",
label: "Metashape 1.5.2"
},
{
id: "dronemapper-1.9",
label: "DroneMapper 1.9"
},
{
id: "nodemicmac-0.0.1",
label: "NodeMICMAC 0.0.1"
},
{
id: "pix4d-4.4.10",
label: "Pix4D 4.4.10"
},
]
// Add functionality to the btn for switching comparison type
$("#btnChangeComparison").on("click", function(){
var comparisonType = $("#btnChangeComparison").attr("data-comparison");
if (comparisonType === "sideBySide"){
$("#btnChangeComparison").attr("data-comparison", "sync");
$("#btnChangeComparison").text("Switch to slider comparison");
// get center and zoom of sideBySide map and set sync map to it
syncMap1.setView(sideBySideMap.getCenter(), sideBySideMap.getZoom());
updateLayers();
}else{
$("#btnChangeComparison").attr("data-comparison", "sideBySide");
$("#btnChangeComparison").text("Switch to synced comparison");
// get center and zoom of sync map and set sideBySide map to it
sideBySideMap.setView(syncMap1.getCenter(), syncMap1.getZoom());
updateLayers();
}
});
// Initiate maps
var sideBySideMap = L.map('sideBySideMap', {
zoom: 20,
center: datasets[0].center
});
var syncMap1 = L.map('syncMap1', {
zoom: 20,
center: datasets[0].center
});
var syncMap2 = L.map('syncMap2', {
zoom: 20,
center: datasets[0].center,
zoomControl: false
});
// Create and add an OSM reference layer to each map
// (we cannot create just one L.tileLayer and initiate all 3 maps with it)
var osmTileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmTileConfig = {
maxZoom: 99,
maxNativeZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}
L.tileLayer(osmTileUrl, osmTileConfig).addTo(sideBySideMap);
L.tileLayer(osmTileUrl, osmTileConfig).addTo(syncMap1);
L.tileLayer(osmTileUrl, osmTileConfig).addTo(syncMap2);
// Sync the two synced maps per https://github.com/jieter/Leaflet.Sync
syncMap1.sync(syncMap2);
syncMap2.sync(syncMap1);
// Populate datasets
var $dataset = $("#dataset");
$dataset.on('change', function(e){
updateLayers("dataset");
});
for (var i in datasets){
var d = datasets[i];
var $opt = $('<option value="' + d.id + '">' + d.label + '</option>');
$dataset.append($opt);
}
// Populate engines
var $leftEngine = $("#leftEngine");
$leftEngine.on('change', function(e){
if ($(this).val() !== $rightEngine.val()){
updateLayers();
}else{
var engId = null;
for (var k in engines){
if (engines[k].id !== $rightEngine.val()){
engId = engines[k].id;
break;
}
}
$(this).val(engId);
updateLayers();
}
});
var $rightEngine = $("#rightEngine");
$rightEngine.on('change', function(e){
if ($(this).val() !== $leftEngine.val()){
updateLayers();
}else{
var engId = null;
for (var k in engines){
if (engines[k].id !== $leftEngine.val()){
engId = engines[k].id;
break;
}
}
$(this).val(engId);
updateLayers();
}
});
for (var i in engines){
var e = engines[i];
var $opt = $('<option value="' + e.id + '"' + (e.rightStart ? 'selected' : '') + '>' + e.label + '</option>');
$rightEngine.append($opt);
$opt = $('<option value="' + e.id + '"' + (e.leftStart ? 'selected' : '') + '>' + e.label + '</option>');
$leftEngine.append($opt);
}
var $product = $("#product");
$product.on("change", function(){
updateLayers();
});
var leftLayer, rightLayer;
var prefix = "/";
if (window.location.href.toLowerCase().indexOf("opendronemap.github.io") !== -1){
prefix = "/UAVArena/";
}
var layerConfig = {
noWrap: true,
maxZoom: 99,
maxNativeZoom: 21,
tms: true
}
var sideBySide = L.control.sideBySide([], []).addTo(sideBySideMap);
var cleanLayers = function(){
if (sideBySideMap.hasLayer(leftLayer)) sideBySideMap.removeLayer(leftLayer);
if (sideBySideMap.hasLayer(rightLayer)) sideBySideMap.removeLayer(rightLayer);
if (syncMap1.hasLayer(leftLayer)) syncMap1.removeLayer(leftLayer);
if (syncMap2.hasLayer(rightLayer)) syncMap2.removeLayer(rightLayer);
}
var updateSideBySideLayers = function(){
leftLayer = L.tileLayer(prefix + 'data/' + $leftEngine.val() +'/' +
$dataset.val() + '/' + $product.val() + '/tiles/{z}/{x}/{y}.png', layerConfig);
rightLayer = L.tileLayer(prefix + 'data/' + $rightEngine.val() +'/' +
$dataset.val() + '/' + $product.val() + '/tiles/{z}/{x}/{y}.png', layerConfig);
if (leftLayer){
leftLayer.addTo(sideBySideMap);
sideBySide.setLeftLayers([leftLayer]);
}else{
sideBySide.setLeftLayers([]);
}
if (rightLayer){
rightLayer.addTo(sideBySideMap);
sideBySide.setRightLayers([rightLayer]);
}else{
sideBySide.setRightLayers([]);
}
};
var updateSyncLayers = function(){
leftLayer = L.tileLayer(prefix + 'data/' + $leftEngine.val() +'/' +
$dataset.val() + '/' + $product.val() + '/tiles/{z}/{x}/{y}.png', layerConfig);
rightLayer = L.tileLayer(prefix + 'data/' + $rightEngine.val() +'/' +
$dataset.val() + '/' + $product.val() + '/tiles/{z}/{x}/{y}.png', layerConfig);
if (leftLayer) leftLayer.addTo(syncMap1);
if (rightLayer) rightLayer.addTo(syncMap2);
};
var updateLayers = function(updateType){
cleanLayers();
// Center the map on the dataset *if* the dataset changes,
// because then we're jumping to a different location
if(updateType === "dataset"){
for (var k in datasets){
if (datasets[k].id === $dataset.val()){
syncMap1.panTo(datasets[k].center);
sideBySideMap.panTo(datasets[k].center);
break;
}
}
}
// show hide the maps according to which comparison is active
var comparisonType = $("#btnChangeComparison").attr("data-comparison");
if (comparisonType === "sideBySide"){
$("#syncMap1").hide();
$("#syncMap2").hide();
$("#sideBySideMap").show();
updateSideBySideLayers();
}else{
$("#syncMap1").show();
$("#syncMap2").show();
$("#sideBySideMap").hide();
updateSyncLayers();
}
};
updateLayers();
});