-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlong_description.html
547 lines (454 loc) · 20.8 KB
/
long_description.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
<style>
#globecontainer canvas {
position:relative !important;
}
</style>
<div class="row-fluid">
<div class="span12">
<p>
Urban Parks is a <strong>demo application</strong> for PyBossa that shows how you can
crowdsourcing a geo localization problem.
</p>
<p>
This application uses a list of cities from all over the world. The
goal is really simple: navigate the map in order to find an urban park.
</p>
<p>
When the user finds one park, adds one marker to indicate the position and
saves the coordinates in GeoJSON format to easily parse it at a later stage.
</p>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<h2>Results <small>urban parks reported by the volunteers in a 3D globe</small></h2>
<p>This 3D Globe uses the HTML5 WebGL technology for showing the results, each blue pike represents and urban park submitted by a volunteer, almost in realtime from this <strong>demo application</strong>.</p>
<p>You can rotate the globe by clicking on it and dragging it!</p>
<div id="notwebgl" style="display:none">
<span class="label label-danger"><i class="icon-bullhorn"></i> Error:</span>
Sorry, your browser or your GPU do not support WebGL so we can not show you the results in a 3D Globe using WebGL.
<p>
If your browser and your computer would support <strong>WebGL</strong>, you will be able to view the answers from the users in a 3D world globe like this:
</p>
<img src="https://pbs.twimg.com/media/AxxDoY9CIAET_0L.png">
</div>
<div id="globecontainer" style="position:relative;"></div>
<script type="text/javascript" src="/static/globe/third-party/Three/ThreeWebGL.js"></script>
<script type="text/javascript" src="/static/globe/third-party/Three/ThreeExtras.js"></script>
<script type="text/javascript" src="/static/globe/third-party/Three/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="/static/globe/third-party/Three/Detector.js"></script>
<script type="text/javascript" src="/static/globe/third-party/Tween.js"></script>
<script type="text/javascript" src="/static/globe/third-party/Tween.js"></script>
<script type="text/javascript" src="/static/globe/globe.js"></script>
<script>
/**
* dat.globe Javascript WebGL Globe Toolkit
* http://dataarts.github.com/dat.globe
*
* Copyright 2011 Data Arts Team, Google Creative Lab
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
var DAT = DAT || {};
DAT.Globe = function(container, colorFn) {
colorFn = colorFn || function(x) {
var c = new THREE.Color();
c.setHSV( ( 0.6 - ( x * 0.5 ) ), 1.0, 1.0 );
return c;
};
var Shaders = {
'earth' : {
uniforms: {
'texture': { type: 't', value: 0, texture: null }
},
vertexShader: [
'varying vec3 vNormal;',
'varying vec2 vUv;',
'void main() {',
'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'vNormal = normalize( normalMatrix * normal );',
'vUv = uv;',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D texture;',
'varying vec3 vNormal;',
'varying vec2 vUv;',
'void main() {',
'vec3 diffuse = texture2D( texture, vUv ).xyz;',
'float intensity = 1.05 - dot( vNormal, vec3( 0.0, 0.0, 1.0 ) );',
'vec3 atmosphere = vec3( 1.0, 1.0, 1.0 ) * pow( intensity, 3.0 );',
'gl_FragColor = vec4( diffuse + atmosphere, 1.0 );',
'}'
].join('\n')
},
'atmosphere' : {
uniforms: {},
vertexShader: [
'varying vec3 vNormal;',
'void main() {',
'vNormal = normalize( normalMatrix * normal );',
'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'}'
].join('\n'),
fragmentShader: [
'varying vec3 vNormal;',
'void main() {',
'float intensity = pow( 0.8 - dot( vNormal, vec3( 0, 0, 1.0 ) ), 12.0 );',
'gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ) * intensity;',
'}'
].join('\n')
}
};
var camera, scene, sceneAtmosphere, renderer, w, h;
var vector, mesh, atmosphere, point;
var overRenderer;
var imgDir = '/static/img/';
var curZoomSpeed = 0;
var zoomSpeed = 50;
var mouse = { x: 0, y: 0 }, mouseOnDown = { x: 0, y: 0 };
var rotation = { x: 0, y: 0 },
target = { x: Math.PI*3/2, y: Math.PI / 6.0 },
targetOnDown = { x: 0, y: 0 };
var distance = 100000, distanceTarget = 100000;
var padding = 40;
var PI_HALF = Math.PI / 2;
function init() {
container.style.color = '#fff';
container.style.font = '13px/20px Arial, sans-serif';
var shader, uniforms, material;
w = container.offsetWidth || window.innerWidth;
h = container.offsetHeight || window.innerHeight;
camera = new THREE.Camera(
30, w / h, 1, 10000);
camera.position.z = distance;
vector = new THREE.Vector3();
scene = new THREE.Scene();
sceneAtmosphere = new THREE.Scene();
var geometry = new THREE.Sphere(200, 40, 30);
shader = Shaders['earth'];
uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms['texture'].texture = THREE.ImageUtils.loadTexture(imgDir+'world' +
'.jpg');
material = new THREE.MeshShaderMaterial({
uniforms: uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
});
mesh = new THREE.Mesh(geometry, material);
mesh.matrixAutoUpdate = false;
scene.addObject(mesh);
shader = Shaders['atmosphere'];
uniforms = THREE.UniformsUtils.clone(shader.uniforms);
material = new THREE.MeshShaderMaterial({
uniforms: uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
});
mesh = new THREE.Mesh(geometry, material);
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.1;
mesh.flipSided = true;
mesh.matrixAutoUpdate = false;
mesh.updateMatrix();
sceneAtmosphere.addObject(mesh);
geometry = new THREE.Cube(0.75, 0.75, 1, 1, 1, 1, null, false, { px: true,
nx: true, py: true, ny: true, pz: false, nz: true});
for (var i = 0; i < geometry.vertices.length; i++) {
var vertex = geometry.vertices[i];
vertex.position.z += 0.5;
}
point = new THREE.Mesh(geometry);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.autoClear = false;
renderer.setClearColorHex(0x000000, 0.0);
renderer.setSize(w, h);
renderer.domElement.style.position = 'absolute';
container.appendChild(renderer.domElement);
container.addEventListener('mousedown', onMouseDown, false);
container.addEventListener('mousewheel', onMouseWheel, false);
document.addEventListener('keydown', onDocumentKeyDown, false);
window.addEventListener('resize', onWindowResize, false);
container.addEventListener('mouseover', function() {
overRenderer = true;
}, false);
container.addEventListener('mouseout', function() {
overRenderer = false;
}, false);
}
addData = function(data, opts) {
var lat, lng, size, color, i, step, colorFnWrapper;
opts.animated = opts.animated || false;
this.is_animated = opts.animated;
opts.format = opts.format || 'magnitude'; // other option is 'legend'
console.log(opts.format);
if (opts.format === 'magnitude') {
step = 3;
colorFnWrapper = function(data, i) { return colorFn(data[i+2]); }
} else if (opts.format === 'legend') {
step = 4;
colorFnWrapper = function(data, i) { return colorFn(data[i+3]); }
} else {
throw('error: format not supported: '+opts.format);
}
if (opts.animated) {
if (this._baseGeometry === undefined) {
this._baseGeometry = new THREE.Geometry();
for (i = 0; i < data.length; i += step) {
lat = data[i];
lng = data[i + 1];
// size = data[i + 2];
color = colorFnWrapper(data,i);
size = 0;
addPoint(lat, lng, size, color, this._baseGeometry);
}
}
if(this._morphTargetId === undefined) {
this._morphTargetId = 0;
} else {
this._morphTargetId += 1;
}
opts.name = opts.name || 'morphTarget'+this._morphTargetId;
}
var subgeo = new THREE.Geometry();
for (i = 0; i < data.length; i += step) {
lat = data[i];
lng = data[i + 1];
color = colorFnWrapper(data,i);
size = data[i + 2];
size = size*200;
addPoint(lat, lng, size, color, subgeo);
}
if (opts.animated) {
this._baseGeometry.morphTargets.push({'name': opts.name, vertices: subgeo.vertices});
} else {
this._baseGeometry = subgeo;
}
};
function createPoints() {
if (this._baseGeometry !== undefined) {
if (this.is_animated === false) {
this.points = new THREE.Mesh(this._baseGeometry, new THREE.MeshBasicMaterial({
color: 0xffffff,
vertexColors: THREE.FaceColors,
morphTargets: false
}));
} else {
if (this._baseGeometry.morphTargets.length < 8) {
console.log('t l',this._baseGeometry.morphTargets.length);
var padding = 8-this._baseGeometry.morphTargets.length;
console.log('padding', padding);
for(var i=0; i<=padding; i++) {
console.log('padding',i);
this._baseGeometry.morphTargets.push({'name': 'morphPadding'+i, vertices: this._baseGeometry.vertices});
}
}
this.points = new THREE.Mesh(this._baseGeometry, new THREE.MeshBasicMaterial({
color: 0xffffff,
vertexColors: THREE.FaceColors,
morphTargets: true
}));
}
scene.addObject(this.points);
}
}
function addPoint(lat, lng, size, color, subgeo) {
var phi = (90 - lat) * Math.PI / 180;
var theta = (180 - lng) * Math.PI / 180;
point.position.x = 200 * Math.sin(phi) * Math.cos(theta);
point.position.y = 200 * Math.cos(phi);
point.position.z = 200 * Math.sin(phi) * Math.sin(theta);
point.lookAt(mesh.position);
point.scale.z = -size;
point.updateMatrix();
var i;
for (i = 0; i < point.geometry.faces.length; i++) {
point.geometry.faces[i].color = color;
}
GeometryUtils.merge(subgeo, point);
}
function onMouseDown(event) {
event.preventDefault();
container.addEventListener('mousemove', onMouseMove, false);
container.addEventListener('mouseup', onMouseUp, false);
container.addEventListener('mouseout', onMouseOut, false);
mouseOnDown.x = - event.clientX;
mouseOnDown.y = event.clientY;
targetOnDown.x = target.x;
targetOnDown.y = target.y;
container.style.cursor = 'move';
}
function onMouseMove(event) {
mouse.x = - event.clientX;
mouse.y = event.clientY;
var zoomDamp = distance/1000;
target.x = targetOnDown.x + (mouse.x - mouseOnDown.x) * 0.005 * zoomDamp;
target.y = targetOnDown.y + (mouse.y - mouseOnDown.y) * 0.005 * zoomDamp;
target.y = target.y > PI_HALF ? PI_HALF : target.y;
target.y = target.y < - PI_HALF ? - PI_HALF : target.y;
}
function onMouseUp(event) {
container.removeEventListener('mousemove', onMouseMove, false);
container.removeEventListener('mouseup', onMouseUp, false);
container.removeEventListener('mouseout', onMouseOut, false);
container.style.cursor = 'auto';
}
function onMouseOut(event) {
container.removeEventListener('mousemove', onMouseMove, false);
container.removeEventListener('mouseup', onMouseUp, false);
container.removeEventListener('mouseout', onMouseOut, false);
}
function onMouseWheel(event) {
event.preventDefault();
if (overRenderer) {
zoom(event.wheelDeltaY * 0.3);
}
return false;
}
function onDocumentKeyDown(event) {
switch (event.keyCode) {
case 38:
zoom(100);
event.preventDefault();
break;
case 40:
zoom(-100);
event.preventDefault();
break;
}
}
function onWindowResize( event ) {
console.log('resize');
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function zoom(delta) {
distanceTarget -= delta;
distanceTarget = distanceTarget > 1000 ? 1000 : distanceTarget;
distanceTarget = distanceTarget < 350 ? 350 : distanceTarget;
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
zoom(curZoomSpeed);
rotation.x += (target.x - rotation.x) * 0.1;
rotation.y += (target.y - rotation.y) * 0.1;
distance += (distanceTarget - distance) * 0.3;
camera.position.x = distance * Math.sin(rotation.x) * Math.cos(rotation.y);
camera.position.y = distance * Math.sin(rotation.y);
camera.position.z = distance * Math.cos(rotation.x) * Math.cos(rotation.y);
vector.copy(camera.position);
renderer.clear();
renderer.render(scene, camera);
renderer.render(sceneAtmosphere, camera);
}
init();
this.animate = animate;
this.__defineGetter__('time', function() {
return this._time || 0;
});
this.__defineSetter__('time', function(t) {
var validMorphs = [];
var morphDict = this.points.morphTargetDictionary;
for(var k in morphDict) {
if(k.indexOf('morphPadding') < 0) {
validMorphs.push(morphDict[k]);
}
}
validMorphs.sort();
var l = validMorphs.length-1;
var scaledt = t*l+1;
var index = Math.floor(scaledt);
for (i=0;i<validMorphs.length;i++) {
this.points.morphTargetInfluences[validMorphs[i]] = 0;
}
var lastIndex = index - 1;
var leftover = scaledt - index;
if (lastIndex >= 0) {
this.points.morphTargetInfluences[lastIndex] = 1 - leftover;
}
this.points.morphTargetInfluences[index] = leftover;
this._time = t;
});
this.addData = addData;
this.createPoints = createPoints;
this.renderer = renderer;
this.scene = scene;
return this;
};
</script>
<script type="text/javascript">
if(!Detector.webgl){
Detector.addGetWebGLMessage();
$("#notwebgl").show();
} else {
var years = ['Urban Parks'];
var container = document.getElementById('globecontainer');
var globe = new DAT.Globe(container);
var i, tweens = [];
var settime = function(globe, t) {
return function() {
new TWEEN.Tween(globe).to({time: t/years.length},500).easing(TWEEN.Easing.Cubic.EaseOut).start();
};
};
var xhr;
TWEEN.start();
xhr = new XMLHttpRequest();
//xhr.open('GET', 'globe/population909500.json', true);
xhr.open('GET', 'http://crowdcrafting.org/api/taskrun?app_id=149&limit=1000', true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
console.log("Urban Parks demos!!");
//console.log(data);
//console.log(data[0]['info']['city']);
//console.log(data[0]['info']['urbanpark']['geometry']['coordinates']);
window.data = data;
var d = [];
//console.log(data[0]);
//if ('coordinates' in data[0]['info']['urbanpark']['geometry'])
for (i=0;i<data.length;i++) {
console.log(data[i]['info']['urbanpark']);
if (typeof data[i]['info']['urbanpark'] !== 'string')
{
d.push(data[i]['info']['urbanpark']['geometry']['coordinates'][1],
data[i]['info']['urbanpark']['geometry']['coordinates'][0],
0.07);
}
}
d = [['Urban Parks', d]];
console.log(d);
data = d;
for (i=0;i<data.length;i++) {
globe.addData(data[i][1], {format: 'magnitude', name: data[i][0], animated: true});
}
globe.createPoints();
settime(globe,0)();
globe.animate();
}
}
};
xhr.send(null);
}
</script>
<span class="label label-warning">
<i class="icon icon-white icon-bullhorn"></i>
Note</span> If you want to learn more about how to use this application as a template,
check the:
<ul>
<li><a href="http://github.com/PyBossa/app-geocoding">source code</a>,</li>
<li><a href="https://docs.google.com/spreadsheet/ccc?key=0AsNlt0WgPAHwdGZnbjdwcnhKRVNlN1dGXy0tTnNWWXc&usp=sharing">Google Spreadsheet Task template</a>,</li>
<li><a href="http://app-geocoding.readthedocs.org/en/latest/index.html"> specific documentation,</a></li>
<li><a href="http://docs.pybossa.com/">the official documentation of PyBossa</a> and </li>
<li><a href="http://docs.pybossa.com/en/latest/user/tutorial.html">the step by step tutorial.</a></li>
</ul>
</p>
</div>
</div>