Cesium1.95中高性能加载1500个点

news2025/6/12 22:42:29

一、基本方式:

图标使用.png比.svg性能要好

<template>
  <div id="cesiumContainer"></div>
  <div class="toolbar">
    <button id="resetButton">重新生成点</button>
    <span id="countDisplay">当前车辆数量: 1500</span>
  </div>
</template>

<script setup>
Cesium.Ion.defaultAccessToken = '你的defaultAccessToken';
import { onMounted } from "vue";
import * as Cesium from "cesium";
import "./Widgets/widgets.css";

window.CESIUM_BASE_URL = "/"; // 设置Cesium静态资源路径(public目录)

onMounted(() => {
  // 中国边界经纬度范围
  const chinaBounds = {
    west: 73.66,
    south: 18.10,
    east: 135.08,
    north: 53.52
  };

  // 中国主要省份排除区域(简化版)
  const exclusionAreas = [
    // 示例:排除南海区域
    { west: 105, south: 0, east: 125, north: 22 }
  ];

  // 检查坐标是否在中国境内且不在排除区域内
  function isInChina(lng, lat) {
    // 检查是否在中国边界内
    if (lng < chinaBounds.west || lng > chinaBounds.east ||
      lat < chinaBounds.south || lat > chinaBounds.north) {
      return false;
    }

    // 检查是否在排除区域内
    for (const area of exclusionAreas) {
      if (lng >= area.west && lng <= area.east &&
        lat >= area.south && lat <= area.north) {
        return false;
      }
    }

    return true;
  }

  // 生成随机经纬度(在中国范围内)
  function generateRandomCoordinatesInChina() {
    let lng, lat;
    do {
      lng = chinaBounds.west + Math.random() * (chinaBounds.east - chinaBounds.west);
      lat = chinaBounds.south + Math.random() * (chinaBounds.north - chinaBounds.south);
    } while (!isInChina(lng, lat));

    return { lng, lat };
  }

  // 初始化Cesium
  const viewer = new Cesium.Viewer('cesiumContainer', {
    terrainProvider: Cesium.createWorldTerrain(),
    baseLayerPicker: false, // 禁用底图选择器
    geocoder: false, // 禁用地理编码器
    homeButton: false, // 禁用主页按钮
    infoBox: false, // 禁用信息框
    sceneModePicker: false, // 禁用场景模式选择器
    selectionIndicator: false, // 禁用选择指示器
    navigationHelpButton: false, // 禁用导航帮助按钮
    animation: false, // 禁用动画控件
    timeline: false, // 禁用时间轴
    fullscreenButton: false // 禁用全屏按钮
  });

  // 调整视角到中国
  viewer.camera.setView({
    destination: Cesium.Rectangle.fromDegrees(
      chinaBounds.west,
      chinaBounds.south,
      chinaBounds.east,
      chinaBounds.north
    ),
    orientation: {
      heading: Cesium.Math.toRadians(0.0),
      pitch: Cesium.Math.toRadians(-15.0)
    }
  });

  // 创建车辆图像Primitive
  let vehiclePrimitives;
  const vehicleCount = 1500;

  // 加载车辆SVG图像
  const carSvgUrl = '/Assets/nav.svg';

  function createVehiclePrimitives() {
    // 清除现有primitives
    if (vehiclePrimitives) {
      viewer.scene.primitives.remove(vehiclePrimitives);
    }

    // 创建新的primitives集合
    vehiclePrimitives = new Cesium.PrimitiveCollection();

    // 创建1500个车辆图标
    for (let i = 0; i < vehicleCount; i++) {
      const position = generateRandomCoordinatesInChina();

      // 创建车辆billboard
      const billboardCollection = new Cesium.BillboardCollection();
      const billboard = billboardCollection.add({
        position: Cesium.Cartesian3.fromDegrees(position.lng, position.lat, 10),
        image: carSvgUrl,
        width: 24,
        height: 24,
        scale: 1.0,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
        color: Cesium.Color.WHITE,
        rotation: Math.random() * Math.PI * 2, // 随机朝向
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      });

      vehiclePrimitives.add(billboardCollection);
    }

    // 添加到场景
    viewer.scene.primitives.add(vehiclePrimitives);
  }

  // 初始化创建车辆
  createVehiclePrimitives();

  // 重置按钮事件
  document.getElementById('resetButton').addEventListener('click', function () {
    createVehiclePrimitives();
    document.getElementById('countDisplay').textContent = `当前车辆数量: ${vehicleCount}`;
  });

})

