当前位置: 首页 > news >正文

CesiumJS 案例 P18:检测文本、删除所有文本、隐藏与显示文本、改变文本

CesiumJS

  • CesiumJS API:https://cesium.com/learn/cesiumjs/ref-doc/index.html

  • CesiumJS 是一个开源的 JavaScript 库,它用于在网页中创建和控制 3D 地球仪(地图)


一、检测文本

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Label - 检测文本</title><link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" /><style>* {margin: 0;padding: 0;box-sizing: border-box;}html,body {width: 100%;height: 100%;}.container {width: 100%;height: 100%;}.btn-remove-text {position: fixed;left: 0px;top: 0px;}.btn-check-text {position: fixed;left: 0px;top: 50px;}</style></head><body><div id="container"></div><button class="btn-remove-text">删除文本</button><button class="btn-check-text">检测文本</button></body><script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script><script>const viewer = new Cesium.Viewer("container");const labels = viewer.scene.primitives.add(new Cesium.LabelCollection());const label = labels.add({text: "Hello World",position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),});const btnMoveText = document.querySelector(".btn-remove-text");const btnCheckText = document.querySelector(".btn-check-text");btnMoveText.addEventListener("click", () => {labels.remove(label);});btnCheckText.addEventListener("click", () => {console.log(labels.contains(label));});</script>
</html>

二、删除所有文本

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Label - 删除文本</title><link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" /><style>* {margin: 0;padding: 0;box-sizing: border-box;}html,body {width: 100%;height: 100%;}.container {width: 100%;height: 100%;}.btn-all-remove {position: fixed;left: 0px;top: 0px;}</style></head><body><div id="container"></div><button class="btn-all-remove">删除所有文本</button></body><script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script><script>const viewer = new Cesium.Viewer("container");const labels = viewer.scene.primitives.add(new Cesium.LabelCollection());labels.add({text: "Hello World",position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),});labels.add({text: "Hello World",position: Cesium.Cartesian3.fromDegrees(-75.59777, 41.03883),});const btnAllRemove = document.querySelector(".btn-all-remove");btnAllRemove.addEventListener("click", () => {labels.removeAll();});</script>
</html>

三、隐藏与显示文本

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Label - 隐藏与显示文本</title><link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" /><style>* {margin: 0;padding: 0;box-sizing: border-box;}html,body {width: 100%;height: 100%;}.container {width: 100%;height: 100%;}.btn-hide-or-show {position: fixed;left: 0px;top: 0px;}</style></head><body><div id="container"></div><button class="btn-hide-or-show">隐藏 / 显示文本</button></body><script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script><script>const viewer = new Cesium.Viewer("container");const labels = viewer.scene.primitives.add(new Cesium.LabelCollection());const label = labels.add({text: "Hello World",position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),});const btnHideOrShow = document.querySelector(".btn-hide-or-show");btnHideOrShow.addEventListener("click", () => {label.show = !label.show;});</script>
</html>

四、改变文本

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Label - 改变文本</title><link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" /><style>* {margin: 0;padding: 0;box-sizing: border-box;}html,body {width: 100%;height: 100%;}.container {width: 100%;height: 100%;}.btn-change {position: fixed;left: 0px;top: 0px;}</style></head><body><div id="container"></div><button class="btn-change">改变文本</button></body><script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script><script>const viewer = new Cesium.Viewer("container");const labels = viewer.scene.primitives.add(new Cesium.LabelCollection());const label = labels.add({text: "Hello World 1",position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),});const btnChange = document.querySelector(".btn-change");btnChange.addEventListener("click", () => {label.text = "Hello World 2";});</script>
</html>

http://www.mrgr.cn/news/64158.html

相关文章:

  • 【Visual Studio】解决 CC++ 控制台程序 printf 函数输出中文和换行符显示异常
  • uniapp实现书架
  • C语言---程序设计练习题目及学习方法2
  • PSI-BLAST位点特异性矩阵PSSM和ProteinMPNN中氨基酸顺序映射
  • 8.3.2 前向分步算法与 AdaBoost
  • git入门教程
  • 二维码中怎么存入文件?文件二维码活码的3步制作技巧
  • CAD图纸防泄密|哪些措施可以加密公司图纸?五个宝藏方法分享,2024必读!
  • 无人机维护保养、部件修理更换技术详解
  • Python 列表的定义语法
  • 【毫米波雷达(四)】车载毫米波雷达下线EOL标定流程
  • 【VUE+DRF】案例升级
  • 国产服务器部署1.获取银河麒麟V10服务器。首先挂gpt数据盘
  • Apache-Seata 拯救分布式系统数据一致性的开源神器
  • vcruntime140.dll如何修复,六种解决vcruntime140.dll的方法分享
  • Python-创建并调用自定义文件中的模块/函数
  • 如何绘制带有误差线的堆叠柱状图
  • 【C语言】文件操作
  • 2021 icpc南京(A,M,C,H,J,D)
  • Java和C++有什么区别?JVM不是跨平台的?JVM是用什么语言编写的?
  • 前端性能优化 | 响应式布局、响应式图片最全解析
  • 智能呼叫中心详细介绍
  • 消息队列mq有哪些缺点?
  • 【Python】进程、线程、协程篇 (无偿分享一份全套的 Python 学习资料)
  • 真题与解析 202212三级 青少年软件编程(Python)考级
  • web服务器