Created
October 30, 2015 18:57
-
-
Save shunter/0fb273feed2ed7b507fe to your computer and use it in GitHub Desktop.
Reading Custom CZML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var viewer = new Cesium.Viewer('cesiumContainer'); | |
viewer.clock.startTime = Cesium.JulianDate.fromIso8601('2015-10-30T12:00:00Z'); | |
viewer.clock.stopTime = Cesium.JulianDate.fromIso8601('2015-10-30T23:00:00Z'); | |
viewer.clock.currentTime = viewer.clock.startTime; | |
viewer.timeline.zoomTo(viewer.clock.startTime, viewer.clock.stopTime); | |
var czml = [ | |
{ | |
"id":"document", | |
"version":"1.0" | |
}, | |
{ | |
"id":"1", | |
"name":"Name", | |
"position":{ | |
"cartographicDegrees":[ | |
-75.5966,40.0386,0 | |
] | |
}, | |
"label":{ | |
"text":"Exton" | |
}, | |
"stringProperty":"Some Value", | |
"doubleProperty":{ | |
"epoch":"2015-10-30T12:00:00Z", | |
"number":[ | |
0,1, | |
39600,100 | |
] | |
} | |
} | |
]; | |
function processCustomProperties(entity, packet, dynamicObjectCollection, sourceUri) { | |
var interval; | |
var intervalString; | |
var stringPropertyData = packet.stringProperty; | |
if (Cesium.defined(stringPropertyData)) { | |
intervalString = stringPropertyData.interval; | |
if (Cesium.defined(intervalString)) { | |
interval = Cesium.TimeInterval.fromIso8601({ | |
iso8601 : intervalString | |
}); | |
} | |
var stringProperty = entity.stringProperty; | |
if (!Cesium.defined(stringProperty)) { | |
entity.addProperty('stringProperty'); | |
} | |
Cesium.CzmlDataSource.processPacketData(String, entity, 'stringProperty', stringPropertyData, interval, sourceUri); | |
} | |
var doublePropertyData = packet.doubleProperty; | |
if (Cesium.defined(doublePropertyData)) { | |
intervalString = doublePropertyData.interval; | |
if (Cesium.defined(intervalString)) { | |
interval = Cesium.TimeInterval.fromIso8601({ | |
iso8601 : intervalString | |
}); | |
} | |
var doubleProperty = entity.doubleProperty; | |
if (!Cesium.defined(doubleProperty)) { | |
entity.addProperty('doubleProperty'); | |
} | |
Cesium.CzmlDataSource.processPacketData(Number, entity, 'doubleProperty', doublePropertyData, interval, sourceUri); | |
} | |
} | |
Cesium.CzmlDataSource.updaters.push(processCustomProperties); | |
var czmlDataSource = new Cesium.CzmlDataSource(); | |
czmlDataSource.load(czml); | |
viewer.dataSources.add(czmlDataSource); | |
var entity = czmlDataSource.entities.getById('1'); | |
var lastDoublePropertyValue; | |
viewer.clock.onTick.addEventListener(function(clock) { | |
var doublePropertyValue = entity.doubleProperty.getValue(clock.currentTime); | |
if (lastDoublePropertyValue !== doublePropertyValue) { | |
console.log(doublePropertyValue); | |
lastDoublePropertyValue = doublePropertyValue; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment