Cesium-经纬度转换笛卡尔坐标系

CZML(百度查阅)字段里的position里坐标系仅支持cartesian(笛卡尔坐标系),一般的地理位置经纬度较为普遍。Cesium提供了转换接口,并且CZML里position字段支持填入常量(详情翻阅API)。

var position = Cesium.Cartesian3.fromDegrees(116.3912822800,39.9074647400);
var czml = [{
    "id" : "document",
    "name" : "Basic CZML billboard and label",
    "version" : "1.0"
}, {
    "id" : "some-unique-id",
    "name" : "AGI",
    "description" : "

Analytical Graphics, Inc. (AGI) founded Cesium.

"
, "billboard" : { "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVDhPrZDRDcMgDAU9GqN0lIzijw6SUbJJygUeNQgSqepJTyHG91LVVpwDdfxM3T9TSl1EXZvDwii471fivK73cBFFQNTT/d2KoGpfGOpSIkhUpgUMxq9DFEsWv4IXhlyCnhBFnZcFEEuYqbiUlNwWgMTdrZ3JbQFoEVG53rd8ztG9aPJMnBUQf/VFraBJeWnLS0RfjbKyLJA8FkT5seDYS1Qwyv8t0B/5C2ZmH2/eTGNNBgMmAAAAAElFTkSuQmCC", "scale" : 2.0 }, "label" : { "fillColor" : { "rgba" : [255, 255, 255, 255] }, "font" : "12pt Lucida Console", "horizontalOrigin" : "LEFT", "pixelOffset" : { "cartesian2" : [8, 0] }, "style" : "FILL", "text" : "AGI", "showBackground" : true, "backgroundColor" : { "rgba" : [112, 89, 57, 200] } }, "position" : { "cartesian":[ position.x, position.y, position.z ] } }]; var viewer = new Cesium.Viewer('cesiumContainer'); viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); console.log(position);

在Viewer中添加一个地面基站,天安门位置(谷歌地球:纬39.9074647400,经116.3912822800)标记一个基站。
经纬度查询:http://www.gpsspg.com/maps.htm
Cesium-经纬度转换笛卡尔坐标系_第1张图片
添加至label字段,基站右侧显示文字:

"text" : "AGI"

zoomTo更改视角:

var viewer = new Cesium.Viewer('cesiumContainer');
var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);
viewer.zoomTo(dataSourcePromise);

Cesium-经纬度转换笛卡尔坐标系_第2张图片

隐藏Cesium-ion的logo:

viewer._cesiumWidget._creditContainer.style.display = "none";

Cesium-经纬度转换笛卡尔坐标系_第3张图片

你可能感兴趣的:(技术)