Commit 8927f7fd by lyc

1

parent 0551d450
...@@ -13,9 +13,12 @@ import baozha from './components/baozha.vue' ...@@ -13,9 +13,12 @@ import baozha from './components/baozha.vue'
import kedupan from './components/kedupan.vue' import kedupan from './components/kedupan.vue'
import raotaiyang from './components/raotaiyng.vue' import raotaiyang from './components/raotaiyng.vue'
import qq from './components/qq.vue' import qq from './components/qq.vue'
import setl from './components/setl.vue'
import xyz from './components/xyz.vue'
export default { export default {
name: 'app', name: 'app',
components: { boom, demo ,draw,moon,fire,selt,sun,camera,dail,baozha,kedupan,raotaiyang,qq} components: { boom, demo ,draw,moon,fire,selt,sun,camera,dail,baozha,kedupan,raotaiyang,qq,setl,xyz}
} }
</script> </script>
...@@ -31,8 +34,10 @@ export default { ...@@ -31,8 +34,10 @@ export default {
<!-- <draw/> --> <!-- <draw/> -->
<!-- <camera/> --> <!-- <camera/> -->
<!-- <dail/> --> <!-- <dail/> -->
<raotaiyang/> <!-- <raotaiyang/> -->
<!-- <qq/> --> <!-- <qq/> -->
<xyz/>
<!-- <setl/> -->
</template> </template>
<style scoped> <style scoped>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<script setup> <script setup>
import { onMounted } from 'vue' import { onMounted } from 'vue'
import * as Cesium from 'cesium' import * as Cesium from 'cesium'
import Cesium3DTile from 'cesium/Source/Scene/Cesium3DTile';
onMounted(() => { onMounted(() => {
...@@ -16,15 +17,32 @@ onMounted(() => { ...@@ -16,15 +17,32 @@ onMounted(() => {
let handler; let handler;
// 添加轨迹线实体 // 添加轨迹线实体
const polyline = viewer.entities.add({ viewer.entities.add({
id: 'polyline', id: 'polyline',
polyline: { position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883,300000),
positions: Cesium.Cartesian3.fromDegreesArray([-100, 20, -100, 30,-90,25]), ellipsoid: {
width: 20, radii: new Cesium.Cartesian3(200000.0, 200000.0, 200000.0),
material: Cesium.Color.YELLOW, }
},
}); });
const polyline = viewer.entities.add({
id: 'line',
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([-70, 30, -60, 20,-50,30]),
width:2,
material:Cesium.Color.YELLOW
}
})
viewer.entities.add({
id: "point",
position: Cesium.Cartesian3.fromDegrees(-85, 30, 100),
point: {
pixelSize: 10,
color: Cesium.Color.RED
}
})
// 添加用于显示标签的实体 // 添加用于显示标签的实体
const entity = viewer.entities.add({ const entity = viewer.entities.add({
label: { label: {
...@@ -34,79 +52,64 @@ onMounted(() => { ...@@ -34,79 +52,64 @@ onMounted(() => {
horizontalOrigin: Cesium.HorizontalOrigin.LEFT, horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
verticalOrigin: Cesium.VerticalOrigin.TOP, verticalOrigin: Cesium.VerticalOrigin.TOP,
pixelOffset: new Cesium.Cartesian2(15, 0), pixelOffset: new Cesium.Cartesian2(15, 0),
eyeOffset: new Cesium.Cartesian3(0, 0, -10000)
}, },
}); });
// 设置鼠标事件处理器 // 设置鼠标事件处理器
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
// 处理鼠标移动事件
handler.setInputAction(function (movement) { handler.setInputAction(function (movement) {
const pickedObject = viewer.scene.pick(movement.endPosition);
if (Cesium.defined(pickedObject) && pickedObject.id && pickedObject.id.id === 'polyline') {
const cartesian = viewer.camera.pickEllipsoid( const cartesian = viewer.camera.pickEllipsoid(
movement.endPosition, movement.endPosition,
scene.globe.ellipsoid scene.globe.ellipsoid
); );
if (cartesian) {
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
const heightString = cartographic.height.toFixed(2);
const xString = cartesian.x.toFixed(2);
const yString = cartesian.y.toFixed(2);
const zString = cartesian.z.toFixed(2);
entity.position = cartesian;
entity.label.show = true;
entity.label.text =
`Lon: ${` ${longitudeString}`.slice(-7)}\u00B0` +
`\nLat: ${` ${latitudeString}`.slice(-7)}\u00B0` +
`\nHeight: ${heightString} m` +
`\n\nECEF:` +
`\nX: ${xString} m` +
`\nY: ${yString} m` +
`\nZ: ${zString} m`;
}
} else {
entity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
handler.setInputAction(function (movement) {
const pickedObject = viewer.scene.pick(movement.position);
if (Cesium.defined(pickedObject) && pickedObject.id && pickedObject.id.id === 'polyline') {
const cartesian = viewer.camera.pickEllipsoid(
movement.position,
scene.globe.ellipsoid
);
if (cartesian) { if (cartesian) {
// 从笛卡尔坐标转换为地理坐标
const cartographic = Cesium.Cartographic.fromCartesian(cartesian); const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2); const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2); const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
const heightString = cartographic.height.toFixed(2); const heightString = cartographic.height.toFixed(2);
const xString = cartesian.x.toFixed(2); // 将笛卡尔坐标转换为字符串
const yString = cartesian.y.toFixed(2); const cartesianString = `X: ${cartesian.x.toFixed(2)}, Y: ${cartesian.y.toFixed(2)}, Z: ${cartesian.z.toFixed(2)}`;
const zString = cartesian.z.toFixed(2);
entity.position = cartesian; entity.position = cartesian;
entity.label.show = true; entity.label.show = true;
entity.label.text = entity.label.text =
`Lon: ${` ${longitudeString}`.slice(-7)}\u00B0` + `X: ${cartesian.x.toFixed(2)}` +
`\nLat: ${` ${latitudeString}`.slice(-7)}\u00B0` + `\nY: ${cartesian.y.toFixed(2)}` +
`\nHeight: ${heightString} m` + `\nZ: ${cartesian.z.toFixed(2)}`;
`\n\nECEF:` +
`\nX: ${xString} m` +
`\nY: ${yString} m` +
`\nZ: ${zString} m`;
}
} else { } else {
entity.label.show = false; entity.label.show = false;
} }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
// handler.setInputAction(function (movement) {
// const cartesian = viewer.camera.pickEllipsoid(
// movement.endPosition,
// scene.globe.ellipsoid
// );
// if (cartesian) {
// const pickedEntity = viewer.scene.pick(movement.endPosition);
// if (Cesium.defined(pickedEntity) && pickedEntity.id) {
// const entityPosition = Cesium.Cartographic.fromCartesian(pickedEntity.id.position.getValue(viewer.clock.currentTime));
// const longitudeString = Cesium.Math.toDegrees(entityPosition.longitude).toFixed(2);
// const latitudeString = Cesium.Math.toDegrees(entityPosition.latitude).toFixed(2);
// const heightString = entityPosition.height.toFixed(2);
// entity.position = cartesian;
// entity.label.show = true;
// entity.label.text =
// `Lon: ${longitudeString}\u00B0` +
// `\nLat: ${latitudeString}\u00B0`;
// } else {
// entity.label.show = false;
// }
// } else {
// entity.label.show = false;
// }
// }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
......
<template>
<div id="cesiumContainer" class="all"></div>
</template>
<script setup>
import { onMounted } from 'vue'
import * as Cesium from 'cesium'
onMounted(() => {
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyYTI3MDQxMS1hYzgxLTRlYTQtODExZS00YzdmYjM0YTg3OTAiLCJpZCI6MjI0NzQzLCJpYXQiOjE3MTkzOTcxMDF9._VD-W1rEy7jSUtPmcVytEYbZIZ00_IeHCZm59Kua5aE'
const viewer = new Cesium.Viewer("cesiumContainer", {
})
const scene = viewer.scene;
let handler;
// 添加用于显示标签的实体
const entity = viewer.entities.add({
label: {
show: false,
showBackground: true,
font: "16px monospace",
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
verticalOrigin: Cesium.VerticalOrigin.TOP,
pixelOffset: new Cesium.Cartesian2(15, 0),
eyeOffset: new Cesium.Cartesian3(0, 0, -10000)
},
});
// 设置鼠标事件处理器
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
const cartesian = viewer.camera.pickEllipsoid(
movement.endPosition,
scene.globe.ellipsoid
);
if (cartesian) {
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
entity.position = cartesian;
entity.label.show = true;
entity.label.text =`Lon: ${` ${longitudeString}`.slice(-7)}\u00B0` +`\nLat: ${` ${latitudeString}`.slice(-7)}\u00B0`;
} else {
entity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
})
</script>
<style>
.all {
display: block;
position: absolute;
top: 0;
left: 0;
border: none;
width: 100%;
height: 100%
}
</style>
<template>
<div id="cesiumContainer" class="all"></div>
</template>
<script setup>
import { onMounted } from 'vue'
import * as Cesium from 'cesium'
onMounted(() => {
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyYTI3MDQxMS1hYzgxLTRlYTQtODExZS00YzdmYjM0YTg3OTAiLCJpZCI6MjI0NzQzLCJpYXQiOjE3MTkzOTcxMDF9._VD-W1rEy7jSUtPmcVytEYbZIZ00_IeHCZm59Kua5aE'
const viewer = new Cesium.Viewer("cesiumContainer", {
})
const scene = viewer.scene;
let handler;
// 添加用于显示标签的实体
const entity = viewer.entities.add({
label: {
show: false,
showBackground: true,
font: "16px monospace",
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
verticalOrigin: Cesium.VerticalOrigin.TOP,
pixelOffset: new Cesium.Cartesian2(15, 0),
eyeOffset: new Cesium.Cartesian3(0, 0, -10000)
},
});
// 设置鼠标事件处理器
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
const cartesian = viewer.camera.pickEllipsoid(movement.endPosition,scene.globe.ellipsoid);
if (cartesian) {
entity.position = cartesian;
entity.label.show = true;
entity.label.text =`X: ${cartesian.x.toFixed(2)}` +`\nY: ${cartesian.y.toFixed(2)}` +`\nZ: ${cartesian.z.toFixed(2)}`;
} else {
entity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
})
</script>
<style>
.all {
display: block;
position: absolute;
top: 0;
left: 0;
border: none;
width: 100%;
height: 100%
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment