Cesium: picking entity and retrieving info of WMS

不问归期 提交于 2020-05-29 07:19:20

问题


I have developed a 3D viewer of buildings. What I'm trying to add now is the selection of the content of a WMS (Web Map Service) below the building entities.

Basically, I want to be able to select the building at the position were the user left clicks. The colour of the building should change (which works). And I want to retrieve the information of the Web Map Service at the position were the user clicked.

This is what I have coded so far:

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);

However, my variable "info" stays undefined, whereas I expect it to return an array.


回答1:


For WMS you need to use the wms GetFeatureInfo capability:

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);
        }
    });
}


来源:https://stackoverflow.com/questions/34220203/cesium-picking-entity-and-retrieving-info-of-wms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!