Cesium中添加entitie模型,实现贴地。

1.Cesium中添加entitie模型,实现贴地。

2. 添加模型

const createModel = (url) => {
	const entity = viewer.entities.add({
		name: '这是一个模型',
		position: Cesium.Cartesian3.fromDegrees({ -123.0744619, 44.0503706, 100 }),
		model: {
			uri: url,
			minimumPixelSize: 128,
			maximumScale: 2000,
			heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
		}
	})
};

这里的url(模型的链接),我是用node.js。express框架实现的静态资源
node.js

const express = require('express')
const app = express()
const port = 5555

app.get('/', (req, res) => {
    res.send('Hello World!')
})
app.use((req, res, next) => {
    //设置请求头
    res.set({
        'Access-Control-Allow-Credentials': true,
        'Access-Control-Max-Age': 1728000,
        'Access-Control-Allow-Origin': req.headers.origin || '*',
        'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
        'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
        'Content-Type': 'application/json; charset=utf-8'
    })
    req.method === 'OPTIONS' ? res.status(204).end() : next()
})

app.use(express.static('./static'))
app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

Cesium中添加entitie模型,实现贴地。_第1张图片
2.实现贴地

heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
const entity = viewer.entities.add({
		name: '这是一个模型',
		position: Cesium.Cartesian3.fromDegrees({ -123.0744619, 44.0503706, 100 }),
		model: {
			uri: url,
			minimumPixelSize: 128,
			maximumScale: 2000,
			heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
		}
	})
viewer.trackedEntity = entity;


完整代码




你可能感兴趣的:(vue,javascript)