@@ -94,6 +94,24 @@ requirejs(['Cesium'], function(Cesium) {
94
94
} ;
95
95
96
96
97
+ Pile . prototype . putDescription = function ( whereToPutDescription , property ) {
98
+ console . log ( this . peoples ) ;
99
+
100
+ var description = document . createDocumentFragment ( ) ;
101
+
102
+
103
+ for ( const peopleId in this . peoples ) {
104
+ if ( this . peoples . hasOwnProperty ( peopleId ) ) {
105
+ var peopleDiv = document . createElement ( 'div' ) ;
106
+ peopleDiv . innerHTML = "<h2>" + peopleId + "</h2>" ;
107
+ description . appendChild ( peopleDiv ) ;
108
+ }
109
+ }
110
+
111
+
112
+ whereToPutDescription . description = description . innerHTML ;
113
+ } ;
114
+
97
115
98
116
/**
99
117
* This class is very closely modeled after the Cesium Data Source example of the same name. It represents the
@@ -350,10 +368,10 @@ requirejs(['Cesium'], function(Cesium) {
350
368
var latitude = parseInt ( geo . lat ) ;
351
369
var longitude = parseInt ( geo . lng ) ;
352
370
353
- var peoples = new Pile ( geo . peoples ) ;
371
+ piles [ x ] = new Pile ( geo . peoples ) ;
354
372
355
373
// TODO make calculation selection a dynamic feature
356
- var heights = peoples . calcHeights ( Pile . heightFormat . JPS ) ;
374
+ var heights = piles [ x ] . calcHeights ( Pile . heightFormat . JPS ) ;
357
375
// var heights = peoples.calcHeights(Pile.heightFormat.PROFESS);
358
376
359
377
// TODO break this into more functions so things are more readily callable when user options are made available.
@@ -369,7 +387,7 @@ requirejs(['Cesium'], function(Cesium) {
369
387
// Create Green Bar
370
388
if ( heights . g > 1 ) {
371
389
entities . add ( new Cesium . Entity ( {
372
- id : "g" + ' index ' + x . toString ( ) ,
390
+ id : "g " + x . toString ( ) ,
373
391
show : true ,
374
392
position : Cesium . Cartesian3 . fromDegrees ( longitude , latitude , heights . g / 2 ) ,
375
393
cylinder : {
@@ -388,7 +406,7 @@ requirejs(['Cesium'], function(Cesium) {
388
406
// Create "SpringGreeen" bar
389
407
if ( heights . s > 1 ) {
390
408
entities . add ( new Cesium . Entity ( {
391
- id : "s" + ' index ' + x . toString ( ) ,
409
+ id : "s " + x . toString ( ) ,
392
410
show : true ,
393
411
position : Cesium . Cartesian3 . fromDegrees ( longitude , latitude , heights . g + ( heights . s / 2 ) ) ,
394
412
cylinder : {
@@ -407,7 +425,7 @@ requirejs(['Cesium'], function(Cesium) {
407
425
// Create Yellow bar
408
426
if ( heights . y > 1 ) {
409
427
entities . add ( new Cesium . Entity ( {
410
- id : "y" + ' index ' + x . toString ( ) ,
428
+ id : "y " + x . toString ( ) ,
411
429
show : true ,
412
430
position : Cesium . Cartesian3 . fromDegrees ( longitude , latitude , heights . g + heights . s + ( heights . y / 2 ) ) ,
413
431
cylinder : {
@@ -426,7 +444,7 @@ requirejs(['Cesium'], function(Cesium) {
426
444
// Create Orange bar
427
445
if ( heights . o > 1 ) {
428
446
entities . add ( new Cesium . Entity ( {
429
- id : "o" + ' index ' + x . toString ( ) ,
447
+ id : "o " + x . toString ( ) ,
430
448
show : true ,
431
449
position : Cesium . Cartesian3 . fromDegrees ( longitude , latitude , heights . g + heights . s + heights . y + ( heights . o / 2 ) ) ,
432
450
cylinder : {
@@ -445,7 +463,8 @@ requirejs(['Cesium'], function(Cesium) {
445
463
// Create Red bar
446
464
if ( heights . r > 1 ) {
447
465
entities . add ( new Cesium . Entity ( {
448
- id : "r" + ' index ' + x . toString ( ) ,
466
+ id : "r " + x . toString ( ) ,
467
+ description : "this is a desc" ,
449
468
show : true ,
450
469
position : Cesium . Cartesian3 . fromDegrees ( longitude , latitude , heights . g + heights . s + heights . y + heights . o + ( heights . r / 2 ) ) ,
451
470
cylinder : {
@@ -492,17 +511,17 @@ requirejs(['Cesium'], function(Cesium) {
492
511
//Create a Viewer instances and add the DataSource.
493
512
var viewer = new Cesium . Viewer ( 'cesiumContainer' , {
494
513
animation : false ,
495
- timeline : false ,
514
+ baseLayerPicker : false ,
515
+ fullscreenButton : false , // wil be manually created later, to put it into the toolbar
496
516
geocoder : false ,
517
+ infoBox : true ,
497
518
navigationInstructionsInitiallyVisible : false ,
498
519
imageryProvider : new Cesium . BingMapsImageryProvider ( {
499
520
url : '//dev.virtualearth.net'
500
521
} ) ,
501
522
skyAtmosphere : false ,
502
523
skyBox : false ,
503
- baseLayerPicker : false ,
504
- infoBox : true ,
505
- fullscreenButton : false ,
524
+ timeline : false ,
506
525
scene : {
507
526
globe : {
508
527
enableLighting : true
@@ -512,6 +531,35 @@ requirejs(['Cesium'], function(Cesium) {
512
531
513
532
viewer . infoBox . frame . sandbox = "allow-same-origin allow-top-navigation allow-pointer-lock allow-popups allow-forms allow-scripts" ;
514
533
534
+ // Prevent camera from getting locked to entity via double-click
535
+ viewer . cesiumWidget . screenSpaceEventHandler . setInputAction ( function ( ) { } , Cesium . ScreenSpaceEventType . LEFT_DOUBLE_CLICK ) ;
536
+
537
+ // make selections switch to the intended entity, instead of the actually-clicked entity.
538
+ viewer . cesiumWidget . screenSpaceEventHandler . setInputAction ( function ( movement ) {
539
+ var clickedOn = viewer . scene . pick ( movement . position ) ,
540
+ clickedEntity = ( Cesium . defined ( clickedOn ) ) ? clickedOn . id : undefined ;
541
+ if ( Cesium . defined ( clickedEntity ) && Cesium . defined ( clickedEntity . cylinder ) ) {
542
+
543
+ //TODO select the representative entity here.
544
+ viewer . selectedEntity = handleSelection ( clickedEntity ) ;
545
+
546
+ // clickedEntity.cylinder.material = Cesium.Color.WHITE.withAlpha(0.9);
547
+ } else {
548
+ viewer . selectedEntity = undefined ;
549
+ }
550
+ } , Cesium . ScreenSpaceEventType . LEFT_CLICK ) ;
551
+
552
+ // var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
553
+ // handler.setInputAction(function(movement) {
554
+ // var pickedPrimitive = viewer.scene.pick(movement.endPosition);
555
+ // var pickedEntity = (Cesium.defined(pickedPrimitive)) ? pickedPrimitive.id : undefined;
556
+ // // Highlight the currently picked entity
557
+ // if (Cesium.defined(pickedEntity) && Cesium.defined(pickedEntity.billboard)) {
558
+ // pickedEntity.billboard.scale = 2.0;
559
+ // pickedEntity.billboard.color = Cesium.Color.ORANGERED;
560
+ // }
561
+ // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
562
+
515
563
viewer . scene . globe . enableLighting = true ;
516
564
517
565
new Cesium . FullscreenButton ( viewer . _toolbar ) ;
@@ -549,4 +597,32 @@ requirejs(['Cesium'], function(Cesium) {
549
597
nasaCredit = new Cesium . Credit ( 'NASA Socioeconomic Data and Applications Center (SEDAC)' , 'assets/nasa-logo.svg' , 'http://sedac.ciesin.columbia.edu/data/collection/gpw-v4' ) ;
550
598
viewer . scene . frameState . creditDisplay . addDefaultCredit ( jpCredit ) ;
551
599
viewer . scene . frameState . creditDisplay . addDefaultCredit ( nasaCredit ) ;
600
+
601
+
602
+ var describedEntities = [ ] ,
603
+ now = Cesium . JulianDate . now ( ) ,
604
+ piles = [ ] ;
605
+
606
+ function handleSelection ( selectedEntity ) {
607
+ var pileId = parseInt ( selectedEntity . id . split ( ' ' , 2 ) [ 1 ] ) ;
608
+
609
+ if ( describedEntities [ pileId ] === undefined ) {
610
+ var position = selectedEntity . position . getValue ( now ) ;
611
+ position = Cesium . Cartographic . fromCartesian ( position ) ;
612
+ describedEntities [ pileId ] = new Cesium . Entity ( {
613
+ id : "DE " + pileId . toString ( ) ,
614
+ show : true ,
615
+ position : Cesium . Cartesian3 . fromRadians ( position . longitude , position . latitude , 0 ) ,
616
+ seriesName : "DE"
617
+ } ) ;
618
+
619
+ describedEntities [ pileId ] . description = "<i class='loading'>Loading...</i>" ;
620
+
621
+ piles [ pileId ] . putDescription ( describedEntities [ pileId ] , 'description' ) ;
622
+ }
623
+
624
+ return describedEntities [ pileId ] ;
625
+ }
552
626
} ) ;
627
+
628
+ var v ;
0 commit comments