Skip to content

Commit f9bfe99

Browse files
author
Hannah
authored
Merge pull request #6086 from klim705/czml-custom-properties
Cleanup CZML custom properties demo
2 parents b9cc59d + 68f9870 commit f9bfe99

File tree

3 files changed

+55
-49
lines changed

3 files changed

+55
-49
lines changed

Apps/Sandcastle/gallery/CZML Custom Properties.html

+52-49
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
</style>
2323
<div id="cesiumContainer" class="fullSize"></div>
2424
<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>
2629

2730
<script id="cesium_sandcastle_script">
2831
function startup(Cesium) {
@@ -33,45 +36,48 @@
3336
"name" : "CZML Custom Properties",
3437
"version" : "1.0",
3538
"clock": {
36-
"interval": "1990/2010",
37-
"currentTime": "1990",
38-
"multiplier": 100000000
39+
"interval": "1970/2010",
40+
"currentTime": "1970",
41+
"multiplier": 500000000
3942
}
4043
}, {
4144
"id" : "custom_property_object",
4245
"name" : "An object with custom properties",
4346
"properties" : {
4447
"constant_property" : true,
4548
"population_intervals" : [{
49+
"interval": "1970/1980",
50+
"number": 2209600
51+
}, {
52+
"interval": "1980/2090",
53+
"number": 2889700
54+
}, {
4655
"interval" : "1990/2000",
47-
"number": 11881643
56+
"number": 3307600
4857
}, {
4958
"interval" : "2000/2010",
50-
"number" : 12281054
59+
"number" : 4326900
5160
}],
5261
"population_sampled" : {
5362
"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
5768
]
5869
}
5970
}
6071
}, {
61-
"id" : "pennsylvania",
62-
"name" : "Pennsylvania",
72+
"id" : "colorado",
73+
"name" : "Colorado",
6374
"polygon" : {
6475
"positions" : {
6576
"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
7581
]
7682
},
7783
"material" : {
@@ -89,35 +95,6 @@
8995
var viewer = new Cesium.Viewer('cesiumContainer');
9096
var dataSource = new Cesium.CzmlDataSource();
9197

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-
12198
function scaleProperty(property, scalingFactor) {
12299
// returns a property that scales another property by a constant factor.
123100
return new Cesium.CallbackProperty(function(time, result) {
@@ -127,6 +104,32 @@
127104
}, property.isConstant);
128105
}
129106

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+
130133
dataSource.load(czml);
131134
viewer.dataSources.add(dataSource);
132135
viewer.zoomTo(dataSource);//Sandcastle_End
Loading

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ Change Log
33

44
### 1.42 - 2018-02-01
55

6+
* Breaking changes
7+
*
68
* Added `ClippingPlaneCollection.isSupported` function for checking if rendering with clipping planes is supported.
9+
* Improved CZML Custom Properties sandcastle example [#6086](https://github.com/AnalyticalGraphicsInc/cesium/pull/6086)
710

811
### 1.41 - 2018-01-02
912

0 commit comments

Comments
 (0)