map-split.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <script setup>
  2. import {
  3. Store
  4. } from '@/store/index'
  5. store = Store();
  6. import {
  7. deepTree
  8. } from "@/utils/deepTree.js";
  9. </script>
  10. <template>
  11. <jt-popup title="卷帘对比" :showfooter="isshowfooter" height="120rem" width="620rem" :isEmit="true" @closeJTPopup="closeJTPopup">
  12. <div class="jt-map-split">
  13. <div class="_left">
  14. <div style="line-height: 30rem;float: left;">左侧图层:</div>
  15. <el-tree-select v-model="leftModel" :data="leftData" :render-after-expand="true" @change="handleClickLeft" style="width: 200rem; float: left;" />
  16. </div>
  17. <div class="_right">
  18. <div style="line-height: 30rem;float: left;">右侧图层:</div>
  19. <el-tree-select v-model="rightModel" :data="rightData" :render-after-expand="true" @change="handleClickRight" style="width: 200rem; float: left;" />
  20. </div>
  21. </div>
  22. </jt-popup>
  23. </template>
  24. <script>
  25. let store = undefined;
  26. let earthAtLeft = undefined;
  27. let earthAtRight = undefined;
  28. import * as mapWork from "../map"
  29. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  30. //例如:import 《组件名称》 from '《组件路径》';
  31. export default {
  32. //import引入的组件需要注入到对象中才能使用
  33. components: {},
  34. //这里存放数据
  35. data() {
  36. return {
  37. leftModel: {},
  38. leftData: [],
  39. leftValue: [],
  40. rightModel: {},
  41. rightData: [],
  42. rightValue: [],
  43. };
  44. },
  45. //监听属性 类似于data概念
  46. computed: {},
  47. //监控data中的数据变化
  48. watch: {},
  49. //方法集合
  50. methods: {
  51. /**
  52. * 左侧图层控制
  53. * @param {Object} item
  54. */
  55. handleClickLeft(item) {
  56. let _self = this;
  57. //移除
  58. if (earthAtLeft) {
  59. mapWork.setLayersControl(window.viewer, _self.leftValue, false);
  60. }
  61. //添加
  62. mapWork.setLayersControl(window.viewer, item, true).then(res => {
  63. //定位
  64. mapWork.setLayersLocation(window.viewer, {
  65. serviceId: item.serviceId,
  66. parameterset: item.parameterset,
  67. loadtype: item.loadtype,
  68. isinit: '1',
  69. });
  70. _self.leftValue = item;
  71. earthAtLeft = window[item.serviceId];
  72. earthAtLeft.splitDirection = Cesium.SplitDirection.LEFT;
  73. });
  74. },
  75. /**
  76. *
  77. *
  78. * 右侧图层控制
  79. * @param {Object} item
  80. */
  81. handleClickRight(item) {
  82. let _self = this;
  83. //移除
  84. if (earthAtRight) {
  85. mapWork.setLayersControl(window.viewer, _self.rightValue, false);
  86. }
  87. //添加
  88. mapWork.setLayersControl(window.viewer, item, true).then(res => {
  89. //定位
  90. mapWork.setLayersLocation(window.viewer, {
  91. serviceId: item.serviceId,
  92. parameterset: item.parameterset,
  93. loadtype: item.loadtype,
  94. isinit: '1',
  95. });
  96. _self.rightValue = item;
  97. earthAtRight = window[item.serviceId];
  98. earthAtRight.splitDirection = Cesium.SplitDirection.RIGHT;
  99. });
  100. },
  101. /**
  102. * 卷帘对比初始化
  103. */
  104. initSplitLayer() {
  105. let _self = this;
  106. this.viewer = window.viewer;
  107. let sliderDiv = document.getElementById("image_slider");
  108. if (sliderDiv == null) {
  109. //创建画布
  110. sliderDiv = document.createElement('div');
  111. sliderDiv.id = "image_slider";
  112. sliderDiv.style.position = "absolute";
  113. sliderDiv.style.left = "50%";
  114. sliderDiv.style.top = "70rem";
  115. sliderDiv.style.backgroundColor = "#d3d3d3";
  116. sliderDiv.style.width = "5rem";
  117. sliderDiv.style.height = "calc(100% - 70rem)";
  118. sliderDiv.style.zIndex = "9999";
  119. sliderDiv.onmouseover = function() {
  120. //设置其背景颜色为黄色
  121. this.style.cursor = "ew-resize";
  122. };
  123. /* 加入到页面 */
  124. document.body.appendChild(sliderDiv);
  125. }
  126. // 设置图像拆分位置
  127. this.viewer.scene.splitPosition = sliderDiv.offsetLeft / sliderDiv.parentElement.offsetWidth; //确定分割点位置,占据父级容器的比例
  128. if (this.handler) {
  129. this.handler.destroy();
  130. this.handler = null;
  131. }
  132. //处理用户输入事件。可以添加自定义功能以在用户输入时执行;参数为任意
  133. this.handler = new Cesium.ScreenSpaceEventHandler(sliderDiv);
  134. var moveActive = false;
  135. // 计算拆分
  136. function move(movement) {
  137. if (!moveActive) {
  138. return;
  139. }
  140. //捕获滑动停止的位置
  141. var relativeOffset = movement.endPosition.x;
  142. var splitPosition = (sliderDiv.offsetLeft + relativeOffset) / sliderDiv.parentElement.offsetWidth;
  143. sliderDiv.style.left = `${100.0 * splitPosition}%`;
  144. viewer.scene.splitPosition = splitPosition;
  145. }
  146. //对分割条的操作
  147. this.handler.setInputAction(function() {
  148. moveActive = true;
  149. }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
  150. this.handler.setInputAction(function() {
  151. moveActive = true;
  152. }, Cesium.ScreenSpaceEventType.PINCH_START);
  153. this.handler.setInputAction(move, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
  154. this.handler.setInputAction(move, Cesium.ScreenSpaceEventType.PINCH_MOVE);
  155. this.handler.setInputAction(function() {
  156. moveActive = false;
  157. }, Cesium.ScreenSpaceEventType.LEFT_UP);
  158. this.handler.setInputAction(function() {
  159. moveActive = false;
  160. }, Cesium.ScreenSpaceEventType.PINCH_END);
  161. _self.handleClickLeft(_self.leftModel);
  162. _self.handleClickRight(_self.rightModel);
  163. },
  164. /**
  165. * 初始化图层控制树
  166. */
  167. initLayerTree() {
  168. let _self = this;
  169. mapWork.getLayers().then(layers => {
  170. layers.map((item) => {
  171. let num = Number(item.layerorder)
  172. if (num < 10) {
  173. item.layerorder = '0' + item.layerorder
  174. }
  175. //图层ID
  176. let serviceId = "service_" + item.layercode + item.layerorder;
  177. item.serviceId = serviceId;
  178. //透明度
  179. let opacity = 1;
  180. if (item.opacity == null) {
  181. opacity = 1;
  182. } else {
  183. opacity = Number(item.opacity);
  184. }
  185. item.opacity = opacity;
  186. item.value = item;
  187. item.label = item.layername;
  188. if (item.layername === "二调") {
  189. _self.leftModel = item;
  190. }
  191. if (item.layername === "三调") {
  192. _self.rightModel = item;
  193. }
  194. })
  195. _self.leftData = _self.rightData = deepTree(layers)
  196. _self.initSplitLayer();
  197. });
  198. },
  199. /**
  200. * 移除卷帘
  201. */
  202. removeSplitLayer() {
  203. let sliderDiv = document.getElementById("image_slider");
  204. if (sliderDiv) {
  205. document.body.removeChild(sliderDiv);
  206. }
  207. if (earthAtLeft) {
  208. mapWork.setLayersControl(window.viewer, this.leftValue, false);
  209. earthAtLeft.splitDirection = Cesium.SplitDirection.NONE;
  210. }
  211. if (earthAtRight) {
  212. mapWork.setLayersControl(window.viewer, this.rightValue, false);
  213. earthAtRight.splitDirection = Cesium.SplitDirection.NONE;
  214. }
  215. },
  216. closeJTPopup() {
  217. if (window.viewerLeft) {
  218. mapWork.removeSplitScreen(window.viewerLeft);
  219. }
  220. // mapWork.removeSplitLayer(window.viewer, earthAtLeft, earthAtRight,_self.leftValue,_self.rightValue);
  221. this.removeSplitLayer();
  222. }
  223. },
  224. //生命周期 - 创建完成(可以访问当前this实例)
  225. created() {},
  226. //生命周期 - 挂载完成(可以访问DOM元素)
  227. mounted() {
  228. this.initLayerTree();
  229. },
  230. beforeCreate() {}, //生命周期 - 创建之前
  231. beforeMount() {}, //生命周期 - 挂载之前
  232. beforeUpdate() {}, //生命周期 - 更新之前
  233. updated() {}, //生命周期 - 更新之后
  234. beforeDestroy() {}, //生命周期 - 销毁之前
  235. destroyed() {}, //生命周期 - 销毁完成
  236. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. //整体样式
  241. .jt-map-split {
  242. // padding: 10rem;
  243. //左侧
  244. ._left {
  245. width: 300rem;
  246. float: left;
  247. }
  248. //右侧
  249. ._right {
  250. width: 300rem;
  251. float: left;
  252. margin-left: 10rem;
  253. }
  254. .el-tree {
  255. width: 300rem !important;
  256. }
  257. }
  258. </style>