美文网首页开源
Cesium Cesium3DTileset鼠标pickFeat

Cesium Cesium3DTileset鼠标pickFeat

作者: 宿州刘德华 | 来源:发表于2020-03-12 09:10 被阅读0次
    
    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
        }
    }
    
    
    
    

    相关文章

      网友评论

        本文标题:Cesium Cesium3DTileset鼠标pickFeat

        本文链接:https://www.haomeiwen.com/subject/gdnejhtx.html