铯:选择实体并检索WMS的信息 [英] Cesium: picking entity and retrieving info of WMS

查看:204
本文介绍了铯:选择实体并检索WMS的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

基本上,我希望能够在用户左键单击的位置选择建筑物.建筑物的颜色应该改变(起作用).我想在用户单击的位置检索Web Map Service的信息.

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

但是,我的变量"info"保持未定义状态,而我希望它返回一个数组.

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

推荐答案

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

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

这篇关于铯:选择实体并检索WMS的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