</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

#cesiumContainer {
  width: 100wh;
  height: 100vh;
}

.toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(42, 42, 42, 0.8);
  color: white;
  padding: 8px 15px;
  border-radius: 5px;
  display: flex;
  gap: 15px;
  align-items: center;
  z-index: 100;
}

.toolbar button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 6px 12px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.toolbar button:hover {
  background-color: #45a049;
}

.toolbar span {
  font-size: 14px;
}
</style>

二、加载图片性能更好的方式:

<template>
  <div id="cesiumContainer"></div>
</template>

<script setup>
Cesium.Ion.defaultAccessToken = '你的defaultAccessToken';
import { onMounted } from "vue";
import * as Cesium from "cesium";
import "./Widgets/widgets.css";

window.CESIUM_BASE_URL = "/"; // 设置Cesium静态资源路径(public目录)

onMounted(() => {
  // ===== 初始化Viewer =====
  const viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode: Cesium.SceneMode.SCENE2D, // 初始二维模式
    terrainProvider: Cesium.createWorldTerrain(),
    baseLayerPicker: false
  });

  // ===== 生成1500个中国坐标 =====
  const positions = [];
  for (let i = 0; i < 1500; i++) {
    const lon = Math.random() * 62 + 73;  // 东经73°-135°
    const lat = Math.random() * 35 + 18;  // 北纬18°-53°
    positions.push(Cesium.Cartesian3.fromDegrees(lon, lat, 0));
  }

  // ===== 二维模式:使用BillboardCollection加载PNG图标 =====
  const billboards = new Cesium.BillboardCollection();
  viewer.scene.primitives.add(billboards);

  positions.forEach(pos => {
    billboards.add({
      position: pos,
      image: '/Assets/nav.svg',
      width: 32,
      height: 32,
      scaleByDistance: new Cesium.NearFarScalar(1e3, 1.0, 2e6, 0.2) // 视距缩放优化[3](@ref)
    });
  });

  // ===== 性能监控(可选) =====
  viewer.scene.debugShowFramesPerSecond = true;
})

</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

#cesiumContainer {
  width: 100wh;
  height: 100vh;
}

.toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(42, 42, 42, 0.8);
  color: white;
  padding: 8px 15px;
  border-radius: 5px;
  display: flex;
  gap: 15px;
  align-items: center;
  z-index: 100;
}

.toolbar button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 6px 12px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.toolbar button:hover {
  background-color: #45a049;
}

.toolbar span {
  font-size: 14px;
}
</style>

刷新数据

<template>
  <div id="cesiumContainer"></div>
  <div class="toolbar">
    <button id="resetButton">重新生成点</button>
    <span id="countDisplay">当前车辆数量: 1500</span>
  </div>
</template>

<script setup>
Cesium.Ion.defaultAccessToken = '你的defaultAccessToken';
import { onMounted } from "vue";
import * as Cesium from "cesium";
import "./Widgets/widgets.css";

window.CESIUM_BASE_URL = "/"; // 设置Cesium静态资源路径(public目录)

onMounted(() => {
  // ===== 初始化Viewer =====
  const viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode: Cesium.SceneMode.SCENE2D, // 初始二维模式
    terrainProvider: Cesium.createWorldTerrain(),
    baseLayerPicker: false
  });

  // ===== 生成1500个中国坐标 =====
  const positions = [];
  for (let i = 0; i < 1500; i++) {
    const lon = Math.random() * 62 + 73;  // 东经73°-135°
    const lat = Math.random() * 35 + 18;  // 北纬18°-53°
    positions.push(Cesium.Cartesian3.fromDegrees(lon, lat, 0));
  }

  // 创建车辆图像Primitive
  let billboards;

  function createVehiclePrimitives() {
    // 清除现有primitives
    if (billboards) {
      viewer.scene.primitives.remove(billboards);
    }

    // 创建新的primitives集合
    billboards = new Cesium.BillboardCollection();

    positions.forEach(pos => {
      billboards.add({
        position: pos,
        image: '/Assets/nav.svg',
        width: 32,
        height: 32,
        scaleByDistance: new Cesium.NearFarScalar(1e3, 1.0, 2e6, 0.2) // 视距缩放优化[3](@ref)
      });
    });

    // 添加到场景
    viewer.scene.primitives.add(billboards);
  }

  // 初始化创建车辆
  createVehiclePrimitives();

  // 重置按钮事件
  document.getElementById('resetButton').addEventListener('click', function () {
    createVehiclePrimitives();
    document.getElementById('countDisplay').textContent = `当前车辆数量: 1500`;
  });

  // ===== 性能监控(可选) =====
  viewer.scene.debugShowFramesPerSecond = true;
})

