vue3 + vite + ts 集成mars3d

文章目录

  • vue3 + vite + ts 集成mars3d
  • 前言
  • 一、创建一个vue3 + vite + ts项目
  • 二、引入mars3d相关依赖
  • 三、vite.config.ts 相关配置
  • 四、 新建DIV容器 + 创建地图

前言

使用mars3d过程中,需要集成mars3d到自己的项目中,mars3d开发教程中已经有集成好的项目模板
http://mars3d.cn/doc.html
项目模板gitte地址:https://gitee.com/marsgis/mars3d-vue-template/tree/master/mars3d-vue3-vite
如果不想用官方的模板就需要自己集成


一、创建一个vue3 + vite + ts项目

如何创建项目参考网上的教程,这里就不做详细的说明,我们直接步入正题。

二、引入mars3d相关依赖

这里使用npm的方式引用
1、引入mars3d

npm install mars3d --save

2、引入mars3d-cesium

npm install mars3d-cesium --save

到目前为止mars3d最主要的依赖库已经安装好了

三、vite.config.ts 相关配置

参考教程:安装mars3d vite插件库
具体配置如下

到这步基本配置就完成了

四、 新建DIV容器 + 创建地图

1、在app.vue中使用组件main-view

2、创建main-view组件

<template><div id="mars3dContainer" class="mars3d-container"></div>
</template><script lang="ts" setup>
import { onMounted,reactive } from "vue";
import * as mars3d from "mars3d";onMounted(() => {var mapOptions = {basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
};
var map = new mars3d.Map("mars3dContainer", mapOptions);});
};
</script><style lang="less" scoped>
</style>

到这步不出意外的话Mars3d地球已经出来了。

其它问题:
这是基本配置,可以在public文件夹下新建config文件,文件夹下新建config.json文件
http://mars3d.cn/config/config.json

main-view组件改动一下

<template><div id="mars3dContainer" class="mars3d-container"></div>
</template><script lang="ts" setup>
import { onMounted,reactive } from "vue";
import * as mars3d from "mars3d";onMounted(() => {const configUrl = `${process.env.BASE_URL}config/config.json`;mars3d.Util.fetchJson({ url: configUrl }).then((data) => {initMars3d(data.map3d);});
});// const router = useRouter()let map: any;
const initMars3d = (option: any) => {map = new mars3d.Map("mars3dContainer", option);// 开场动画// map.openFlyAnimation();// 针对不同终端的优化配置if (mars3d.Util.isPCBroswer()) {map.zoomFactor = 2.0; // 鼠标滚轮放大的步长参数// IE浏览器优化if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 0) {map.viewer.targetFrameRate = 20; // 限制帧率map.scene.requestRenderMode = false; // 取消实时渲染}} else {map.zoomFactor = 5.0; // 鼠标滚轮放大的步长参数// 移动设备上禁掉以下几个选项,可以相对更加流畅map.scene.requestRenderMode = false; // 取消实时渲染map.scene.fog.enabled = false;map.scene.skyAtmosphere.show = false;map.scene.globe.showGroundAtmosphere = false;}// //二三维切换不用动画if (map.viewer.sceneModePicker) {map.viewer.sceneModePicker.viewModel.duration = 0.0;}
};
</script><style lang="less" scoped>
.mars3d-container {width: 100%;height: 100%;overflow: hidden;}
</style>

基本上一个炫酷的地球就完成了
如果控制台报 资源图片没有找到 404错误,就把官方示例下载下来 ,把public/img文件拷贝到 对应你的问夹下就可以了
附:整个项目结构目录

vue3 + vite + ts 集成mars3d相关推荐

  1. 【Vue3+Vite+TS项目集成ESlint +Prettier实现代码规范检查和代码格式化】

    目录 前言 创建项目 安装初始化ESlint 安装ESlint: 初始化ESlint: 安装配置Prettier 安装prettier: 配置prettier: 配置VScode保存时自动格式化代码 ...

  2. vue3:vue3+vite+ts+pinia

    一.背景 记录一套技术方案. 二.项目基础 2.1.创建项目 yarn create vite 输入名字后,这里出现了几个选项,不清楚都是干啥的,下来研究 选择后完成 2.2.vite.config. ...

  3. 【记录】VUE3 + VITE + TS 配置跨域

    [记录]VUE3 + VITE + TS 配置跨域 在vite.config.ts进行如下设置 在vite.config.ts进行如下设置 server: {host: true,// 设置端口号po ...

  4. 如何在vue3+vite+ts中使用require

    vue3+vite+ts中不能使用require 之前使用vue2,去动态设置图片src属性时,采用require,但是vue3+vite+ts中使用require,项目能够运行,但浏览器中报错req ...

  5. vue3 vite ts引入vue文件报错 ts(2307)

    vue3 vite ts 生成的项目模板,在ts文件中引入vue文件报错 ts(2307),只是ts报错,并不影响项目运行. 官方文档有说明:http://vue.dragonlm.com/guide ...

  6. 一个基于vue3+vite+ts的完整项目

    VUE VBEN ADMIN2.0 介绍 vue-vben-admin-2.0 是一个全新的开源系统,基于ant-design-vue2.x,typescript4,vue3,vite实现的 vue3 ...

  7. webRtc播放rtsp视频流(vue2、vue3+vite+ts)

    一.下载webRtc 开发环境用的win10版本的. github上直接下载,速度感人. Releases · mpromonet/webrtc-streamer · GitHub 提供资源下载,0积 ...

  8. vue3 + vite + ts + pinia + yarn

    Vue3 + Vite + TypeScript + Pinia + Yarn yarn 常用命令 vite 构建工具 vite 创建项目 Vue 3 vue 3 组件库 vue 文档 组合式 API ...

  9. vue3+vite+ts项目集成科大讯飞语音识别(项目搭建过程以及踩坑记录)

最新文章

  1. 新风系统风速推荐表_家用新风常用管道规格和对应风量推荐值
  2. django1.4 关于处理静态文件的问题
  3. VTK:模型之CappedSphere
  4. TypeScript Type Assertions - 类型断言
  5. Netflix监管者测试–引入了知事-Junit-runner
  6. win7 删除Windows服务的方法
  7. 多线程-ReentrantLock
  8. Linux中的同步机制
  9. Problem C: 爬楼梯
  10. c++ poco 使用mysql中文乱码问题
  11. Python 设计模式-- 命令模式
  12. 人工智能之高等数学2
  13. 010序列检测电路设计
  14. 量子计算到底是个什么鬼?
  15. 【微信小程序】开发入门篇(一)
  16. ARM核心板有哪些不同之处?
  17. 七牛---借助第三方平台实现移动直播
  18. 公路货运、安全如何风险感知?
  19. Hook钩子C#实例
  20. 医疗时鲜资讯:在线问诊可否采用熟人推荐“模式

热门文章

  1. python中str isnumeric_python pandas Series.str.isnumeric用法及代码示例
  2. 计算机内部浮点数表示方法以及计算方式AND计算机内部浮点数加减法运算规则和步骤(包含实例)(32位为例)
  3. 这年头谁还用POI,快来使用国人写的EasyExcel吧,SpringBoot+EasyExcel的快速入门
  4. G-mixup论文阅读
  5. 结对项目-最长单词链总结
  6. 【SpringBoot框架篇】4.集成jta-atomikos实现分布式事务
  7. 产品经理经常遇到的诸多问题(一)
  8. python 撞库_python 脚本撞库国内“某榴”账号
  9. python运维管理系统_运维管理系统方案
  10. java开发之图形界面GUI初步-Swing几种常用组件及其应用