在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

相关推荐
代数狂人11 小时前
《深入浅出Godot 4与C# 3D游戏开发》第二章:编辑器导航
3d·编辑器·游戏引擎·godot
VBsemi-专注于MOSFET研发定制11 小时前
高端汽车零部件尺寸3D检测设备功率MOSFET选型方案:精密高效运动与成像电源驱动系统适配指南
3d·汽车
threelab14 小时前
从工厂模式到简化封装:三维引擎架构演进之路 threejs设计
javascript·3d·架构·webgl
三毛的二哥14 小时前
BEV:MapTR
人工智能·算法·计算机视觉·3d
地知通18 小时前
地下管网AR可视化更新:支持AR拍照、智能巡检、3dtiles等4项功能
3d·ar·数字孪生·地下管网·移动巡检·参数化建模
林恒smileZAZ1 天前
Three.js实现更真实的3D地球[特殊字符]动态昼夜交替
开发语言·javascript·3d
三维频道1 天前
不止于精度:汽车精密锻铸件质检的“数据降维”与方案重构
3d·重构·汽车·工业数字化·蓝光三维扫描仪·汽车供应链·汽车智能制造
yeflx1 天前
正射模块-odm_orthophoto
3d
Hali_Botebie1 天前
【3D 生成技术】3D Gaussian Splatting 的基础理解
3d
3DVisionary2 天前
【深度实测】从三坐标到全场扫描:汽车精密锻铸件 3D 质检的数字化进阶
3d·汽车·质量检测·精密制造·三维扫描仪·汽车工业·xtop3d