forked from jgcasta/lostatnight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.html
676 lines (540 loc) · 21.5 KB
/
template.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
<link href="http://www.iderail.es/testiss/css/ol.css" rel="stylesheet">
<style type="text/css">
.map {
float: left;
padding: 10px 10px;
height: 475px;
width: 475px;
}
.mapOSM {
float: left;
padding: 10px 10px;
height:475px;
width: 475px;
}
.mapVIIRS {
float: left;
padding: 10px 10px;
height:300px;
width: 475px;
}
.txtOSM {
float: left;
padding: 5px 5px;
height:160px;
width: 160px;
}
.container {
margin-right: 10px;
margin-left: 10px;
}
</style>
<div class="row">
<!-- Success and Error Messages for the user -->
<div class="span6 offset2" style="height:10px">
<div id="success" class="alert alert-success" style="display:none;">
<a class="close">×</a>
<strong>Well done!</strong> Your answer has been saved
</div>
<div id="loading" class="alert alert-info" style="display:none;">
<a class="close">×</a>
Loading next task...
</div>
<div id="taskcompleted" class="alert alert-info" style="display:none;">
<strong>The task has been completed!</strong> Thanks a lot!
</div>
<div id="finish" class="alert alert-success" style="display:none;">
<strong>Congratulations!</strong> You have participated in all available tasks!
<br/>
<div class="alert-actions">
<a class="btn small" href="/">Go back</a>
<a class="btn small" href="/app">or, Check other applications</a>
</div>
</div>
<div id="error" class="alert alert-error" style="display:none;">
<a class="close">×</a>
<strong>Error!</strong> Something went wrong, please contact the site administrators
</div>
</div> <!-- End Success and Error Messages for the user -->
</div> <!-- End of Row -->
<div class="row skeleton" style="width:1550px"> <!-- Start Skeleton Row-->
<div class="span12" style="width:1550px"><!-- Start of Question and Submission DIV (column) -->
<h1 id="question">Do you know about this City?</h1> <!-- The question will be loaded here -->
<div id="step1" class="btn-group" style="text-align:center"> <!-- Start DIV for the submission buttons -->
<div id="answer" class="btn-group" style="text-align:center"> <!-- Start DIV for the submission buttons -->
<button class="btn btn-large btn-answer" value='save'>Save</button>
<button class="btn btn-large btn-answer" value='404'>No photo</button>
<button class="btn btn-large btn-answer" value='unknown'>I don't know</button>
</div><!-- End of DIV for the submission buttons -->
</div><!-- End of DIV for the submission buttons -->
<!-- Link to picture data provided by NASA site -->
<div>
<span class="label label-danger">Please, be patient with large ISS images</span><br> Use de [+] and [-] buttons to Zoom In and Zoom Out. Press Shift + Left Mouse Button to rotate the image <br><a id="hrefPicture" href='' target='_blank'>ISS picture data - Earth Science and Remote Sensing Unit, NASA-Johnson Space Center. "The Gateway to Astronaut Photography of Earth."</a></div>
<!-- These are maps -->
<div id="map" class="map"></div>
<div id="mapOSM" class="mapOSM"></div>
<!-- DataList to save -->
<form id='dataList' name='dataList'>
<input type='button' onClick="removeOptions()"; value='Remove Selected'><br>
<span class="label label-info" >XY</span> <input type='text' name='xyValues' style="width:150px">
<span class="label label-info" >Lon, Lat</span> <input type='text' name='lonlatValues' style="width:150px"><br><br>
<span class="label label-info">2012 Night View from NPP-VIIRS</span>
<div id="mapVIIRS" class="mapVIIRS"></div>
</form>
</div><!-- End of DIV for the submission buttons -->
<!-- -------------- Social buttons ------------- -->
<div>
<div id="Twitter-share-section" style='float: left'>
<a href="https://twitter.com/share" class="twitter-share-button" data-text="Check this amazing picture and help us to georreference it" data-size="large" data-hashtags="LostAtNight">Tweet</a>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div> <!-- end twitter -->
<div class="g-plusone" style="float:left" data-annotation="inline" data-width="300"></div>
<script type="text/javascript">
window.___gcfg = {lang: 'es'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<div style="float:left">
<div id="fb-like" class="fb-like" data-href="http://www.cowdcrafting.org/app/LostAtNight" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
<div id="fb-root"></div>
</div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_ES/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
</div>
<!-- -------------- End social buttons -------------------- -->
</div><!-- End of DIV for the submission buttons -->
<div class="row skeleton" style="margin-top:15px;"> <!-- Start Skeleton Row-->
<div class="span8 offset2"><!-- Start of Question and Submission DIV (column) -->
<p>You are working now on task: <span id="task-id" class="label label-warning">#</span></p>
<p>You have completed: <span id="done" class="label label-info"></span> tasks from
<!-- Progress bar for the user -->
<span id="total" class="label label-info"></span></p>
<div class="progress progress-striped">
<div id="progress" rel="tooltip" title="#" class="bar" style="width: 0%;"></div>
</div>
<!--
This application uses Disqus to allow users to provide some feedback.
The next section includes a button that when a user clicks on it will
load the comments, if any, for the given task
-->
<div id="disqus_show_btn" style="margin-top:5px;">
<button class="btn btn-primary btn-large btn-disqus" onclick="loadDisqus()"><i class="icon-comments"></i> Show comments</button>
<button class="btn btn-large btn-disqus" onclick="loadDisqus()" style="display:none"><i class="icon-comments"></i> Hide comments</button>
</div><!-- End of Disqus Button section -->
<!-- Disqus thread for the given task -->
<div id="disqus_thread" style="margin-top:5px;display:none"></div>
</div><!-- End of Question and Submission DIV (column) -->
</div><!-- End of Skeleton Row -->
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
/* * * DON'T EDIT BELOW THIS LINE * * */
function loadDisqus() {
$("#disqus_thread").toggle();
$(".btn-disqus").toggle();
var disqus_shortname = 'pybossa';
var disqus_identifier = taskId;
var disqus_developer = 1;
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
}
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="https://earthdata.nasa.gov/labs/gibs/examples/openlayers2/lib/openlayers-2.13.1/OpenLayers.js"></script>
<script>
function loadUserProgress() {
pybossa.userProgress('LostAtNight').done(function(data){
var pct = Math.round((data.done*100)/data.total);
$("#progress").css("width", pct.toString() +"%");
$("#progress").attr("title", pct.toString() + "% completed!");
$("#progress").tooltip({'placement': 'left'});
$("#total").text(data.total);
$("#done").text(data.done);
});
}
var xy;
var lonlat;
var clickImg = false;
var clickMap = false;
var urlImage = '';
pybossa.taskLoaded(function(task, deferred) {
if ( !$.isEmptyObject(task) ) {
task.answer = {
'imageResult' : '',
'XY': '',
'LONLAT': '',
'img_big': task.info.link_big,
'rotationAngle' : ''
}
deferred.resolve(task);
}
else {
deferred.resolve(task);
}
updateTwitterValues(window.location.href);
});
pybossa.presentTask(function(task, deferred) {
if ( !$.isEmptyObject(task) ) {
loadUserProgress();
// first time I load the whole map
if (firstTime){
loadOSM(task.info.citylon,task.info.citylat,7);
loadISSImage(task.info.link_big);
firstTime = false;
}
$("#question").html(task.info.question);
$('#task-id').html(task.id);
$('.btn-answer').off('click').on('click', function(evt) {
$("#hrefPicture").attr("href",task.info.linkData);
$("#fb-like").attr("data-href",task.info.linkData);
var answer = $(evt.target).attr("value");
urlImage = task.info.link_big;
if (typeof answer != 'undefined') {
if (answer == 'save'){
$("#step1").hide();
task.answer.XY = document.dataList.xyValues.value;
task.answer.LONLAT = document.dataList.lonlatValues.value;
xy = '';
lonlat = '';
//task.answer.rotationAngle = getRotationAngle();
pybossa.saveTask(task.id, task.answer).done(function() {
deferred.resolve();
});
$("#step1").show();
//center OSM map if aprox location is known
if (task.info.citylon != ''){
changeMapOSM(task.info.citylon,task.info.citylat,7);
}else{
changeMapOSM(0,0,1);
}
removeAllOptions();
loadNewISSImage(urlImage);
pybossa.saveTask(task.id, task.answer).done(function() {
deferred.resolve();
});
}else if (answer == '404'){
removeAllOptions();
//center OSM map if aprox location is known
if (task.info.citylon != ''){
changeMapOSM(task.info.citylon,task.info.citylat,7);
}else{
changeMapOSM(0,0,1);
}
loadNewISSImage(urlImage);
task.answer.imageResult = '404';
pybossa.saveTask(task.id, task.answer).done(function() {
deferred.resolve();
});
}else {
removeAllOptions();
//center OSM map if aprox location is known
if (task.info.citylon != ''){
changeMapOSM(task.info.citylon,task.info.citylat,7);
}else{
changeMapOSM(0,0,1);
}
loadNewISSImage(urlImage);
task.answer.imageResult = 'unknown';
pybossa.saveTask(task.id, task.answer).done(function() {
deferred.resolve();
});
}
}
});
//$("#loading").hide();
}
else {
$(".skeleton").hide();
//$("#loading").hide();
$("#finish").fadeIn(500);
}
});
function updateTwitterValues(share_url) {
$("#Twitter-share-section").html(' ');
$("#Twitter-share-section").html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+share_url+'" data-text="Check out this amazing image!" data-size="large" data-hashtags="LostAtNight">Tweet</a>');
//twttr.widgets.load();
}
// functions to show ISS picture and OSM Map
var firstTime = true;
var clickImg = false;
var clickMap = false;
var pixelProjection;
var iconStyle = new ol.style.Style({
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color: [255, 0, 0, 1]
}),
stroke: new ol.style.Stroke({
color: [255, 0, 0, 1],
width: 1.5
})
}),
zIndex: 1
});
var iconStyleVIIRS = new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: [255, 0, 0, 1]
}),
stroke: new ol.style.Stroke({
color: [255, 0, 0, 1],
width: 1.5
})
}),
zIndex: 1
});
var iconFeature;
var map;
var ISSlayer;
function createISSLayer(urlImage, imgX, imgY){
pixelProjection = new ol.proj.Projection({
code: 'pixel',
units: 'pixels',
extent: [0, 0, eval(imgX), eval(imgY)]
});;
ISSlayer = new ol.layer.Image({
source: new ol.source.ImageStatic({
attributions: [
new ol.Attribution({
html: '<a href="http://guaix.fis.ucm.es/DarkSkies">ISS - GUAIX UCM</a>'
})
],
url: urlImage,
imageSize: [eval(imgX), eval(imgY)],
projection: pixelProjection,
imageExtent: pixelProjection.getExtent()
})
});
}
var dimX,dimY;
function loadISSImage(urlImage){
$("#loading").show();
var dim = new Array();
var img = new Image();
img.onload = function() {
dim[0] = this.width;
dim[1] = this.height;
dimX = dim[0];
dimY = dim[1];
createISSLayer(urlImage, dimX, dimY);
map = new ol.Map({
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()
]),
layers: [ISSlayer],
target: 'map',
view: new ol.View({
projection: pixelProjection,
center: ol.extent.getCenter(pixelProjection.getExtent()),
zoom: 1
})
});
map.on('click', function(evt) {
var coordinate = evt.coordinate;
var xy = ol.coordinate.toStringXY(ol.proj.transform(coordinate, pixelProjection, pixelProjection));
if (clickImg == false){
document.dataList.xyValues.value = xy;
addPointLayer();
clickImg = true;
clickMap = false;
}
});
$("#loading").hide();
} // img.load
img.src = urlImage;
} // loadISSImage
function getRotationAngle(){
var currentRadians = map.getView().getView().getRotation();
return currentRadians;
}
function unloadISSImage(){
window.map.removeLayer(ISSlayer);
}
function loadNewISSImage(urlImage){
$("#loading").show();
var dim = new Array();
var img = new Image();
img.onload = function() {
dim[0] = this.width;
dim[1] = this.height;
dimX = dim[0];
dimY = dim[1];
map.removeLayer(ISSlayer);
createISSLayer(urlImage, dimX, dimY);
map.addLayer(ISSlayer);
$("#loading").hide();
} // img.load
img.src = urlImage;
}
function handleMapClick(evt) {
if (clickMap == false){
var lonlat = mapOSM.getLonLatFromViewPortPx(evt.xy).transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
var coord = lonlat.lon.toFixed(6) + ',' + lonlat.lat.toFixed(6);
document.dataList.lonlatValues.value = coord;
addPointLayerOSM();
clickMap = true;
clickImg = false;
mapOSM.addLayer(pointLayerOSM);
}
}
var mapOSM;
var osmlayer = new OpenLayers.Layer.OSM();
var gmaplayerSt = new OpenLayers.Layer.Google("Google Streets",{numZoomLevels: 20});
var gmaplayerSat = new OpenLayers.Layer.Google("Google Satellite",{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22});
var fromProjection = new OpenLayers.Projection("EPSG:4326");
var toProjection = new OpenLayers.Projection("EPSG:900913");
function loadOSM(lonOSM, latOSM, zoomOSM){
mapOSM = new OpenLayers.Map({
div: "mapOSM",
projection: "EPSG:4326"
});
mapOSM.addLayers([gmaplayerSt,gmaplayerSat,osmlayer]);
mapOSM.addControl(new OpenLayers.Control.LayerSwitcher());
var centerPosition = new OpenLayers.LonLat(eval(lonOSM),eval(latOSM)).transform( fromProjection, toProjection);
mapOSM.setCenter(centerPosition, zoomOSM );
mapOSM.events.register('click', mapOSM, handleMapClick);
//load VIIRS help map
mapVIIRS = new ol.Map({
target: 'mapVIIRS',
layers: [
viirs
],
view: new ol.View({
projection: ol.proj.get("EPSG:4326"),
extent: [-180, -90, 180, 90],
center: [0,0],
zoom: 1
})
});
var icons = [];
nadirISS = new ol.Feature({ geometry: new ol.geom.Point([eval(lonOSM),eval(latOSM)])});
nadirISS.setStyle(iconStyleVIIRS);
icons.push(nadirISS);
nadirLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: icons }) });
mapVIIRS.addLayer(nadirLayer);
} // loadOSM
function changeMapOSM(lonOSM, latOSM, zoomOSM){
// change OSM
var centerPosition = new OpenLayers.LonLat(eval(lonOSM),eval(latOSM)).transform( fromProjection, toProjection);
mapOSM.setCenter(centerPosition, zoomOSM );
// change VIIRS
mapVIIRS.removeLayer(nadirLayer);
var icons = [];
nadirISS = new ol.Feature({ geometry: new ol.geom.Point([eval(lonOSM),eval(latOSM)])});
nadirISS.setStyle(iconStyleVIIRS);
icons.push(nadirISS);
nadirLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: icons }) });
mapVIIRS.addLayer(nadirLayer);
}
function addPointLayer(){
window.map.removeLayer(pointLayer);
var pos = [];
var icons = [];
if(typeof dataList.xyValues.value != 'undefined'){
pos = dataList.xyValues.value.split(',');
iconFeature = new ol.Feature({ geometry: new ol.geom.Point([eval(pos[0]), eval(pos[1])])});
iconFeature.setStyle(iconStyle);
icons.push(iconFeature);
}
pointLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: icons })
})
map.addLayer(pointLayer);
}
var pointLayer;
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
var pointLayerOSM = new OpenLayers.Layer.Vector('Points', {
styleMap: new OpenLayers.StyleMap({
pointRadius: "5",
fillColor: "#fc0000"
}),
renderers: renderer
});
function addPointLayerOSM(){
//window.mapOSM.removeLayer(pointLayerOSM);
pointLayerOSM.destroyFeatures();
if(typeof featureP != 'undefined'){
console.log('borrando ' + featureP);
pointLayerOSM.destroyFeatures();
}
var posOSM = [];
var iconsOSM = [];
var features = new Array(50);
if(typeof dataList.lonlatValues.value != 'undefined'){
posOSM = dataList.lonlatValues.value.split(',');
var point = new OpenLayers.Geometry.Point(eval(posOSM[0]), eval(posOSM[1]));
point.transform(fromProjection, toProjection);
var featureP = new OpenLayers.Feature.Vector(point);
pointLayerOSM.addFeatures([featureP]);
}
//mapOSM.addLayer(pointLayerOSM);
}
function removePoint(){
window.map.removeLayer(pointLayer);
pointLayerOSM.destroyFeatures();
}
var sourceViirs = new ol.source.WMTS({
urls: [
"https://map1a.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi",
"https://map1b.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi",
"https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi",
],
layer: "VIIRS_CityLights_2012",
format: "image/jpeg",
matrixSet: "EPSG4326_500m",
tileGrid: new ol.tilegrid.WMTS({
origin: [-180, 90],
resolutions: [
0.5625,
0.28125,
0.140625,
0.0703125,
0.03515625,
0.017578125,
0.0087890625,
0.00439453125,
0.002197265625
],
matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8],
tileSize: 512
}),
attributions: [
new ol.Attribution({html:"NASA NPP - VIIRS"})
]
});
var viirs = new ol.layer.Tile({source: sourceViirs});
// auxiliar functions
function removeOptions(){
var xyDeleted = false;
window.map.removeLayer(pointLayer);
window.mapOSM.removeLayer(pointLayerOSM);
dataList.xyValues.value = '';
dataList.lonlatValues.value = '';
xyDeleted = true;
addPointLayer();
addPointLayerOSM();
}
function removeAllOptions(){
removePoint();
dataList.xyValues.value = '';
dataList.lonlatValues.value = '';
}
pybossa.run('LostAtNight');
</script>