4

我开发了一个建筑物的 3D 查看器。我现在要添加的是在建筑实体下方选择 WMS(Web 地图服务)的内容。

基本上,我希望能够在用户左键单击的位置选择建筑物。建筑物的颜色应该改变(有效)。我想在用户点击的位置检索 Web 地图服务的信息。

到目前为止,这是我编写的代码:

var pickColor = Cesium.Color.CYAN.withAlpha(0.7);
var selectedEntity = new Map();

handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = viewer.scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
        var entityId = pickedObject.id._id;
        var oldColor = buildingMap.get(entityId).polygon.material.color;
        buildingMap.get(entityId).polygon.material.color = pickColor;
        selectedEntity.set(entityId, oldColor);

        var currentLayer = viewer.scene.imageryLayers.get(1);
        if (typeof currentLayer !== 'undefined') {
            var info = currentLayer._imageryProvider._tileProvider.getTileCredits(click.position.x, click.position.y, 0);
        }
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

但是,我的变量“info”保持未定义,而我希望它返回一个数组。

4

1 回答 1

1

对于 WMS,您需要使用 wmsGetFeatureInfo功能:

var pickRay = viewer.camera.getPickRay(windowPosition);
var featuresPromise = viewer.imageryLayers.pickImageryLayerFeatures(pickRay, viewer.scene);
if (!Cesium.defined(featuresPromise)) {
    console.log('No features picked.');
} else {
    Cesium.when(featuresPromise, function(features) {
        // This function is called asynchronously when the list if picked features is available.
        console.log('Number of features: ' + features.length);
        if (features.length > 0) {
            console.log('First feature name: ' + features[0].name);
        }
    });
}
于 2019-06-18T08:47:57.843 回答