thank you , Gabby.
I change my demo, and not use private attribute. but strange questions also exist.
for example, I hide line first, when I want to change color and show , I need to click right button three times.
[test.json]
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "Id": 0 }, "geometry": { "type": "LineString", "coordinates": [ [ 114.86133705101572, 40.51725185876473 ], [ 115.27982758793854, 40.326149243638127 ], [ 115.74186049286489, 40.461614388538003 ], [ 115.96682939421648, 40.289863936968516 ], [ 116.20873143868053, 40.555956185878983 ] ] } },
{ "type": "Feature", "properties": { "Id": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 114.86859411234964, 40.166493894291847 ], [ 115.49512040751155, 39.965715197386679 ], [ 116.03940000755568, 39.982648340499161 ], [ 116.31274931780007, 40.043123851615178 ], [ 116.67560238449616, 40.21971234407394 ] ] } }
]
}
[code]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>map</title>
<script src="./js/Cesium/Cesium.js"></script>
</head>
<body>
<button type="button" class="btn btn-link" style="position:absolute;z-index:10;left:30px;top:10px;font-size:24px;" onclick="toggleall()">toggleall</button>
<button type="button" class="btn btn-link" style="position:absolute;z-index:10;left:150px;top:10px;font-size:24px;" onclick="showbyid(0)">showbyid</button>
<div id="mapcontainer" style="width: 400px;height: 300px;margin-top:80px;"></div>
<script type="text/javascript">
var viewer=null;
var entityList = {'line':[]};
window.onload = function(){
initMap('mapcontainer');
}
function initMap(divId) {
var me= this;
viewer = new Cesium.Viewer(divId, {
baseLayerPicker : false,
animation : false,
fullscreenButton : false,
geocoder : false,
homeButton : false,
infoBox : false,
sceneModePicker : false,
selectionIndicator : false,
timeline : false,
navigationHelpButton : false,
navigationInstructionsInitiallyVisible : false,
sceneMode : Cesium.SceneMode.SCENE3D,
skyBox : false,
skyAtmosphere : false,
imageryProvider : null
});
viewer._cesiumWidget.creditContainer.style.display = 'none';
viewer.camera.setView( {
destination : Cesium.Cartesian3.fromDegrees(116.0706,38.6695,121321),
orientation: {
heading : Cesium.Math.toRadians(-0),
pitch : Cesium.Math.toRadians(-40),
roll : 0.0
}
} );
viewer.cesiumWidget.canvas.width = 400;
viewer.cesiumWidget.canvas.height = 300;
viewer.cesiumWidget.resize();
viewer.scene.backgroundColor = Cesium.Color.TRANSPARENT;
viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT;
viewer.scene.fxaa = false;
var source1 = new Cesium.GeoJsonDataSource('test');
source1.show = false;
source1.load('./test.json').then(function() {
var me = window;
var p = source1.entities.values;
me.entityList['line'] = p;
for ( var i = 0; i < p.length; i++) {
p[i]._show = true;
/*p[i].polyline.material = new Cesium.PolylineOutlineMaterialProperty({
color : Cesium.Color.fromBytes(11,209,252),
outlineWidth : 0
});*/
p[i].polyline.material = Cesium.Color.fromBytes(11,209,252);
viewer.entities.add(p[i]);
}
});
}
function toggleall(){
var me = window;
var entities = me.entityList['line'];
for(var i in entities){
//entities[i].polyline.material = new Cesium.PolylineOutlineMaterialProperty({color : Cesium.Color.fromBytes(11,209,252),outlineWidth : 0});
entities[i].polyline.material = Cesium.Color.fromBytes(11,209,252);
entities[i].show = !entities[i].show;
}
}
function showbyid(id){
var me = window;
var entities = me.entityList['line'];
for(var i in entities){
if(entities[i].properties['Id']==id){
entities[i].polyline.material = Cesium.Color.fromBytes(255,0,0);
//entities[i].polyline.material = new Cesium.PolylineOutlineMaterialProperty({color : Cesium.Color.fromBytes(255,0,0),outlineWidth : 0});
entities[i].show = true;
}
}
}
</script>
</body>
</html>
在 2017年8月26日星期六 UTC+8上午2:23:22,Gabby Getz写道: