在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

相关推荐
da_vinci_x6 小时前
告别“纸片树冠”:SpeedTree 10的次世代 Nanite 植被透射与程序化季相重构工作流
游戏·3d·重构·aigc·材质·技术美术·游戏策划
CG_MAGIC16 小时前
3D 软件文件格式详解:OBJ/FBX/USD 导出与导入规范
3d·blender·贴图·建模教程·渲云渲染
Tatalaluola1 天前
3DGS高斯泼溅渲染简单理解
3d·unity·三维重建
_千思_1 天前
【小白说】【论文拆解】SSRNet: Scalable 3D Surface Reconstruction Network
3d·三维重建
新启航-光学3D测量1 天前
宠物的关节、牙齿等部位的光学三维扫描测量逆向-激光三维扫描仪
科技·3d·制造
深蓝学院1 天前
港科大沈劭劼团队|VG3S:不微调、不遗忘,即插即用实现高精度3D占用预测
3d·自动驾驶
小小码农Come on1 天前
VTK-8.2.0+QT5.14.2展示3D图像
qt·3d·swift
沙振宇2 天前
【Web】使用Vue3+PlayCanvas开发3D游戏(二)3D 地图自由巡视闯关游戏
游戏·3d·vue3·playcanvas
新启航光学频率梳2 天前
齿轮箱传动轴孔孔深光学3D轮廓测量-激光频率梳3D轮廓技术
科技·3d·制造
青稞社区.2 天前
MIT&Harvard 最新提出 PAGE-4D:让 3D 模型“看懂“动态世界的统一框架
人工智能·3d