vue集成mars3d后,basemaps加不上去

首先:

<template>

  <div id="centerDiv" class="mapcontainer">

    <mars-map :url="configUrl" @οnlοad="onMapload" />

  </div>

</template>

<script>

import MarsMap from '../components/mars-work/mars-map.vue'

import * as mars3d from 'mars3d'

//npm install mars3d-echarts --save

import 'mars3d-echarts'

const Cesium = mars3d.Cesium

export default {

  // eslint-disable-next-line vue/multi-word-component-names

  name: 'Index',

  components: {

    MarsMap

  },

  data() {

    const basePathUrl = window.basePathUrl || ''

    return {

      configUrl: basePathUrl + 'config/config.json'

    }

  },

  methods: {

    // 地图构造完成回调

    onMapload(map) {

      // 以下为演示代码

      map.setCameraView({ lat: 30.617828, lng: 116.294045, alt: 44160, heading: 357, pitch: -59 })

      // 创建entity图层

      const graphicLayer = new mars3d.layer.GraphicLayer()

      map.addLayer(graphicLayer)

      const tiles3dLayer = new mars3d.layer.TilesetLayer({

        url: '//data.mars3d.cn/3dtiles/bim-qiaoliang/tileset.json',

        maximumScreenSpaceError: 16,

        position: { lng: 117.096906, lat: 31.851564, alt: 45 },

        rotation: { z: 17.5 },

        flyTo: true

      })

      map.addLayer(tiles3dLayer)

      const poiQueryButton = new PoiQueryButton({

        insertIndex: 0 // 插入的位置顺序

      })

      map.addControl(poiQueryButton)

      // 2.在layer上绑定监听事件

      graphicLayer.on(this.mars3d.EventType.click, function (event) {

        console.log('监听layer,单击了矢量对象', event)

      })

      graphicLayer.on(this.mars3d.EventType.mouseOver, function (event) {

        console.log('监听layer,鼠标移入了矢量对象', event)

      })

      graphicLayer.on(this.mars3d.EventType.mouseOut, function (event) {

        console.log('监听layer,鼠标移出了矢量对象', event)

      })

      // 可在图层上绑定popup,对所有加到这个图层的矢量数据都生效

      graphicLayer.bindPopup('我是layer上绑定的Popup', {

        anchor: [0, -10]

      })

      // 可在图层绑定右键菜单,对所有加到这个图层的矢量数据都生效

      graphicLayer.bindContextMenu([

        {

          text: '删除对象',

          iconCls: 'fa fa-trash-o',

          callback: function (e) {

            const graphic = e.graphic

            if (graphic) {

              graphicLayer.removeGraphic(graphic)

            }

          }

        }

      ])

    },

    addDemoGraphic1: (graphicLayer) => {

      const graphic = new mars3d.graphic.LabelEntity({

        position: new mars3d.LngLatPoint(116.1, 31.0, 1000),

        style: {

          text: '火星科技Mars3D平台',

          font_size: 25,

          font_family: '楷体',

          color: '#003da6',

          outline: true,

          outlineColor: '#bfbfbf',

          outlineWidth: 2,

          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,

          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

          visibleDepth: false

        },

        attr: { remark: '示例1' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic2: (graphicLayer) => {

      const graphic = new mars3d.graphic.PointEntity({

        position: [116.2, 31.0, 1000],

        style: {

          color: '#ff0000',

          pixelSize: 10,

          outline: true,

          outlineColor: '#ffffff',

          outlineWidth: 2

        },

        attr: { remark: '示例2' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic3: (graphicLayer) => {

      const graphic = new mars3d.graphic.BillboardEntity({

        name: '贴地图标',

        position: [116.3, 31.0, 1000],

        style: {

          image: 'img/marker/mark-blue.png',

          scale: 1,

          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,

          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

          clampToGround: true

        },

        attr: { remark: '示例3' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic4: (graphicLayer) => {

      const graphic = new mars3d.graphic.PlaneEntity({

        position: new mars3d.LngLatPoint(116.4, 31.0, 1000),

        style: {

          plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, 0.0),

          dimensions: new Cesium.Cartesian2(4000.0, 4000.0),

          materialType: mars3d.MaterialType.Image2,

          materialOptions: {

            image: 'img/textures/poly-rivers.png',

            transparent: true

          }

        },

        attr: { remark: '示例4' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic5: (graphicLayer) => {

      const graphic = new mars3d.graphic.BoxEntity({

        position: new mars3d.LngLatPoint(116.5, 31.0, 1000),

        style: {

          dimensions: new Cesium.Cartesian3(2000.0, 2000.0, 2000.0),

          fill: true,

          color: '#00ffff',

          opacity: 0.9,

          heading: 45,

          roll: 45,

          pitch: 0

        },

        attr: { remark: '示例5' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic6: (graphicLayer) => {

      const graphic = new mars3d.graphic.CircleEntity({

        position: [116.1, 30.9, 1000],

        style: {

          radius: 1800.0,

          color: '#00ff00',

          opacity: 0.3,

          outline: true,

          outlineWidth: 3,

          outlineColor: '#ffffff',

          clampToGround: true

        },

        popup: '直接传参的popup',

        attr: { remark: '示例6' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic7: (graphicLayer) => {

      const graphic = new mars3d.graphic.CylinderEntity({

        position: [116.2, 30.9, 1000],

        style: {

          length: 3000.0,

          topRadius: 0.0,

          bottomRadius: 1300.0,

          color: '#00FFFF',

          opacity: 0.7

        },

        popup: '直接传参的popup',

        attr: { remark: '示例7' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic8: (graphicLayer) => {

      const graphic = new mars3d.graphic.EllipsoidEntity({

        position: new mars3d.LngLatPoint(116.3, 30.9, 1000),

        style: {

          radii: new Cesium.Cartesian3(1500.0, 1500.0, 1500.0),

          color: 'rgba(255,0,0,0.5)',

          outline: true,

          outlineColor: 'rgba(255,255,255,0.3)'

        },

        attr: { remark: '示例8' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic9: (graphicLayer) => {

      const graphic = new mars3d.graphic.ModelEntity({

        name: '消防员',

        position: [116.4, 30.9, 1000],

        style: {

          url: '//data.mars3d.cn/gltf/mars/firedrill/xiaofangyuan-run.gltf',

          scale: 16,

          minimumPixelSize: 100

        },

        attr: { remark: '示例9' }

      })

      graphicLayer.addGraphic(graphic)

    },

    addDemoGraphic10: (graphicLayer) => {

      const graphic = new mars3d.graphic.PolylineEntity({

        positions: [

          [116.5, 30.9, 1000],

          [116.52, 30.91, 1000],

          [116.53, 30.89, 1000]

        ],

        style: {

          width: 5,

          color: '#3388ff'

        },

        attr: { remark: '示例10' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    },

    addDemoGraphic11: (graphicLayer) => {

      const graphic = new mars3d.graphic.PolylineVolumeEntity({

        positions: [

          [116.1, 30.8, 1000],

          [116.12, 30.81, 1000],

          [116.13, 30.79, 1000]

        ],

        style: {

          shape: 'pipeline',

          radius: 80,

          color: '#3388ff',

          opacity: 0.9

        },

        attr: { remark: '示例11' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    },

    addDemoGraphic12: (graphicLayer) => {

      const graphic = new mars3d.graphic.CorridorEntity({

        positions: [

          [116.2, 30.8, 1000],

          [116.22, 30.81, 1000],

          [116.23, 30.79, 1000],

          [116.247328, 30.806077, 610.41]

        ],

        style: {

          width: 500,

          color: '#3388ff'

        },

        attr: { remark: '示例12' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    },

    addDemoGraphic13: (graphicLayer) => {

      const graphic = new mars3d.graphic.WallEntity({

        positions: [

          [116.3, 30.8, 1000],

          [116.31, 30.81, 1000],

          [116.334639, 30.800735, 721.39],

          [116.32, 30.79, 1000]

        ],

        style: {

          closure: true,

          diffHeight: 500,

          // 动画线材质

          materialType: mars3d.MaterialType.LineFlow,

          materialOptions: {

            image: 'img/textures/fence.png',

            color: '#00ff00',

            speed: 10,

            axisY: true

          }

        },

        attr: { remark: '示例13' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    },

    addDemoGraphic14: (graphicLayer) => {

      const graphic = new mars3d.graphic.RectangleEntity({

        positions: [

          [116.383144, 30.819978, 444.42],

          [116.42216, 30.793431, 1048.07]

        ],

        style: {

          color: '#3388ff',

          opacity: 0.5,

          outline: true,

          outlineWidth: 3,

          outlineColor: '#ffffff'

        },

        attr: { remark: '示例14' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    },

    addDemoGraphic15: (graphicLayer) => {

      const graphic = new mars3d.graphic.PolygonEntity({

        positions: [

          [116.510278, 30.834372, 567.29],

          [116.530085, 30.809331, 448.31],

          [116.507367, 30.788551, 98.21],

          [116.472468, 30.823091, 677.39]

        ],

        style: {

          materialType: mars3d.MaterialType.Water,

          materialOptions: {

            normalMap: 'img/textures/waterNormals.jpg', // 水正常扰动的法线图

            frequency: 8000.0, // 控制波数的数字。

            animationSpeed: 0.02, // 控制水的动画速度的数字。

            amplitude: 5.0, // 控制水波振幅的数字。

            specularIntensity: 0.8, // 控制镜面反射强度的数字。

            baseWaterColor: '#006ab4', // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4

            blendColor: '#006ab4' // 从水中混合到非水域时使用的rgba颜色对象。

          }

        },

        attr: { remark: '示例15' }

      })

      graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)

    }

  }

}

</script>

<style>

.mapcontainer {

  position: relative;

  height: 100%;

  overflow: hidden;

}

</style>

其次:

<template>

  <div :id="`mars3d-container${mapKey}`" class="mars3d-container"></div>

</template>

<script>

import Vue from "vue";

// 使用免费开源版本

// import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";

// import "mars3d/dist/mars3d.css";

// import * as mars3d from "mars3d";

// const Cesium = mars3d.Cesium;

// let mars3d = window.mars3d;

// 导入插件(其他插件类似,插件清单访问:http://mars3d.cn/dev/guide/start/architecture.html)

// echarts插件

// import 'mars3d-echarts'

// 为了方便使用,绑定到原型链,在其他vue文件,直接 this.mars3d 来使用

// Vue.prototype.mars3d = mars3d

// Vue.prototype.Cesium = mars3d.Cesium

export default {

  name: "mars3dViewer",

  props: {

    // 地图唯一性标识

    mapKey: {

      type: String,

      default: "",

    },

    // 初始化配置config.json的地址

    url: String,

    // 自定义参数

    options: Object,

  },

  mounted() {

    window.mars3d.Resource.fetchJson({ url: this.url }).then((data) => {

      // 构建地图

      this.initMars3d({

        ...data.map3d,

        ...this.options,

      });

    });

  },

  beforeDestroy() {

    const map = this[`map${this.mapKey}`];

    if (map) {

      map.destroy();

      delete this[`map${this.mapKey}`];

    }

    console.log(">>>>> 地图卸载完成 >>>>");

  },

  methods: {

    initMars3d(mapOptions) {

      console.log(mapOptions);

      // if (this[`map${this.mapKey}`]) {

      //   this[`map${this.mapKey}`].destroy();

      // }

      // 创建三维地球场景

      var map = new window.mars3d.Map(

        `mars3d-container${this.mapKey}`,

        mapOptions

      );

      this[`map${this.mapKey}`] = map;

      console.log(">>>>> 地图创建成功 >>>>", map);

      // 挂载到全局对象下,所有组件通过 this.map 访问

      // Vue.prototype[`map${this.mapKey}`] = map

      // 绑定对alert的处理,右键弹出信息更美观。

      // window.haoutil = window.haoutil || {}

      // window.haoutil.msg = (msg) => {

      //   this.$message.success(msg)

      // }

      // window.haoutil.alert = (msg) => {

      //   this.$message.success(msg)

      // }

      // 抛出事件

      this.$emit("onload", map);

    },

  },

};

</script>

<style>

.mars3d-container {

  height: 100%;

  overflow: hidden;

}

/**cesium 工具按钮栏*/

.cesium-viewer-toolbar {

  top: auto !important;

  bottom: 35px !important;

  left: 12px !important;

  right: auto !important;

}

.cesium-toolbar-button img {

  height: 100%;

}

.cesium-viewer-toolbar > .cesium-toolbar-button,

.cesium-navigationHelpButton-wrapper,

.cesium-viewer-geocoderContainer {

  margin-bottom: 5px;

  float: left;

  clear: both;

  text-align: center;

}

.cesium-button {

  background-color: #3f4854;

  color: #e6e6e6;

  fill: #e6e6e6;

  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);

  line-height: 32px;

}

/**cesium 底图切换面板*/

.cesium-baseLayerPicker-dropDown {

  bottom: 0;

  left: 40px;

  max-height: 700px;

  margin-bottom: 5px;

}

/**cesium 帮助面板*/

.cesium-navigation-help {

  top: auto;

  bottom: 0;

  left: 40px;

  transform-origin: left bottom;

}

/**cesium 二维三维切换*/

.cesium-sceneModePicker-wrapper {

  width: auto;

}

.cesium-sceneModePicker-wrapper .cesium-sceneModePicker-dropDown-icon {

  float: right;

  margin: 0 3px;

}

/**cesium POI查询输入框*/

.cesium-viewer-geocoderContainer .search-results {

  left: 0;

  right: 40px;

  width: auto;

  z-index: 9999;

}

.cesium-geocoder-searchButton {

  background-color: #3f4854;

}

.cesium-viewer-geocoderContainer .cesium-geocoder-input {

  background-color: rgba(63, 72, 84, 0.7);

}

.cesium-viewer-geocoderContainer .cesium-geocoder-input:focus {

  background-color: rgba(63, 72, 84, 0.9);

}

.cesium-viewer-geocoderContainer .search-results {

  background-color: #3f4854;

}

/**cesium info信息框*/

.cesium-infoBox {

  top: 50px;

  background: rgba(63, 72, 84, 0.9);

}

.cesium-infoBox-title {

  background-color: #3f4854;

}

/**cesium 任务栏的FPS信息*/

.cesium-performanceDisplay-defaultContainer {

  top: auto;

  bottom: 35px;

  right: 50px;

}

.cesium-performanceDisplay-ms,

.cesium-performanceDisplay-fps {

  color: #fff;

}

/**cesium tileset调试信息面板*/

.cesium-viewer-cesiumInspectorContainer {

  top: 10px;

  left: 10px;

  right: auto;

  background-color: #3f4854;

}

</style>

问题的原因是:

服务有返回东西,使用的就是示例中的配置;数据正常返回了,mock拦截机制的原因,自行处理把mock注释掉就解决了。

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/101048.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Golang:微服务常用代码分层结构

1.代码结构 代码分层结构是一个老生常谈的话题&#xff0c;好的代码结构能够使得系统易于理解、开发及维护&#xff0c;如果代码结构很混乱就会使得不同层级的代码块耦合&#xff0c;导致难以维护和拓展。 比较经典的代码结构&#xff08;宏观&#xff09;有Web的MVC模式分层结…

Spring Cloud Foundry上使用通配符模式匹配进行的安全绕过漏洞 CVE-2023-20873

文章目录 0.前言1.参考文档2.基础介绍描述如果满足以下任一条件&#xff0c;应用程序就不会有太大风险&#xff1a;受影响的Spring产品和版本 3.解决方案3.1. 升级版本3.2. 替代方案 0.前言 背景&#xff1a;公司项目扫描到 Spring Cloud Foundry上使用通配符模式匹配进行的安全…

tp5使用redis及redis7.2安装到window系统上面

redis安装教程 redis7.2安装到window系统上面 https://download.csdn.net/download/qq_39161501/88269037 解决方案&#xff1a;修改配置php.ini文件 打开Apache目录下的php.ini文件&#xff0c;搜索extension&#xff0c;在空白处加上下列代码&#xff1a; 注&#xff1a;e…

2019CVPR Semantic Graph Convolutional Networks for 3D Human Pose Regression

基于语义图卷积网络的三维人体姿态回归 源码 https://github.com/garyzhao/SemGCN 摘要 在本文中&#xff0c;我们研究了学习图卷积网络&#xff08;GCN&#xff09;回归的问题。GCN的当前体系结构受限于卷积滤波器和共享的变换矩阵为的小感受野。为了解决这些限制&#xff…

并发 04(Callable,CountDownLatch)详细讲解

并发 Callable 1 可以返回值 2可以抛出异常 泛型指的是返回值的类型 public class Send {public static void main(String[] args) {//怎么启动Callable//new Thread().start();Aaa threadnew Aaa();FutureTask futureTasknew FutureTask(thread);new Thread(futureTask,&qu…

划分字母区间【贪心算法】

划分字母区间 给你一个字符串 s 。我们要把这个字符串划分为尽可能多的片段&#xff0c;同一字母最多出现在一个片段中。 注意&#xff0c;划分结果需要满足&#xff1a;将所有划分结果按顺序连接&#xff0c;得到的字符串仍然是 s 。返回一个表示每个字符串片段的长度的列表。…

深度学习6:自然语言处理-Natural language processing | NLP

目录 NLP 为什么重要&#xff1f; 什么是自然语言处理 – NLP NLP 的2大核心任务 自然语言理解 – NLU|NLI 自然语言生成 – NLG NLP(自然语言处理) 的5个难点 NLP 的4个典型应用 NLP 的 2 种途径、3 个核心步骤 总结 自然语言处理 NLP 为什么重要&#xff1f; “语言…

Unity3D下如何采集camera场景数据并推送RTMP服务?

Unity3D使用场景 Unity3D是非常流行的游戏开发引擎&#xff0c;可以创建各种类型的3D和2D游戏或其他互动应用程序。常见使用场景如下&#xff1a; 游戏开发&#xff1a;Unity3D是一个广泛用于游戏开发的环境&#xff0c;适用于创建各种类型的游戏&#xff0c;包括动作游戏、角…

汽车电子笔记之:基于AUTOSAR的多核监控机制

目录 1、概述 2、系统监控的目标 2.1、任务的状态机 2.2、任务服务函数 2.3、任务周期性事件 2.4、时间监控的指标 2.5、时间监控的原理 2.6、CPU负载率监控原理 2.6.1、设计思路 2.6.2、监控方法的评价 3、基于WDGM模块热舞时序监控方法 3.1、活跃监督 3.2、截至时…

wireshark 流量抓包例题

一、题目一(1.pcap) 题目要求&#xff1a; 1.黑客攻击的第一个受害主机的网卡IP地址 2.黑客对URL的哪一个参数实施了SQL注入 3.第一个受害主机网站数据库的表前缀&#xff08;加上下划线例如abc&#xff09; 4.第一个受害主机网站数据库的名字 看到题目SQL注入&#xff0c…

Modbus通信协议

Modbus通信协议 一、概述 Modbus通信协议是一种工业现场总线协议标准&#xff0c;常用的Modbus协议有以下三种类型&#xff1a;Modbus TCP、Modbus RTU、Modbus ASCll。 Modbus通信协议解决了通过串行线路在电子设备之间发送信息的问题。该协议在遵循该协议的体系结构中实现主…

CSAPP的Lab学习——BombLab

文章目录 前言一、一号炸弹&#xff08;小试牛刀&#xff09;二、二号炸弹&#xff08;六重循环&#xff09;三、三号炸弹&#xff08;不同输入&#xff0c;不同答案&#xff09;四、四号炸弹&#xff08;判断语句的实现&#xff09;五、五号炸弹&#xff08;跳转&#xff0c;循…

【MTK平台】根据kernel log分析wifi scan的时候流程

一 概要: 本文主要讲解根据kernel log分析下 当前路径下(vendor/mediatek/kernel_modules/connectivity/wlan/core/gen4m/)wifi scan的时候代码流程 二. Log分析: 先看Log: 2.1)在Framework层WifiManager.java 方法中,做了一个标记,可以精准的确认时间 这段log可以…

探索UniApp分包

目录 什么是UniApp分包&#xff1f; UniApp分包的原理 优势 如何使用UniApp分包 1.manifest.json文件配置 2.静态图片资源分包注意事项 3.pages.json配置 结论 探索UniApp分包&#xff1a;优化移动应用性能与用户体验 在移动应用开发领域&#xff0c;性能和用户体验是至…

【vue2第七章】vue的四个生命周期与八个钩子函数

vue的四个生命周期与八个钩子函数 Vue的四个生命周期有&#xff1a;创建&#xff08;creation&#xff09;、挂载&#xff08;mounting&#xff09;、更新&#xff08;updating&#xff09;和销毁&#xff08;destroying&#xff09;。 钩子函数是什么&#xff1a; vue生命周…

vue3下的密码输入框(antdesignvue)

参考:vue下的密码输入框 注意:这是个半成品,有些问题(input输入框加了文字间距letter-spaceing,会导致输入到第6位的时候会往后窜出来一个空白框、光标位置页会在数字前面),建议不采用下面这种方式,用另外的(画六个input框更方便) 效果预览 实现思路 制作6个小的正方…

Linux中Tomcat发布war包后无法正常访问非静态资源

事故现象 在CentOS8中安装完WEB环境&#xff0c;首次部署WEB项目DEMO案例&#xff0c;发现可以静态的网页内容&#xff0c; 但是无法向后台发送异步请求&#xff0c;全部出现404问题&#xff0c;导致数据库数据无法渲染到界面上。 原因分析 CentOS请求中提示用来获取资源的连…

Prometheus监控(一)

文章目录 监控对于企业和运维工作的重要性监控&#xff1f;告警&#xff1f;数据采集 Prometheus介绍Prometheus相对于老牌监控的优势和不足 理想的监控系统的实现监控系统设计&#xff08;架构师&#xff09;监控系统的搭建数据采集的编写监控数据分析和算法稳定性测试监控自动…

IPC进程间通信及示例代码

一. 什么是进程通信 进程通信&#xff08; InterProcess Communication&#xff0c;IPC&#xff09;就是指进程之间的信息交换。实际上&#xff0c;进程的同步与互斥本质上也是一种进程通信&#xff08;这也就是待会我们会在进程通信机制中看见信号量和 PV 操作的原因了&#x…

什么?内存爆了?详细解读虚拟内存机制

不知道大家在运行自己写的程序时&#xff0c;有没有发现一个问题&#xff1a;就是物理机器明明只有8G内存&#xff0c;但是我们运行的程序却可以申请到16G的内存&#xff1f;或者说机器上运行的多个进程&#xff0c;占用的总内存已经远超物理内存了&#xff0c;却还能正常工作。…
最新文章