javascript - 为 `name` 添加 `description` 和 `Cesium PolylineCollection` 框

标签 javascript opengl opengl-3 cesiumjs

铯沙堡页面上@ https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Polyline.html&label=Geometries

enter image description here

你可以看到,当我点击紫色线时,我得到一个框(图像的右上角)指示 Cesium [Polyline 的 name ][2] 作为 “高度上的紫色直箭头”。如何为 [PolylineCollection][2] 添加相同的 name box(下面代码中的第 5 行)?

这是代码

var viewer = new Cesium.Viewer('cesiumContainer');



var lineCollection = new Cesium.PolylineCollection(); // line no 5
lineCollection.add({
        name : "Hi",
        description : "Hi description",
        positions : Cesium.Cartesian3.fromDegreesArrayHeights([-75, 53, 500000,
                                                               -125, 53, 500000]),
        width : 10,
        followSurface : false
    });
viewer.scene.primitives.add(lineCollection);



var purpleArrow = viewer.entities.add({
    name : 'Purple straight arrow at height',
    polyline : {
        positions : Cesium.Cartesian3.fromDegreesArrayHeights([-75, 43, 500000,
                                                               -125, 43, 500000]),
        width : 10,
        followSurface : false,
        material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.PURPLE)
    }
});


viewer.zoomTo(viewer.entities);

最佳答案

名称和描述是 Cesium 中更高级别“实体”API 的一部分。在 PolylineCollection 所在的图形基元级别,没有这样的东西。

您需要使用较低级别的 API 吗?通常,想要绿色选择指示器、信息框、名称和描述等高级功能的用户应该坚持使用实体,而不是基元。

就是说,有一种方法可以检测图元何时被鼠标“选中”,并查找一些名称和信息,并命令信息框手动更新。不过,所有这些逻辑都内置于实体层中,因此在您自己的应用中重新实现它之前您应该三思。

关于javascript - 为 `name` 添加 `description` 和 `Cesium PolylineCollection` 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53943673/

相关文章:

c++ - 使用 GL_TEXTURE_2D_ARRAY 作为绘制目标

opengl - 纹理数组访问不起作用 Opengl 3.3、GLSL 330

javascript - 通过 CSS 属性选择 jQuery

javascript - 如何让输入的数字中的数字增加数百

javascript - JWplayer控制栏添加按钮来控制javascript

python - 嵌套循环显然不在 PyOpenGL 中循环

c++ - 函数名称表示什么以及更多

javascript - 准确捕获 iframe 上的点击

opengl - glReadPixels 获得的深度缓冲区始终为 1

c++ - OpenGL 3.+ 中的阵列纹理与 mipmap