如何在Cesiumjs中为实体添加标签?

问题描述 投票:1回答:1

如何在铯中给实体(多边形)添加标签?我试过下面的代码,但标签没有显示。我不知道我哪里写错了。


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

var entity = viewer.entities.add({
  polygon : {
    hierarchy : Cesium.Cartesian3.fromDegreesArray([
                              -109.080842,45.002073,
                              -105.91517,45.002073,
                              -104.058488,44.996596,
                              -104.053011,43.002989,
                              -104.053011,41.003906,
                              -105.728954,40.998429,
                              -107.919731,41.003906,
                              -109.04798,40.998429,
                              -111.047063,40.998429,
                              -111.047063,42.000709,
                              -111.047063,44.476286,
                              -111.05254,45.002073]),
    height : 0,
    material : Cesium.Color.RED.withAlpha(0.5),
    outline : true,
    outlineColor : Cesium.Color.BLACK
  },
  label: {text: 'hello world'}
});

entity.label.show = true;
viewer.zoomTo(entity);

WX20200508-152835@2x.png

你可以在官网的演示代码中进行测试。https:/sandcastle.cesium.comindex.html?src=GeoJSON%20和%20TopoJSON.html&label=DataSources。

gis cesium
1个回答
0
投票

与多边形不同,标签取决于实体是否有一个 position. 标签显示在(或相对于)实体的位置。

试着在你的示例代码中加入这一行。

position: Cesium.Cartesian3.fromDegrees(-108, 43),

这里是 完整演示.

© www.soinside.com 2019 - 2024. All rights reserved.