cesium - How to customize czml datasource? -


i have czml data extracted via python. have buildings, geometry, height, building id, , intervals. each interval has value. after loading czml data cesium, i'd access attributes , customize color of buildings according value given. here sample of czml:

[{ "id": "document", "version": "1.0" }, { "id": 32, "availability": "2014-01-01t00:00:00z/2014-12-31t00:00:00z", "polygon": { "positions": { "cartographicdegrees": [54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0] }, "someproperty": [{ "interval": "2014-00-01t00:00:00z/2014-01-01t00:00:00z", "en_c_need": 0.7 }, { "interval": "2014-01-01t00:00:00z/2014-02-01t00:00:00z", "en_c_need": 1.0 }, { "interval": "2014-02-01t00:00:00z/2014-03-01t00:00:00z", "en_c_need": 2.6 }, { "interval": "2014-03-01t00:00:00z/2014-04-01t00:00:00z", "en_c_need": 12.1 }, { "interval": "2014-04-01t00:00:00z/2014-05-01t00:00:00z", "en_c_need": 30.2 }, { "interval": "2014-05-01t00:00:00z/2014-06-01t00:00:00z", "en_c_need": 37.8 }], "extrudedheight": 6.0 } }]

i have other geojson data customized, tried same method didn't work.

here i'm trying (this not work):

var test2 = cesium.czmldatasource.load ('data/czml/testing/example_8.czml'); test2.then(function (datasource) {     viewer.datasources.add(test2);     viewer.zoomto (test2); var entities = datasource.entities.values;       var colorhash = {};     var energy = [];     (var = 0; < entities.length; i++) {         var entity = entities[i];         energy = entity.someproperty.en_c_need;         var color = colorhash [energy];         if(!color ) {             if (energy < 5 ) {             color = cesium.color.darksalmon.withalpha (0.95);         } else if (energy < 10) {                 color = cesium.color.burlywood.withalpha (0.95);         } else if (energy < 20) {                 color = cesium.color.red.withalpha (0.95);         } else {                 color = cesium.color.pink.withalpha (0.95);          };         colorhash[energy] = color;         };         entity.polygon.fill = true;         entity.polygon.material = color;         entity.polygon.outline = false;          }; 

});

to start solution - here's working plnkr: https://plnkr.co/edit/p1cg4dnjytk9r9xrlzxk?p=preview

i've changed several things in code: 1) viewer.datasources.add(test2); should outside promise (it doesn't matter, it's cleaner code - using promise inside promise feels strange). 2) according czml properties spec, need place properties in right location in czml. should not inside polygon, in "root":

var czml = [{"id": "document", "version": "1.0"}, {     "id": 32, "availability": "2014-01-01t00:00:00z/2014-12-31t00:00:00z", "properties": {     "someproperty": [         {"interval": "2014-00-01t00:00:00z/2014-01-01t00:00:00z", "en_c_need": 0.7},          {"interval": "2014-01-01t00:00:00z/2014-02-01t00:00:00z", "en_c_need": 1.0},         {"interval": "2014-02-01t00:00:00z/2014-03-01t00:00:00z", "en_c_need": 2.6},         {"interval": "2014-03-01t00:00:00z/2014-04-01t00:00:00z", "en_c_need": 12.1},         {"interval": "2014-04-01t00:00:00z/2014-05-01t00:00:00z", "en_c_need": 30.2},         {"interval": "2014-05-01t00:00:00z/2014-06-01t00:00:00z", "en_c_need": 37.8}         ], },     "polygon": {         "positions": {             "cartographicdegrees":                 [54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0]         },         "extrudedheight": 6.0     } }]; 

then can ask properties according interval (energy = entity.properties.getvalue(viewer.clock.currenttime).someproperty.en_c_need;) , energy @ viewer's current time.

update after commentchatting: code not meant change dynamically. need set value either callbackproperty in example: plnkr.co/edit/lm290uaqewevfiogxbdp?p=preview or using timeintervalcollection


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -