vue3 + mars3D 三分钟画一个地球

mars3D开发文档:

http://mars3d.cn/docs/http://mars3d.cn/docs/

Vue组件中:

复制代码
<script setup lang="ts">
import * as mars3d from "mars3d"
import { onMounted} from "vue"
let map: mars3d.Map;
onMounted(() => {
  map = new mars3d.Map("key", {
  basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }]
})
});

</script>

<template>

<div id="key" class="mars3d-container"></div>

</template>


<style scoped>

</style>

package.json:

复制代码
//已经省去无关代码
"dependencies": {
    //已经省去无关代码
    "mars3d": "^3.10.6",
    "mars3d-cesium": "^1.134.0",
    "mars3d-space": "^3.10.6",
    "vite-plugin-mars3d": "^4.2.2",
  },
  //已经省去无关代码

vite.config.ts:

复制代码
import { mars3dPlugin } from "vite-plugin-mars3d"
  //已经省去无关代码
  plugins: [
    //已经省去无关部分
    mars3dPlugin(),
    
  ],
  //已经省去无关代码

运行

pnpm i

pnpm run dev

效果图:

常见问题:

TypeError: Failed to execute 'createImageBitmap' on 'Window': The provided value is not of type '(Blob or HTMLCanvasElement or HTMLImageElement or HTMLVideoElement or ImageBitmap or ImageData or OffscreenCanvas or SVGImageElement or VideoFrame)'.

原因:当前开发阶段,后端暂无法提供服务,前端开发引入mockjs模拟后端接口响应数据。mockjs原生代码影响了cesium加载地图,

InvalidStateError: The source image could not be decoded.

原因:没有引入ars3d插件

解决:

在vite配置文件中加入mars3dPlugin():

复制代码
import { mars3dPlugin } from "vite-plugin-mars3d"
export default defineConfig({
  plugins: [
    //已经省去无关部分
    mars3dPlugin(),
    
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
相关推荐
风骏时光牛马10 分钟前
C语言核心高频问题与代码实战梳理
前端
葬送的代码人生18 分钟前
别再「Ctrl+C/V」了!Git 开发必备技能,10 分钟告别单机码农
前端·github·代码规范
xuankuxiaoyao20 分钟前
vue.js 设计与开发 ---路由
前端·javascript·vue.js
ZC跨境爬虫22 分钟前
跟着 MDN 学CSS day_6:(伪类和伪元素详解)
前端·javascript·css·数据库·ui·html
idcu24 分钟前
Lyt.js + Vite 快速开发指南
前端·typescript
暗不需求24 分钟前
玩转 React Hooks:从基础到实战,逐行解析带你彻底掌握
前端·react.js·面试
一颗小青松25 分钟前
css 文字区域根据图片形状显示,根据文字设置背景图
前端·css
阿黎梨梨26 分钟前
跟 Git 打交道的正确姿势
前端
idcu26 分钟前
深入 Lyt.js 路由系统:L6 生态系统层的核心
前端·typescript
idcu27 分钟前
用 Lyt.js 构建 Todo 应用:完整教程
前端·typescript