Commit 4b9b2634 by jlc

update:相机缩放案例的添加

parent dc3bc06d
export function addFog() { let viewer;
export function addCameraZoom() {
const script = document.createElement('script'); const script = document.createElement('script');
script.src = 'https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Cesium.js'; script.src = 'https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Cesium.js';
script.onload = () => { script.onload = () => {
window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE' window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE'
const viewer = new window.Cesium.Viewer('cesiumContainer', { viewer = new window.Cesium.Viewer('cesiumContainer', {
infoBox: false, infoBox: false,
}); });
}; };
document.head.appendChild(script); document.head.appendChild(script);
...@@ -17,3 +17,35 @@ export function addFog() { ...@@ -17,3 +17,35 @@ export function addFog() {
link.href = 'https://cesium.com/downloads/cesiumjs/releases/1.119/Build/Cesium/Widgets/widgets.css'; link.href = 'https://cesium.com/downloads/cesiumjs/releases/1.119/Build/Cesium/Widgets/widgets.css';
document.head.appendChild(link); document.head.appendChild(link);
} }
// 获取视图中心点
function pickCenter() {
var ellipsoid = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(
viewer.canvas.clientWidth / 2,
viewer.canvas.clientHeight / 2));
var curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(ellipsoid);
var lon = curPosition.longitude * 180 / Math.PI;
var lat = curPosition.latitude * 180 / Math.PI;
return {
lon: lon,
lat: lat
};
}
export function zoomByBound(flag){
const center = pickCenter()
var height = viewer.camera.positionCartographic.height;
const camera = viewer.camera;
var boundingSph = new Cesium.BoundingSphere(Cesium.Cartesian3.fromDegrees(center.lon, center.lat, 1000), height);
var moveRate = 0;
if(flag){
moveRate = 0.5
}
else{
moveRate = 1.5
}
var zoomParams = {
duration: 0.8,
offset: new Cesium.HeadingPitchRange(camera.heading, camera.pitch, height * moveRate)
}
camera.flyToBoundingSphere(boundingSph,zoomParams);
}
<template> <template>
<div id="cesiumContainer" class="cesium-container"></div> <div id="cesiumContainer" class="cesium-container"></div>
<div class="btn-class">
<button @click="zoomByBound(1)">放大相机视角</button>
<button @click="zoomByBound(0)">缩小相机视角</button>
</div>
</template> </template>
<script setup> <script setup>
import { onMounted } from 'vue'; import { onMounted } from 'vue';
import { addCameraZoom } from './function'; import { addCameraZoom, zoomByBound } from './function';
onMounted(() => { onMounted(() => {
addCameraZoom() addCameraZoom()
}); });
...@@ -11,7 +15,12 @@ onMounted(() => { ...@@ -11,7 +15,12 @@ onMounted(() => {
<style> <style>
.cesium-container { .cesium-container {
width: 100%; width: 100%;
height: 100vh; height: 100vh;
}
.btn-class {
position: absolute;
top: 10px;
left: 10px;
} }
</style> </style>
\ No newline at end of file
...@@ -150,7 +150,7 @@ export const elementCameraMap = { ...@@ -150,7 +150,7 @@ export const elementCameraMap = {
}, },
相机缩放: { 相机缩放: {
title: '相机缩放', title: '相机缩放',
pngUrl: '/src/assets/Mapx.png' pngUrl: '/src/assets/CameraZoom.png'
} }
} }
......
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