</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

#cesiumContainer {
  width: 100wh;
  height: 100vh;
}

.toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(42, 42, 42, 0.8);
  color: white;
  padding: 8px 15px;
  border-radius: 5px;
  display: flex;
  gap: 15px;
  align-items: center;
  z-index: 100;
}

.toolbar button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 6px 12px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.toolbar button:hover {
  background-color: #45a049;
}

.toolbar span {
  font-size: 14px;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2407849.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

大型活动交通拥堵治理的视觉算法应用

大型活动下智慧交通的视觉分析应用 一、背景与挑战 大型活动&#xff08;如演唱会、马拉松赛事、高考中考等&#xff09;期间&#xff0c;城市交通面临瞬时人流车流激增、传统摄像头模糊、交通拥堵识别滞后等问题。以演唱会为例&#xff0c;暖城商圈曾因观众集中离场导致周边…

循环冗余码校验CRC码 算法步骤+详细实例计算

通信过程&#xff1a;&#xff08;白话解释&#xff09; 我们将原始待发送的消息称为 M M M&#xff0c;依据发送接收消息双方约定的生成多项式 G ( x ) G(x) G(x)&#xff08;意思就是 G &#xff08; x ) G&#xff08;x) G&#xff08;x) 是已知的&#xff09;&#xff0…

【HarmonyOS 5.0】DevEco Testing:鸿蒙应用质量保障的终极武器

——全方位测试解决方案与代码实战 一、工具定位与核心能力 DevEco Testing是HarmonyOS官方推出的​​一体化测试平台​​&#xff0c;覆盖应用全生命周期测试需求&#xff0c;主要提供五大核心能力&#xff1a; ​​测试类型​​​​检测目标​​​​关键指标​​功能体验基…

Day131 | 灵神 | 回溯算法 | 子集型 子集

Day131 | 灵神 | 回溯算法 | 子集型 子集 78.子集 78. 子集 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a; 笔者写过很多次这道题了&#xff0c;不想写题解了&#xff0c;大家看灵神讲解吧 回溯算法套路①子集型回溯【基础算法精讲 14】_哔哩哔哩_bilibili 完…

python/java环境配置

环境变量放一起 python&#xff1a; 1.首先下载Python Python下载地址&#xff1a;Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个&#xff0c;然后自定义&#xff0c;全选 可以把前4个选上 3.环境配置 1&#xff09;搜高级系统设置 2…

安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件

在选煤厂、化工厂、钢铁厂等过程生产型企业&#xff0c;其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进&#xff0c;需提前预防假检、错检、漏检&#xff0c;推动智慧生产运维系统数据的流动和现场赋能应用。同时&#xff0c;…

如何在看板中体现优先级变化

在看板中有效体现优先级变化的关键措施包括&#xff1a;采用颜色或标签标识优先级、设置任务排序规则、使用独立的优先级列或泳道、结合自动化规则同步优先级变化、建立定期的优先级审查流程。其中&#xff0c;设置任务排序规则尤其重要&#xff0c;因为它让看板视觉上直观地体…

PPT|230页| 制造集团企业供应链端到端的数字化解决方案:从需求到结算的全链路业务闭环构建

制造业采购供应链管理是企业运营的核心环节&#xff0c;供应链协同管理在供应链上下游企业之间建立紧密的合作关系&#xff0c;通过信息共享、资源整合、业务协同等方式&#xff0c;实现供应链的全面管理和优化&#xff0c;提高供应链的效率和透明度&#xff0c;降低供应链的成…

Mybatis逆向工程,动态创建实体类、条件扩展类、Mapper接口、Mapper.xml映射文件

今天呢&#xff0c;博主的学习进度也是步入了Java Mybatis 框架&#xff0c;目前正在逐步杨帆旗航。 那么接下来就给大家出一期有关 Mybatis 逆向工程的教学&#xff0c;希望能对大家有所帮助&#xff0c;也特别欢迎大家指点不足之处&#xff0c;小生很乐意接受正确的建议&…

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…

Docker 运行 Kafka 带 SASL 认证教程

Docker 运行 Kafka 带 SASL 认证教程 Docker 运行 Kafka 带 SASL 认证教程一、说明二、环境准备三、编写 Docker Compose 和 jaas文件docker-compose.yml代码说明&#xff1a;server_jaas.conf 四、启动服务五、验证服务六、连接kafka服务七、总结 Docker 运行 Kafka 带 SASL 认…

《从零掌握MIPI CSI-2: 协议精解与FPGA摄像头开发实战》-- CSI-2 协议详细解析 (一)

CSI-2 协议详细解析 (一&#xff09; 1. CSI-2层定义&#xff08;CSI-2 Layer Definitions&#xff09; 分层结构 &#xff1a;CSI-2协议分为6层&#xff1a; 物理层&#xff08;PHY Layer&#xff09; &#xff1a; 定义电气特性、时钟机制和传输介质&#xff08;导线&#…

基于uniapp+WebSocket实现聊天对话、消息监听、消息推送、聊天室等功能,多端兼容

基于 ​UniApp + WebSocket​实现多端兼容的实时通讯系统,涵盖WebSocket连接建立、消息收发机制、多端兼容性配置、消息实时监听等功能,适配​微信小程序、H5、Android、iOS等终端 目录 技术选型分析WebSocket协议优势UniApp跨平台特性WebSocket 基础实现连接管理消息收发连接…

Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)

概述 在 Swift 开发语言中&#xff0c;各位秃头小码农们可以充分利用语法本身所带来的便利去劈荆斩棘。我们还可以恣意利用泛型、协议关联类型和协议扩展来进一步简化和优化我们复杂的代码需求。 不过&#xff0c;在涉及到多个子类派生于基类进行多态模拟的场景下&#xff0c;…

无法与IP建立连接,未能下载VSCode服务器

如题&#xff0c;在远程连接服务器的时候突然遇到了这个提示。 查阅了一圈&#xff0c;发现是VSCode版本自动更新惹的祸&#xff01;&#xff01;&#xff01; 在VSCode的帮助->关于这里发现前几天VSCode自动更新了&#xff0c;我的版本号变成了1.100.3 才导致了远程连接出…

基于Flask实现的医疗保险欺诈识别监测模型

基于Flask实现的医疗保险欺诈识别监测模型 项目截图 项目简介 社会医疗保险是国家通过立法形式强制实施&#xff0c;由雇主和个人按一定比例缴纳保险费&#xff0c;建立社会医疗保险基金&#xff0c;支付雇员医疗费用的一种医疗保险制度&#xff0c; 它是促进社会文明和进步的…

SCAU期末笔记 - 数据分析与数据挖掘题库解析

这门怎么题库答案不全啊日 来简单学一下子来 一、选择题&#xff08;可多选&#xff09; 将原始数据进行集成、变换、维度规约、数值规约是在以下哪个步骤的任务?(C) A. 频繁模式挖掘 B.分类和预测 C.数据预处理 D.数据流挖掘 A. 频繁模式挖掘&#xff1a;专注于发现数据中…

vscode(仍待补充)

写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh&#xff1f; debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…

解决Ubuntu22.04 VMware失败的问题 ubuntu入门之二十八

现象1 打开VMware失败 Ubuntu升级之后打开VMware上报需要安装vmmon和vmnet&#xff0c;点击确认后如下提示 最终上报fail 解决方法 内核升级导致&#xff0c;需要在新内核下重新下载编译安装 查看版本 $ vmware -v VMware Workstation 17.5.1 build-23298084$ lsb_release…

(二)TensorRT-LLM | 模型导出(v0.20.0rc3)

0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述&#xff0c;后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作&#xff0c;其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…