在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 小时前
3D激光轮廓仪知识整理(待补充)
数码相机·3d
MediaTea1 天前
Ae 效果详解:3D 眼镜
3d
知来者逆2 天前
探索生成式AI在游戏开发中的应用——3D角色生成式 AI 实现
人工智能·深度学习·神经网络·计算机视觉·3d·游戏开发
木木黄木木2 天前
html5炫酷3D文字效果项目开发实践
前端·3d·html5
帮帮志2 天前
05.unity 游戏开发-3D工程的创建及使用方式和区别
3d·unity·游戏引擎
在下胡三汉3 天前
gltf unity-Unity中Gltf模型的使用与优化技巧
3d
前端极客探险家3 天前
如何用 Three.js 和 Vue 3 实现 3D 商品展示
javascript·vue.js·3d
余人于RenYu3 天前
3D 地图渲染-区域纹理图添加
3d·高德地图
小西几哦3 天前
3D点云配准RPM-Net模型解读(附论文+源码)
人工智能·pytorch·3d