Map.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <!-- <div class='Map' @click="cutVr('fd720_WoDGV0K2r',13)"> -->
  3. <div class="Map">
  4. <div id="mars3dContainer" class="mars3d-container"></div>
  5. </div>
  6. </template>
  7. <script>
  8. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  9. //例如:import 《组件名称》 from '《组件路径》';
  10. //引入cesium基础库
  11. // import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";
  12. // import * as Cesium from "mars3d-cesium";
  13. //导入mars3d主库
  14. import "mars3d/dist/mars3d.css";
  15. import * as mars3d from "mars3d";
  16. export default {
  17. //import引入的组件需要注入到对象中才能使用
  18. components: {},
  19. data() {
  20. //这里存放数据
  21. return {
  22. // 地图实例
  23. // map: null,
  24. };
  25. },
  26. //监听属性 类似于data概念
  27. computed: {},
  28. //监控data中的数据变化
  29. watch: {},
  30. //方法集合
  31. methods: {
  32. // 初始化地图
  33. async initMap() {
  34. // 读取 config.json 配置文件
  35. const json = await mars3d.Util.fetchJson({ url: "config/config.json" });
  36. console.log("读取 config.json 配置文件完成", json); // 打印测试信息
  37. // 创建三维地球场景
  38. const mapOptions = json.map3d;
  39. let map = new mars3d.Map("mars3dContainer", mapOptions);
  40. // 打印测试信息
  41. // console.log("mars3d的Map主对象构造完成", this.map);
  42. // console.log("其中Cesium原生的Cesium.Viewer为", this.map.viewer);
  43. return map;
  44. },
  45. // 倾斜模型加载
  46. loadModel(_map) {
  47. const modelLayer = new mars3d.layer.TilesetLayer({
  48. name: "雨花台模型",
  49. url: "https://testgis.4dage.com/yuhuatai1021-qp/tileset.json",
  50. maximumMemoryUsage: 2048,
  51. position: { alt: -290 },
  52. preloadFlightDestinations: true,
  53. flyTo: false,
  54. });
  55. _map.addLayer(modelLayer);
  56. },
  57. drawLabel(_layer) {
  58. const graphic = new mars3d.graphic.DivGraphic({
  59. position: [118.775298, 31.999126, 80.5],
  60. style: {
  61. html: `<div
  62. style="
  63. width: 316px;
  64. height: 174px;
  65. display: flex;
  66. justify-content: center;
  67. align-items: flex-start;
  68. cursor:pointer;
  69. "
  70. >
  71. <div
  72. style="
  73. position: absolute;
  74. margin-left: 25px;
  75. width: 190px;
  76. height: 70px;
  77. line-height: 70px;
  78. text-align: center;
  79. color: #fff;
  80. font-size: 20px;
  81. font-weight: bold;
  82. "
  83. >
  84. 雨花台烈士纪念馆
  85. </div>
  86. <div><img src="/YHT/Qjkk/MapBs.png"/></div>
  87. </div>`,
  88. horizontalOrigin: mars3d.Cesium.HorizontalOrigin.CENTER,
  89. verticalOrigin: mars3d.Cesium.VerticalOrigin.BOTTOM,
  90. // distanceDisplayCondition: new mars3d.Cesium.DistanceDisplayCondition(0, 30000), // 按视距距离显示
  91. // scaleByDistance: new mars3d.Cesium.NearFarScalar(100, 1, 1000, 0.5),
  92. scale: 0.1,
  93. clampToGround: false,
  94. },
  95. });
  96. graphic.on(mars3d.EventType.click, () => {
  97. this.cutVr("fd720_WoDGV0K2r", 13);
  98. });
  99. _layer.addGraphic(graphic);
  100. },
  101. cutVr(code, index) {
  102. this.$emit("mapCutVr", code, index);
  103. },
  104. },
  105. //生命周期 - 创建完成(可以访问当前this实例)
  106. created() {},
  107. //生命周期 - 挂载完成(可以访问DOM元素)
  108. mounted() {
  109. // 初始化地图实例
  110. this.initMap().then(
  111. (map) => {
  112. // 加载模型
  113. this.loadModel(map);
  114. // 加载标签
  115. let graphicLayer = new mars3d.layer.GraphicLayer();
  116. map.addLayer(graphicLayer);
  117. this.drawLabel(graphicLayer);
  118. map.setCameraView({
  119. lat: 31.99314,
  120. lng: 118.776577,
  121. alt: 656,
  122. heading: 350,
  123. pitch: -43,
  124. });
  125. },
  126. (error) => {
  127. console.log("地图初始化失败", error);
  128. }
  129. );
  130. },
  131. beforeCreate() {}, //生命周期 - 创建之前
  132. beforeMount() {}, //生命周期 - 挂载之前
  133. beforeUpdate() {}, //生命周期 - 更新之前
  134. updated() {}, //生命周期 - 更新之后
  135. beforeDestroy() {}, //生命周期 - 销毁之前
  136. destroyed() {}, //生命周期 - 销毁完成
  137. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  138. };
  139. </script>
  140. <style lang='less' scoped>
  141. .Map {
  142. position: absolute;
  143. top: 0;
  144. left: 0;
  145. z-index: 98;
  146. width: 100%;
  147. height: 100%;
  148. // background-color: aqua;
  149. }
  150. #mars3dContainer {
  151. width: 100%;
  152. height: 100%;
  153. position: absolute;
  154. top: 0px;
  155. left: 0px;
  156. }
  157. /deep/.mars3d-locationbar {
  158. background-color: #000 !important;
  159. z-index: 0 !important;
  160. }
  161. </style>