【问题标题】:How to target specific point in Cesium pointprimitivecollection?如何定位铯点原始集合中的特定点?
【发布时间】:2017-06-05 16:46:34
【问题描述】:

我正在研究如何显示/隐藏点,以便过滤我在 Cesium 地球上的 PointPrimitiveCollection 中显示的数据。我知道您可以按索引号定位,但我想知道是否有办法将某种元数据添加到点,以便我可以根据这些值定位它们?

【问题讨论】:

    标签: javascript cesium


    【解决方案1】:

    您可以在创建点后添加属性(此行:points.add({ position : Cesium.Cartesian3.fromDegrees(longitude, latitude), color : color }).customId = [longitude, latitude];)。
    这是一个有效的代码:

    var viewer = new Cesium.Viewer('cesiumContainer');
    var points = viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection());
    
    for (var longitude = -180; longitude < 180; longitude++) {
        var color = Cesium.Color.PINK;
        if ((longitude % 2) === 0) {
            color = Cesium.Color.CYAN;
        }
    
        for (var latitude = -90; latitude < 90; latitude++) {
            points.add({
                position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
                color : color
            }).customId = [longitude, latitude];
        }
    }
    
    var red = false;
    setInterval(function() {
      var myPoints = points._pointPrimitives.filter(function(point){return point.customId[1] > -20 && point.customId[1] < 20;});
      red = !red;
      myPoints.forEach(function(point) {
        point.color = red ? Cesium.Color.GREEN : Cesium.Color.RED;
      })
    }, 2000);
    

    此代码在纬度 -20 和 20 之间切换点的颜色。您可以设置任何您想要的自定义属性并使用它(注意 - 此代码在任何方面都不是最佳的,仅用于演示)。 工作示例: http://plnkr.co/edit/DxWMwfdr4L5pfHRlVmlX?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-28
      • 2022-06-14
      • 2012-12-06
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多