在nuxt中集成mars3d

创建一个nuxt项目

创建一个项目,安装依赖

安装mars3d ,安装mars3d-cesium

替换app.vue

html 复制代码
<template>
  <div id="mars3dContainer" class="mars3d-container"></div>
  <!-- <div>123</div> -->
</template>

<script>
import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";
import "mars3d-cesium";

import "mars3d/dist/mars3d.css";
import * as mars3d from "mars3d";

export default {
  mounted() {
    // 创建Mars3D地球实例
    const map = new mars3d.Map("mars3dContainer", {
      // 配置项,如底图、中心点等
      basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
      center: { lng: 116.397428, lat: 39.90923, alt: 1181 },
    });
  },
};
</script>

<style>
.mars3d-container {
  width: 100%;
  height: 100vh; /* 或其他固定高度 */
}
</style>

替换nuxt.config.ts文件

html 复制代码
// https://nuxt.com/docs/api/configuration/nuxt-config

export default defineNuxtConfig({
  ssr: false,
  compatibilityDate: "2024-04-03",
  devtools: { enabled: false },
  app: {
    head: {
      script: [
        {
          //must match the nitro config below for where the files are being served publicly
          children: `window.CESIUM_BASE_URL='_nuxt/Cesium';`,
        },
      ],
    },
  },
  nitro: {
    publicAssets: [
      {
        baseURL: "_nuxt/Cesium/Assets",
        dir: "../node_modules/mars3d-cesium/Build/Cesium/Assets",
      },
      {
        baseURL: "_nuxt/Cesium/Workers",
        dir: "../node_modules/mars3d-cesium/Build/Cesium/Workers",
      },
      {
        baseURL: "_nuxt/Cesium/ThirdParty",
        dir: "../node_modules/mars3d-cesium/Build/Cesium/ThirdParty",
      },
      {
        baseURL: "_nuxt/Cesium/Widgets",
        dir: "../node_modules/mars3d-cesium/Build/Cesium/Widgets",
      },
    ],
  },
});

成功

参考连接

https://community.cesium.com/t/using-cesium-npm-package-with-nuxt-3/29593/3

相关推荐
yuankoudaodaokou13 小时前
无图纸如何定制汽车外饰件?3DeVOK MT+ QUICKSURFACE逆向设计解决方案
python·3d·汽车·机器翻译
yuankoudaodaokou14 小时前
精准与高效:3D扫描技术如何重塑康复辅具设计与制造
python·3d·制造
Coovally AI模型快速验证16 小时前
Meta ShapeR重磅开源:多模态3D生成,从真实杂乱视频中稳健重建
人工智能·学习·算法·yolo·3d·人机交互
zl_vslam16 小时前
SLAM中的非线性优-3D图优化之绝对位姿SE3约束SO3/t形式(十八)
人工智能·算法·计算机视觉·3d
CG_MAGIC16 小时前
Blender 渲染降噪:Cycles 核心参数与 AI 降噪工具应用
3d·blender·贴图·建模教程·渲云渲染
memmolo17 小时前
【3D测量中的术语:系统误差、随机误差、精密度、准确度】
算法·计算机视觉·3d
秋名山大前端17 小时前
前端大规模 3D 轨迹数据可视化系统的性能优化实践
前端·3d·性能优化
HZjiangzi17 小时前
汽车覆盖件拉延模具磨损怎么修复?思看3DeVOK MT逆向工程方案推荐
科技·3d·汽车
CG_MAGIC17 小时前
Maya 角色绑定基础:骨骼搭建与权重绘制避坑要点
3d·maya·渲云渲染·3d软件
L186924547821 天前
Win 下 PCL部分函数析构崩溃问题总结
c++·计算机视觉·3d·pcl