cesium-切分地图

在cesium中只看想看到的部分地图,其他的隐藏。

做法如下

复制代码
import {ArrowRight} from '@element-plus/icons-vue'
import {onMounted, ref, watch} from "vue";
import * as Cesium from "cesium";
import InitCesium from "../js/InitCesiumHide.js";

初始化

复制代码
let viewer = null;
let points = ref({
	position: null
});
let checked3 = ref(true);
let checked4 = ref(true);
// 添加矩形以显示边界
const rectangles = [];
// 热带和南回归线 需要展示的区域
let coffeeBeltRectangle = Cesium.Rectangle.fromDegrees(-180.0, -23.43687, 180.0, 23.43687);

onMounted(() => {
	let initCesium = new InitCesium('cesiumContainer');
	viewer = initCesium.initViewer({});

	viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
	viewer.scene.skyAtmosphere.show = true;

	for (let i = 0; i < 10; i++) {
		rectangles.push(viewer.entities.add({
			rectangle: {
				coordinates: coffeeBeltRectangle,
				material: Cesium.Color.WHITE.withAlpha(0.0),
				height: i * 5000.0,
				outline: true,
				outlineWidth: 4.0,
				outlineColor: Cesium.Color.WHITE
			}
		}));
	}
})

监听两个值的变化,一个是是否要隐藏一个是是否显示边框

复制代码
watch([checked3, checked4], (newVal, oldVal) => {
	if (newVal[0]) {
		viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
	} else {
		viewer.scene.globe.cartographicLimitRectangle = Cesium.Rectangle.MAX_VALUE;
	}
	const rectanglesLength = rectangles.length;
	for (let i = 0; i < rectanglesLength; i++) {
		const rectangleEntity = rectangles[i];
		rectangleEntity.show = newVal[1];
	}
})

所有代码

复制代码
<template>
	<div id="cesiumContainer" style="height: 100vh;"></div>
	<div id="toolbar" style="position: fixed;top:20px;left:220px;">
		<el-breadcrumb :separator-icon="ArrowRight">
			<el-breadcrumb-item>场景</el-breadcrumb-item>
			<el-breadcrumb-item>切分地图</el-breadcrumb-item>
		</el-breadcrumb>
		<el-checkbox v-model="checked3" label="限制启用"/>
		<el-checkbox v-model="checked4" label="显示边界"/>
	</div>
</template>
<script setup>
import {ArrowRight} from '@element-plus/icons-vue'
import {onMounted, ref, watch} from "vue";
import * as Cesium from "cesium";
import InitCesium from "../js/InitCesiumHide.js";

let viewer = null;
let points = ref({
	position: null
});
let checked3 = ref(true);
let checked4 = ref(true);
// 添加矩形以显示边界
const rectangles = [];
// 热带和南回归线
let coffeeBeltRectangle = Cesium.Rectangle.fromDegrees(-180.0, -23.43687, 180.0, 23.43687);

onMounted(() => {
	let initCesium = new InitCesium('cesiumContainer');
	viewer = initCesium.initViewer({});
	// flyToRight2();
	viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
	viewer.scene.skyAtmosphere.show = true;

	for (let i = 0; i < 10; i++) {
		rectangles.push(viewer.entities.add({
			rectangle: {
				coordinates: coffeeBeltRectangle,
				material: Cesium.Color.WHITE.withAlpha(0.0),
				height: i * 5000.0,
				outline: true,
				outlineWidth: 4.0,
				outlineColor: Cesium.Color.WHITE
			}
		}));
	}
})

watch([checked3, checked4], (newVal, oldVal) => {
	if (newVal[0]) {
		viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
	} else {
		viewer.scene.globe.cartographicLimitRectangle = Cesium.Rectangle.MAX_VALUE;
	}
	const rectanglesLength = rectangles.length;
	for (let i = 0; i < rectanglesLength; i++) {
		const rectangleEntity = rectangles[i];
		rectangleEntity.show = newVal[1];
	}
})
</script>
<style scoped>
#cesiumContainer {
	overflow: hidden;
}
</style>
<style>
.el-breadcrumb__inner, .el-breadcrumb__separator {
	color: #ffffff !important;
}
</style>

效果图如下

相关推荐
lightgis1 天前
chrome中的axure插件提示无法不受支持
前端·chrome
速易达网络1 天前
Vue3 原生移动应用开发来了
前端·javascript·css
GISer_Jing1 天前
LLM对话框项目技术栈&重难点总结
前端·ai·node.js
我爱学习_zwj1 天前
【鸿蒙进阶-7】鸿蒙与web混合开发
前端·华为·harmonyos
小谭鸡米花1 天前
高德地图电子围栏/地图选区/地图打点
前端·javascript·vue.js
摆烂工程师1 天前
什么是 ChatGPT Business 会员?与 ChatGPT Plus 有什么不同?
前端·后端·程序员
闲不住的李先森1 天前
使用Context7:告别AI“幻觉”,让编程助手永远生成最新、可用的代码
前端·ai编程·cursor
西瓜树枝1 天前
解决 JS 大整数精度丢失?一文读懂 BigInt 的底层逻辑与实战规则
前端·javascript
刺客_Andy1 天前
React 第四十六节 Router中useInRouterContext的使用详细介绍及注意事项
前端·javascript·react.js
刺客_Andy1 天前
React 第四十四节Router中 usefetcher的使用详解及注意事项
前端·javascript·react.js