在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

相关推荐
与妖为邻3 小时前
好玩的进3D度条
css·3d·css3·动态渐变·js自动输入
炫云云渲染9 小时前
2024年”3D Awards”优秀作品提名新鲜出炉
3d·云渲染·渲染技术·max插件·炫云
qq_153214526417 小时前
【2023工业3D异常检测文献】PointCore: 基于局部-全局特征的高效无监督点云异常检测器
深度学习·神经网络·目标检测·机器学习·计算机视觉·3d·视觉检测
bei_7721 小时前
发掘3D文件格式的无限潜力:打造沉浸式虚拟世界
3d
光学测量小菜鸡1 天前
TOF系列—深度图滤波
人工智能·算法·3d
数据猎手小k1 天前
SUP-NeRF-ECCV2024: 单目3D对象重建的新突破
3d
loong_XL2 天前
3D 模型GLTF、GLB格式文件介绍使用;FBX格式
3d·gltf·glb·3d 模型
zenpluck2 天前
GS-SLAM论文阅读笔记--MM3DGS SLAM
论文阅读·笔记·3d
试剂界的爱马仕2 天前
AbMole揭秘3D类器官技术解锁SARS-CoV-2子宫内膜感染新视角
网络·科技·3d