ImageLayerSplit.vue 8.8 KB

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