首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何自定义czml数据源?

如何自定义czml数据源?
EN

Stack Overflow用户
提问于 2017-08-15 07:50:53
回答 1查看 1.3K关注 0票数 1

我有一个通过python提取的CZML数据。我有建筑物,有它们的几何,高度,建筑ID和间隔。每个间隔都有一个值。在将czml数据加载到铯之后,我想访问属性,然后根据给定的值定制建筑物的颜色。下面是我的CZML示例:

[{ "id":“文档”,“版本”:"1.0“},{ "id":32,”可用性“:"2014-01-01T00:00:00Z/2014-12-31T00:00:00Z",”多边形“:{ "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.716161647729823、24.45182937395、0、54.716162035538772、24.4520196028966、0、54.716162360431897、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: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:00:00Z/2014-06-01T00:00:00Z”,"En_C_need":37.8 },"extrudedHeight":6.0 }]

我有其他的GeoJSON数据,我定制了,我尝试了同样的方法,但它没有工作。

下面是我要做的事情(这不起作用):

代码语言:javascript
复制
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 = [];
    for (var i = 0; i < 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;     
    };

});

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-21 13:04:05

首先是解决方案--以下是正在工作的plnkr:https://plnkr.co/edit/P1Cg4DNJYtK9r9XrLzxK?p=preview

我在您的代码中改变了几件事: 1) viewer.dataSources.add(test2);应该超出您的承诺(这并不重要,但它是更干净的代码--使用承诺中的承诺感觉很奇怪)。2)根据CZML属性规范,您需要将属性放在CZML的正确位置。它不应该在多边形内,而应该在“根”中:

代码语言:javascript
复制
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
    }
}];

然后,您可以根据间隔(Energy = entity.properties.getValue(viewer.clock.currentTime).someProperty.En_C_need;)要求属性,并在当前时间获得能量。

注释后的更新():您的代码不打算动态更改。您需要通过callbackProperty设置值,如本例所示:plnkr.co/编辑/lm290uaQewEvfIOgXbDP?P=预览或使用timeIntervalCollection

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45688581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档