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))
    },
  },
})
相关推荐
GISer_Jing2 分钟前
构建高性能Markdown引擎开发计划
前端·aigc·ai编程
CHU72903519 分钟前
生鲜商城小程序前端功能版块:适配生鲜采购核心需求
前端·小程序
huangyiyi6666634 分钟前
Vue + TS 项目文件结构
前端·javascript·vue.js
0思必得01 小时前
[Web自动化] Selenium处理Cookie
前端·爬虫·python·selenium·自动化
徐同保1 小时前
react-markdown使用
前端·react.js·前端框架
2601_949857431 小时前
Flutter for OpenHarmony Web开发助手App实战:CSS参考
前端·css·flutter
无法长大1 小时前
如何判断项目需不需要用、能不能用Tailwind CSS
前端·css·vue.js·elementui·vue3·tailwind css
橙露1 小时前
移动端前端适配:Rem、VW/VH 与媒体查询的综合应用指南
前端·媒体
GGGG寄了1 小时前
CSS——CSS引入方式+选择器类型
前端·css·html
墨染青竹梦悠然1 小时前
基于Django+vue的图书借阅管理系统
前端·vue.js·后端·python·django·毕业设计·毕设