var viewer = new Cesium.Viewer('cesiumContainer', {
animation: false, //是否显示动画控件
homeButton: true, //是否显示home键
//geocoder:false, //是否显示地名查找控件 如果设置为true,则无法查询
baseLayerPicker: false, //是否显示图层选择控件
timeline: false, //是否显示时间线控件
fullscreenButton: true, //是否全屏显示
scene3DOnly: true, //如果设置为true,则所有几何图形以3D模式绘制以节约GPU资源
infoBox: true, //是否显示点击要素之后显示的信息
sceneModePicker: false, //是否显示投影方式控件 三维/二维
navigationInstructionsInitiallyVisible: false,
navigationHelpButton: false, //是否显示帮助信息控件
selectionIndicator: false, //是否显示指示器组件
// //加载谷歌卫星影像
// imageryProvider:new Cesium.ArcGisMapServerImageryProvider({
// url: 'https://server.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer'
// }),
// terrainProvider : new Cesium.CesiumTerrainProvider({url: 'https://www.supermapol.com/iserver/services/3D-stk_terrain/rest/realspace/datas/info/data/path/'}),
// imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
// url: "http://t0.tianditu.gov.cn/img_w/wmts?tk=7b435c61bff7f77eb49206e10d6397bd",
// layer: 'img',
// style: 'default',
// tileMatrixSetID: 'w',
// format: 'tiles',
// maximumLevel: 18
// }),
// terrainProvider : Cesium.createWorldTerrain({
// requestVertexNormals: true
// })
});
scene = viewer.scene;
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (evt) {
var scene = viewer.scene;
if (scene.mode !== Cesium.SceneMode.MORPHING) {
var pickedObject = scene.pick(evt.position);
if (scene.pickPositionSupported && Cesium.defined(pickedObject)) {
var cartesian = viewer.scene.pickPosition(evt.position);
if (Cesium.defined(cartesian)) {
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
var lng = Cesium.Math.toDegrees(cartographic.longitude);
var lat = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;//模型高度
mapPosition = { x: lng, y: lat, z: height };
console.log(mapPosition);
}
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);