|
22 | 22 | </style>
|
23 | 23 | <div id="cesiumContainer" class="fullSize"></div>
|
24 | 24 | <div id="loadingOverlay"><h1>Loading...</h1></div>
|
25 |
| -<div id="toolbar"></div> |
| 25 | +<div id="toolbar"> |
| 26 | + <div id="propertiesMenu"></div> |
| 27 | +</div> |
| 28 | +</div> |
26 | 29 |
|
27 | 30 | <script id="cesium_sandcastle_script">
|
28 | 31 | function startup(Cesium) {
|
|
33 | 36 | "name" : "CZML Custom Properties",
|
34 | 37 | "version" : "1.0",
|
35 | 38 | "clock": {
|
36 |
| - "interval": "1990/2010", |
37 |
| - "currentTime": "1990", |
38 |
| - "multiplier": 100000000 |
| 39 | + "interval": "1970/2010", |
| 40 | + "currentTime": "1970", |
| 41 | + "multiplier": 500000000 |
39 | 42 | }
|
40 | 43 | }, {
|
41 | 44 | "id" : "custom_property_object",
|
42 | 45 | "name" : "An object with custom properties",
|
43 | 46 | "properties" : {
|
44 | 47 | "constant_property" : true,
|
45 | 48 | "population_intervals" : [{
|
| 49 | + "interval": "1970/1980", |
| 50 | + "number": 2209600 |
| 51 | + }, { |
| 52 | + "interval": "1980/2090", |
| 53 | + "number": 2889700 |
| 54 | + }, { |
46 | 55 | "interval" : "1990/2000",
|
47 |
| - "number": 11881643 |
| 56 | + "number": 3307600 |
48 | 57 | }, {
|
49 | 58 | "interval" : "2000/2010",
|
50 |
| - "number" : 12281054 |
| 59 | + "number" : 4326900 |
51 | 60 | }],
|
52 | 61 | "population_sampled" : {
|
53 | 62 | "number": [
|
54 |
| - "1990", 11881643, |
55 |
| - "2000", 12281054, |
56 |
| - "2010", 12702379 |
| 63 | + "1970", 2209600, |
| 64 | + "1980", 2889700, |
| 65 | + "1990", 3307600, |
| 66 | + "2000", 4326900, |
| 67 | + "2010", 5049100 |
57 | 68 | ]
|
58 | 69 | }
|
59 | 70 | }
|
60 | 71 | }, {
|
61 |
| - "id" : "pennsylvania", |
62 |
| - "name" : "Pennsylvania", |
| 72 | + "id" : "colorado", |
| 73 | + "name" : "Colorado", |
63 | 74 | "polygon" : {
|
64 | 75 | "positions" : {
|
65 | 76 | "cartographicDegrees" : [
|
66 |
| - -75.5, 42, 0, |
67 |
| - -79.8, 42, 0, |
68 |
| - -79.9, 42.3, 0, |
69 |
| - -80.5, 42, 0, |
70 |
| - -80.5, 39.8, 0, |
71 |
| - -75.7, 39.8, 0, |
72 |
| - -74.5, 40.2, 0, |
73 |
| - -75.2, 40.8, 0, |
74 |
| - -74.7, 41.3, 0 |
| 77 | + -109.03, 41, 0, |
| 78 | + -102.03, 41, 0, |
| 79 | + -102.03, 37, 0, |
| 80 | + -109.03, 37, 0 |
75 | 81 | ]
|
76 | 82 | },
|
77 | 83 | "material" : {
|
|
89 | 95 | var viewer = new Cesium.Viewer('cesiumContainer');
|
90 | 96 | var dataSource = new Cesium.CzmlDataSource();
|
91 | 97 |
|
92 |
| -// custom properties can be queried directly: |
93 |
| -Sandcastle.addToolbarButton('Print values', function() { |
94 |
| - var entity = dataSource.entities.getById('custom_property_object'); |
95 |
| - // get the values of all properties at the current time. |
96 |
| - var propertyValues = entity.properties.getValue(viewer.clock.currentTime); |
97 |
| - console.log('constant_property: ' + propertyValues.constant_property); |
98 |
| - console.log('population_intervals: ' + propertyValues.population_intervals); |
99 |
| - console.log('population_sampled: ' + propertyValues.population_sampled); |
100 |
| -}); |
101 |
| - |
102 |
| -// Custom properties can be used as the value of graphical properties: |
103 |
| -Sandcastle.addToolbarButton('Use interval data', function() { |
104 |
| - var customProperyObject = dataSource.entities.getById('custom_property_object'); |
105 |
| - var intervalProperty = customProperyObject.properties.population_intervals; |
106 |
| - var pennsylvania = dataSource.entities.getById('pennsylvania'); |
107 |
| - |
108 |
| - // Because the population values are so large, we scale them down |
109 |
| - // by 100 so they fit on the screen. |
110 |
| - // If we didn't need to scale, we could directly assign the property |
111 |
| - // to extrudedHeight. |
112 |
| - pennsylvania.polygon.extrudedHeight = scaleProperty(intervalProperty, 1 / 100.0); |
113 |
| -}); |
114 |
| -Sandcastle.addToolbarButton('Use sampled data', function() { |
115 |
| - var customProperyObject = dataSource.entities.getById('custom_property_object'); |
116 |
| - var sampledProperty = customProperyObject.properties.population_sampled; |
117 |
| - var pennsylvania = dataSource.entities.getById('pennsylvania'); |
118 |
| - pennsylvania.polygon.extrudedHeight = scaleProperty(sampledProperty, 1 / 100.0); |
119 |
| -}); |
120 |
| - |
121 | 98 | function scaleProperty(property, scalingFactor) {
|
122 | 99 | // returns a property that scales another property by a constant factor.
|
123 | 100 | return new Cesium.CallbackProperty(function(time, result) {
|
|
127 | 104 | }, property.isConstant);
|
128 | 105 | }
|
129 | 106 |
|
| 107 | +function setExtrudedHeight(propertyName) { |
| 108 | + var customPropertyObject = dataSource.entities.getById('custom_property_object'); |
| 109 | + var property = customPropertyObject.properties[propertyName]; |
| 110 | + var colorado = dataSource.entities.getById('colorado'); |
| 111 | + |
| 112 | + // Because the population values are so large, we scale them down |
| 113 | + // by 50 so they fit on the screen. |
| 114 | + // If we didn't need to scale, we could directly assign the property |
| 115 | + // to extrudedHeight. |
| 116 | + // colorado.polygon.extrudedHeight = scaleProperty(property, 1 / 50.0); |
| 117 | + colorado.polygon.extrudedHeight = scaleProperty(property, 1 / 50.0); |
| 118 | +} |
| 119 | + |
| 120 | +// Custom properties can be used as the value of graphical properties: |
| 121 | +Sandcastle.addToolbarMenu([{ |
| 122 | + text: 'Use interval data', |
| 123 | + onselect: function () { |
| 124 | + setExtrudedHeight('population_intervals'); |
| 125 | + } |
| 126 | +}, { |
| 127 | + text: 'Use sampled data', |
| 128 | + onselect: function () { |
| 129 | + setExtrudedHeight('population_sampled'); |
| 130 | + } |
| 131 | +}], 'propertiesMenu'); |
| 132 | + |
130 | 133 | dataSource.load(czml);
|
131 | 134 | viewer.dataSources.add(dataSource);
|
132 | 135 | viewer.zoomTo(dataSource);//Sandcastle_End
|
|
0 commit comments