在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

相关推荐
Yao.Li20 分钟前
PVN3D TensorRT Engine 转换与测试记录
3d·具身智能
Yao.Li2 小时前
PVN3D ONNX / ORT / TRT / 原生 CUDA 测试配合说明
3d
charley.layabox2 小时前
新增3D桥接容器、预览运行时的场景视图,LayaAir3.4.0-beta.2再添重磅实用功能
3d
weixin_5051544610 小时前
打破传统界限:Bowell Studio引领3D作业指导新纪元
人工智能·3d·制造·数据安全·数字孪生·数据可视化
3D小将20 小时前
3DXML转GLTF技术文档(推荐免费在线转换网站)
3d·solidworks模型·ug模型·rhino模型·sketchup模型·igs模型·迪威模型网
孪生引擎观星台1 天前
WSBK专业赛车场3D数字孪生Demo快速开发与系统落地实战指南
人工智能·3d
Yao.Li1 天前
PVN3D ONNX 转换与测试记录
人工智能·3d·具身智能
Gkoob1 天前
Vue3+Three.js 打造实时设备状态 3D 可视化面板
开发语言·javascript·3d
syncon121 天前
手机液晶屏幕AOI异常检测及液晶线路激光修复原理方法
科技·3d·制造
CG_MAGIC2 天前
Blender场景搭建:寻找德尔蒙
3d·blender·贴图·建模教程·渲云渲染