selecting info of WMS below an entity

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, the variable "info" stays undefined, while I expect an array...

Hi,

I think you want to use the imagery provider’s pickFeatures method, not getTileCredits:

https://cesiumjs.org/Cesium/Build/Documentation/WebMapServiceImageryProvider.html?classFilter=webmap#pickFeatures

However, if you use that directly, you need to figure out which tile the user clicked within, which be tricky. ImageryLayerCollection.pickImageryLayerFeatures will do this automatically:

It’s a little tricky because you need to figure out which imagery tile the user clicked within. You can avoid the problem by calling ImageryLayerCollection.

To determine the tile x, y, level coordinates, using currentLayer.imageryProvider.tilingScheme.

Also, you should have accessing any property in Cesium whose name starts with an underscore. Those are private implementation details that can change from release to release.

Oops, clumsy fingers somehow found the send button before I had finished typing! Let’s try again…

I think you want to use the imagery provider’s pickFeatures method, not getTileCredits:

https://cesiumjs.org/Cesium/Build/Documentation/WebMapServiceImageryProvider.html?classFilter=webmap#pickFeatures

However, if you use that directly, you need to figure out which tile the user clicked within, which be tricky. ImageryLayerCollection.pickImageryLayerFeatures will do this automatically:

https://cesiumjs.org/Cesium/Build/Documentation/ImageryLayerCollection.html?classFilter=imageryLayer#pickImageryLayerFeatures

Since that will pick against all layers, you may need to filter out results from other layers that you don’t care about.

Also, you should have accessing any property in Cesium whose name starts with an underscore. Those are private implementation details that can change from release to release. In your example code, all of the underscore properties have a non-underscore version that you should use instead.

Kevin