2017-03-20 32 views
1

有没有任何方法可以获得铯采摘实体的颜色?铯获取挑选实体的颜色进行比较

基本上,我需要检查点击的实体的颜色,如果它的蓝色,将其改为红色,反之亦然。

有什么办法可以达到这个目的吗?提前致谢。

回答

1

是的,有一些注意事项:首先,铯实体本身没有颜色。它可以有一个点,并且点可以具有coloroutlineColor,它也可具有一个标签与自己的颜色(一个或多个)等

接着,铯性质都能够进行时间动态或不变。因此,当您“获得”实体属性(如点颜色)时,您通常应通过viewer.clock.currentTime以在特定时间获取该物业。如果您确定知道您获得的财产是ConstantProperty而不是SampledPropertyTimeIntervalCollectionProperty,则无关紧要。

对于下面的演示,我为所有颜色和属性隐式使用了ConstantProperty。我还压制了“SelectionIndicator”(当你点击一个实体时通常出现的绿色框),因为这种情况看起来很奇怪。

我正在使用selectedEntityChanged事件来指示点应该从蓝色变为红色还是回来。本月(2017年3月)发布的Cesium 1.31中新增了selectedEntityChanged事件。如果您的版本较旧且无法升级,则可以根据需要发布旧版本的解决方法。

var viewer = new Cesium.Viewer('cesiumContainer', { 
 
    // Turn off nav help and stuff we're not using. 
 
    navigationInstructionsInitiallyVisible: false, animation: false, timeline: false, 
 
    
 
    // Optionally, you can turn off the green selection box, like this: 
 
    selectionIndicator : false, 
 
    
 
    // These next 6 lines are just to avoid Stack Snippet error messages. 
 
    imageryProvider : Cesium.createTileMapServiceImageryProvider({ 
 
     url : Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII') 
 
    }), 
 
    baseLayerPicker : false, 
 
    geocoder : false, 
 
    infoBox : false 
 
}); 
 

 
var dots = [ 
 
    { lon: -75, lat: 40 }, 
 
    { lon: -95, lat: 40 }, 
 
    { lon: -115, lat: 40 }, 
 
    { lon: -75, lat: 30 }, 
 
    { lon: -95, lat: 30 }, 
 
    { lon: -115, lat: 30 }, 
 
    { lon: -85, lat: 20 }, 
 
    { lon: -105, lat: 20 } 
 
]; 
 

 
dots.forEach(function(dot) { 
 
    viewer.entities.add({ 
 
     position : Cesium.Cartesian3.fromDegrees(dot.lon, dot.lat), 
 
     point : { 
 
      pixelSize : 7, 
 
      color : Cesium.Color.STEELBLUE, 
 
      outlineColor : Cesium.Color.BLACK, 
 
      outlineWidth : 1.0 
 
     } 
 
    }); 
 
}); 
 

 
viewer.selectedEntityChanged.addEventListener(function(entity) { 
 
    // Check if an entity with a point color was selected. 
 
    if (Cesium.defined(entity) && 
 
     Cesium.defined(entity.point) && 
 
     Cesium.defined(entity.point.color)) { 
 
     
 
     // Get the current color 
 
     var color = entity.point.color.getValue(viewer.clock.currentTime); 
 
     
 
     // Test for blue 
 
     if (Cesium.Color.equals(color, Cesium.Color.STEELBLUE)) { 
 
      // Set to red 
 
      entity.point.color = Cesium.Color.RED; 
 
     } 
 

 
     // Test for red 
 
     else if (Cesium.Color.equals(color, Cesium.Color.RED)) { 
 
      // Set to red 
 
      entity.point.color = Cesium.Color.STEELBLUE; 
 
     } 
 
    } 
 
});
html, body, #cesiumContainer { 
 
    width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; 
 
    font-family: sans-serif; 
 
} 
 
#message { 
 
    position: absolute; 
 
    top: 4px; left: 5px; color: #edffff; 
 
}
<link href="http://cesiumjs.org/releases/1.31/Build/Cesium/Widgets/widgets.css" 
 
     rel="stylesheet"/> 
 
<script src="http://cesiumjs.org/releases/1.31/Build/Cesium/Cesium.js"> 
 
</script> 
 
<div id="cesiumContainer"></div> 
 
<div id="message">Single-click a dot to change its color.</div>