BasemapChange.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <transition-group name="map-change" tag="div">
  3. <div
  4. key="map-change"
  5. class="map-change"
  6. :style="{
  7. right: `${rightPosition}%`,
  8. bottom: `${bottomPostion}px`,
  9. }"
  10. @mouseover="mouseover"
  11. @mouseleave="mouseleave"
  12. >
  13. <!-- 注意key值不能使用数组索引 否则无变化 -->
  14. <img
  15. v-for="(item, index) in state.images"
  16. :key="item.type"
  17. :src="item.src"
  18. class="img__box"
  19. :class="{ active: index === 0 }"
  20. :style="{
  21. right: `${index * state.rightPX}px`,
  22. 'z-index': 99 - index,
  23. }"
  24. @click="change(index, item.type)"
  25. />
  26. </div>
  27. </transition-group>
  28. </template>
  29. <script>
  30. export default {
  31. name: "BasemapChange",
  32. data() {
  33. return {
  34. rightPosition: 23,
  35. bottomPostion: 30,
  36. imageGroup: {
  37. // 地形图
  38. DX: require("@/assets/map/02.png"),
  39. // 深色地图
  40. SE: require("@/assets/map/03.png"),
  41. // 街道底图
  42. JD: require("@/assets/map/01.png"),
  43. },
  44. state: {
  45. // 图片数组
  46. images: [
  47. {
  48. src: require("@/assets/map/darkmap.png"),
  49. type: 1,
  50. active: "SEA",
  51. defalut: "SE",
  52. },
  53. {
  54. src: require("@/assets/map/sat2022.png"),
  55. type: 0,
  56. active: "DXA",
  57. defalut: "DX",
  58. },
  59. {
  60. src: require("@/assets/map/sat2019.png"),
  61. type: 2,
  62. active: "DXA1",
  63. defalut: "DX1",
  64. },
  65. ],
  66. rightPX: 50, // 每张图片距离右侧的距离 * index
  67. },
  68. };
  69. },
  70. computed: {
  71. baseMapRight() {
  72. return this.$store.state.baseMapRight;
  73. },
  74. menuChange() {
  75. return this.$store.state.navSelect;
  76. },
  77. baseMapType() {
  78. return this.$store.state.baseMapType;
  79. },
  80. },
  81. watch: {
  82. baseMapRight: {
  83. handler(val) {
  84. this.rightPosition = val;
  85. },
  86. immediate: true,
  87. },
  88. menuChange: {
  89. handler(val) {
  90. if (val.name === "镇域专题") {
  91. this.$store.state.baseMapRight = 40;
  92. } else if (val.name === "土地资源") {
  93. this.$store.state.baseMapRight = 5;
  94. } else {
  95. this.$store.state.baseMapRight = 23;
  96. }
  97. },
  98. deep: true,
  99. immediate: true,
  100. },
  101. baseMapType(val) {
  102. // console.log(val, "地图类型");
  103. },
  104. },
  105. methods: {
  106. change(index, type) {
  107. while (this.state.images[0].type != type) {
  108. let a = this.state.images.pop();
  109. // console.log(a);
  110. this.state.images.unshift(a);
  111. }
  112. this.$store.state.baseMapType = type;
  113. this.setLayer(type);
  114. },
  115. // 设置图层显示
  116. setLayer(type) {
  117. // 当前的底图类型 0 - imagery; 1 - 蓝黑图; 2 - imagery2
  118. switch (type) {
  119. case 0:
  120. // 遥感影像图sat2022
  121. // console.log("影像图");
  122. if (!map2DViewer.map.hasLayer(map2DViewer.layers["imagery"])) {
  123. map2DViewer.map.hasLayer(map2DViewer.layers["darkmap"]) &&
  124. map2DViewer.map.removeLayer(map2DViewer.layers["darkmap"]);
  125. map2DViewer.map.hasLayer(map2DViewer.layers["imagery2"]) &&
  126. map2DViewer.map.removeLayer(map2DViewer.layers["imagery2"]);
  127. map2DViewer.map.addLayer(map2DViewer.layers["imagery"]);
  128. }
  129. break;
  130. case 1:
  131. // console.log("蓝黑图");
  132. // 测绘院蓝黑图
  133. if (!map2DViewer.map.hasLayer(map2DViewer.layers["darkmap"])) {
  134. map2DViewer.map.hasLayer(map2DViewer.layers["imagery"]) &&
  135. map2DViewer.map.removeLayer(map2DViewer.layers["imagery"]);
  136. map2DViewer.map.hasLayer(map2DViewer.layers["imagery2"]) &&
  137. map2DViewer.map.removeLayer(map2DViewer.layers["imagery2"]);
  138. map2DViewer.map.addLayer(map2DViewer.layers["darkmap"]);
  139. }
  140. break;
  141. case 2:
  142. // 遥感影像图sat2018
  143. if (!map2DViewer.map.hasLayer(map2DViewer.layers["imagery2"])) {
  144. map2DViewer.map.hasLayer(map2DViewer.layers["darkmap"]) &&
  145. map2DViewer.map.removeLayer(map2DViewer.layers["darkmap"]);
  146. map2DViewer.map.hasLayer(map2DViewer.layers["imagery"]) &&
  147. map2DViewer.map.removeLayer(map2DViewer.layers["imagery"]);
  148. map2DViewer.map.addLayer(map2DViewer.layers["imagery2"]);
  149. }
  150. }
  151. // 调用全局事件总线中的指定事件
  152. this.$bus.$emit("reJLControl");
  153. },
  154. // 悬浮时图片右移
  155. mouseover() {
  156. this.state.rightPX = 125;
  157. },
  158. mouseleave() {
  159. this.state.rightPX = 50;
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="less" scoped>
  165. .map-change-move {
  166. transition: transform 0.3s;
  167. }
  168. .map-change {
  169. position: absolute;
  170. z-index: 9999;
  171. display: flex;
  172. align-items: center;
  173. background-color: #1e3968;
  174. padding: 2px;
  175. .img__box {
  176. width: 120px;
  177. height: 80px;
  178. cursor: pointer;
  179. position: absolute;
  180. bottom: 0;
  181. transition: all 0.5s;
  182. &.active {
  183. box-shadow: 0 2px 15px 3px #254486;
  184. }
  185. &:hover {
  186. width: 95px;
  187. height: 65px;
  188. box-shadow: 0 2px 15px 3px #254486;
  189. cursor: pointer;
  190. }
  191. }
  192. }
  193. </style>