在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

相关推荐
DolitD7 小时前
无人机×云渲染:点量云流实时交互云推流方案
3d·云计算·数据可视化·虚拟现实
云飞云共享云桌面12 小时前
单机建模卡顿运维繁琐!中小型机械制造厂云飞云 3D 云桌面落地
运维·服务器·网络·3d·自动化·电脑·负载均衡
2601_9564141417 小时前
AI3D模型生成工具怎么比较?看生成质量、后续流程和导出能力
人工智能·3d
私人珍藏库20 小时前
[Android] VOKA -人体解剖3D图谱+医学人体解剖
3d·智能手机·app·工具·软件·多功能
2601_956414142 天前
AI3D模型生成工具怎么比较?2026主流平台对比与实测维度解析
人工智能·3d
蓝速科技2 天前
蓝速科技视觉 3D 全息仓 AI 数字人一体机深度评测
人工智能·科技·3d
chaoyuanl2 天前
现有游乐设施 XR 数字化升级改造方案
大数据·科技·3d·xr·娱乐
3D小将2 天前
3D格式转换之3MF模型转GLB通用技术
3d·solidworks模型·ug模型·rhino模型·catia模型
韭菜钟2 天前
利用OpenCV进行3d相机手眼标定(眼在手上/眼在手外)
opencv·3d
数智工坊3 天前
视图集合化+轻量Transformer:VSFormer开启多视图3D形状理解新范式
深度学习·3d·transformer