viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(click) {
let pickedFeature = viewer.scene.pick(click.position);
if (pickedFeature instanceof Cesium.Cesium3DTileFeature) {
if (lastSelectedFeature) {
if (pickedFeature !== lastSelectedFeature) {
lastSelectedFeature.color = new Cesium.Color(1, 1, 1, 1);
}
}
console.log(getFeaturegetPropertyNamesAndValue(pickedFeature));
lastSelectedFeature = pickedFeature;
pickedFeature.color = new Cesium.Color(1, 0, 0, 0.7);
lastHoverFeature = null;
} else {
if (lastSelectedFeature) {
lastSelectedFeature.color = new Cesium.Color(1, 1, 1, 1);
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
var lastSelectedFeature = undefined;
var lastHoverFeature = null;
viewer.screenSpaceEventHandler.setInputAction(movement => {
let pickedFeature = viewer.scene.pick(movement.endPosition);
if (pickedFeature instanceof Cesium.Cesium3DTileFeature) {
if (pickedFeature === lastSelectedFeature || pickedFeature === lastHoverFeature) {
return
}
if (lastHoverFeature) {
if (pickedFeature !== lastHoverFeature) {
lastHoverFeature.color = new Cesium.Color(1, 1, 1, 1);
}
}
lastHoverFeature = pickedFeature;
pickedFeature.color = new Cesium.Color(0, 1, 0, 0.4);
} else {
if (lastHoverFeature) {
lastHoverFeature.color = new Cesium.Color(1, 1, 1, 1);
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
function getFeaturegetPropertyNamesAndValue(feaure) {
let PropertyNames = feaure.getPropertyNames();
let PropertyValues = [];
PropertyNames.forEach(function(item, index) {
let value = feaure.getProperty(item);
PropertyValues.push(value);
});
return {
names: PropertyNames,
values: PropertyValues
}
}
网友评论