在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

相关推荐
zenithdev11 天前
开源库入门教程 Cesium:3D地球和地图库
其他·3d·arcgis
研梦非凡1 天前
探索3D空间的视觉基础模型系列
人工智能·深度学习·神经网络·机器学习·计算机视觉·3d
CG_MAGIC2 天前
VR 太阳光参数与快速渲染
3d·vr·3dmax·vray·渲云渲染·灯光设置
私人珍藏库2 天前
[Windows] 3D软件 Blender 5.0 alpha版
windows·3d·建模
列兵阿甘2 天前
知微传感Dkam系列3D相机SDK例程篇:CSharp点云滤波
数码相机·3d
LK_072 天前
【Open3D】Open3D 可视化窗口交互控制说明
笔记·3d
暮色驶过苍茫3 天前
3DGS 如何理解它?
3d
DisonTangor3 天前
Hunyuan3D-Omni:可控3D资产生成的统一框架
人工智能·3d·开源·aigc
葡萄城技术团队3 天前
Wyn 商业智能软件:3D 可视化大屏搭建与工具使用全指南
3d·数据分析
ZhuoLuDa--WuShuYan3 天前
3D打印技术如何重塑PEM双极板的制造范式?
3d·制造·双极板