cesium中divPoint展示数据
在用点击面获取位置信息的时候,会弹出一个divPoint框,用来展示这个面的属性信息;或者位置信息。
代码如下:
var handlerClick = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
var divPoint = null;
handlerClick.setInputAction(function (movement) {
var position = viewer.scene.pickPosition(movement.position);
if (position) {
var cartographic = Cesium.Cartographic.fromCartesian(position);
var BSM = showDivPositionOld.BSM._value;
var JSMJ = showDivPositionOld.JSMJ._value;
var YSDM = showDivPositionOld.YSDM._value;
var html = `<div class="label">
<table>
<tr>
<th>属性名</th>
<th>属性值</th>
</tr>
<tr>
<td>BSM</td>
<td>{BSM}</td>
</tr>
<tr>
<td>JSMJ</td>
<td>{JSMJ}</td>
</tr>
<tr>
<td>YSDM</td>
<td>{YSDM}</td>
</tr>
</table>
<span class="triangle"></span>
</div>`;
html = html.replace('{BSM}', BSM)
.replace('{JSMJ}', JSMJ)
.replace('{YSDM}', YSDM); if (divPoint) {
divPoint.destroy();
divPoint = null;
} divPoint = new Cesium.DivPoint(viewer, {
html: html,
position: position,
anchor: [0, -15],
noEvent: true
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
其中我获取的是面的属性信息。如果你想获取它的经纬度信息的话,方法是一样的。
divPoint框就是上面模板字符串里面的html;
divPoint = new Cesium.DivPoint(viewer, {
html: html,//模板字符串中的html
position: position,//你获取到的位置
anchor: [0, -15], 偏移角度
noEvent: true 是否开启
})
相关学习群:854184700