在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

相关推荐
mirrornan14 小时前
3D全景沉浸式看车:虚拟现实重构汽车消费新体验
科技·3d·汽车·vr·3d数字化·3d看车
pixle01 天前
Three.js 快速入门教程【一】开启你的 3D Web 开发之旅
前端·javascript·3d
视觉人机器视觉1 天前
机器视觉中的3D高反光工件检测
人工智能·3d·c#·视觉检测
mirrornan2 天前
从建模到展示,如何实现3D在线预览展示?
3d
3D小将2 天前
STL 在线转 3MF,开启 3D 模型转换新体验
3d·3d格式转换
视觉人机器视觉2 天前
3D与2D机器视觉机械臂引导的区别
人工智能·数码相机·计算机视觉·3d·视觉检测
视觉人机器视觉2 天前
机器视觉3D深度图颜色含义解析
人工智能·3d·c#·视觉检测
fyzy2 天前
QPainter绘制3D 饼状图
qt·3d
mirrornan2 天前
什么是3D可视化?有哪些优势和应用领域?
3d·3d可视化
jimumeta2 天前
VR虚拟展厅如何改变企业展示的传播方式?
3d·vr·虚拟展厅·3d展厅