Vue3项目中集成mars3D简单三部曲

Vue3项目中集成mars3D简单三部曲

这里是参考网址,大佬可以点击一件跳转

1.安装依赖

npm install vite-plugin-mars3d --save-dev

2.修改 vite.config.ts 配置文件

import {
    defineConfig } from 'vite';
import {
    mars3dPlugin } from 'vite-plugin-mars3d';

export default defineConfig({
   
  plugins: [mars3dPlugin()]
});

3. 新建DIV容器 + 创建地图

新建map.ts文件,以下代码闭眼直接copy

import * as mars3d from "mars3d"
import {
    Cesium } from "mars3d"

import "mars3d/dist/mars3d.css";
import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";
//必须有这两行css,否则地球出来了,样式还是乱的
export function initMap() {
   
  // 创建三维地球场景
  const map = new mars3d.Map("mars3dContainer", {
   
    scene: {
   
      center: {
    lat: 30.054604, lng: 108.885436, alt: 17036414, heading: 0, pitch: -90 },
      showSun: true,
      showMoon: true,
      showSkyBox: true,
      showSkyAtmosphere: false, // 关闭球周边的白色轮廓 map.scene.skyAtmosphere = false
      fog: true,
      fxaa: true,
      globe: {
   
        showGroundAtmosphere: false, // 关闭大气(球表面白蒙蒙的效果)
        depthTestAgainstTerrain: false,
        baseColor: "#546a53"
      },
      cameraController: {
   
        zoomFactor: 3.0,
        minimumZoomDistance: 1,
        maximumZoomDistance: 50000000,
        enableRotate: true,
        enableZoom: true
      },
      mapProjection: mars3d.CRS.EPSG3857, // 2D下展示墨卡托投影
      mapMode2D: Cesium.MapMode2D.INFINITE_SCROLL// 2D下左右一直可以滚动重复世界地图
    },
    control: {
   
      baseLayerPicker: false, // basemaps底图切换按钮
      homeButton: false, // 视角复位按钮
      sceneModePicker: false, // 二三维切换按钮
      navigationHelpButton: false, // 帮助按钮
      fullscreenButton: true, // 全屏按钮
      contextmenu: {
    hasDefault: false } // 右键菜单
    },
    terrain: {
   
      url: "//data.mars3d.cn/terrain",
      show: true
    },
    basemaps: [
      {
   
        name: "天地图影像",
        icon: "img/basemaps/tdt_img.png",
        type: "tdt",
        layer: "img_d",
        show: true
      }
    ] as any,
  })

  // 打印测试信息
  console.log("mars3d的Map主对象构造完成", map)
  console.log("其中Cesium原生的Cesium.Viewer为", map.viewer)

  return map
}

vue文件引入map.ts,以下代码闭眼直接copy

<template>
  <div>
    <div id="mars3dContainer" class="mars3d-container"></div> //新建DIV容器
  </div>
</template>

<script setup lang="ts">

import {
    onMounted, ref } from 'vue';
import * as WorkerMap from "./map";
onMounted(async () => {
   
  WorkerMap.initMap();
});
</script>

<style scoped lang="scss">
</style>

在这里插入图片描述

快去试试吧~

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2023-12-15 05:18:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-15 05:18:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-15 05:18:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-15 05:18:01       20 阅读

热门阅读

  1. 学习RPC框架-Thrift日志

    2023-12-15 05:18:01       43 阅读
  2. Retrofit上传文件到oss文件存储

    2023-12-15 05:18:01       36 阅读
  3. SQL区间

    2023-12-15 05:18:01       38 阅读
  4. ClickHouse(17)ClickHouse集成JDBC表引擎详细解析

    2023-12-15 05:18:01       36 阅读
  5. CentOS 7入门指南

    2023-12-15 05:18:01       39 阅读
  6. 使用工具 NVM来管理不同版本的 Node.js启动vue项目

    2023-12-15 05:18:01       37 阅读
  7. 第一周:AI产品经理跳槽准备工作

    2023-12-15 05:18:01       41 阅读
  8. 【Qt5】Qt Creator中CMake的qt5_wrap_ui函数

    2023-12-15 05:18:01       27 阅读