BasemapChange.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <transition-group name="map-change" tag="div">
  3. <div
  4. key="map-change"
  5. class="map-change"
  6. :style="{
  7. right: `${right}px`,
  8. bottom: `${bottom}px`,
  9. }"
  10. @mouseover="mouseover"
  11. @mouseleave="mouseleave"
  12. >
  13. <!-- 注意key值不能使用数组索引 否则无变化 -->
  14. <img
  15. v-for="(item, index) in images"
  16. :key="item.type"
  17. :src="item.src"
  18. class="img__box"
  19. :class="{ active: index === 0 }"
  20. :style="{
  21. right: `${index * 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. imageGroup: {
  35. // 地形图
  36. DX: require("@/assets/map/02.png"),
  37. // 深色地图
  38. SE: require("@/assets/map/03.png"),
  39. // 街道底图
  40. JD: require("@/assets/map/01.png"),
  41. // 遥感地图
  42. DXA: require("@/assets/map/02_.png"),
  43. // 深色地图
  44. SEA: require("@/assets/map/03_.png"),
  45. // 街道底图
  46. JDA: require("@/assets/map/01_.png"),
  47. },
  48. state: {
  49. // 图片数组
  50. images: [
  51. { src: this.imageGroup.SEA, type: 1, active: "SEA", defalut: "SE" },
  52. { src: this.imageGroup.DX, type: 0, active: "DXA", defalut: "DX" },
  53. { src: this.imageGroup.JD, type: 2, active: "JDA", defalut: "JD" },
  54. ],
  55. rightPX: 50, // 每张图片距离右侧的距离 * index
  56. },
  57. };
  58. },
  59. props: {
  60. right: {
  61. type: Number,
  62. default: 10,
  63. },
  64. bottom: {
  65. type: Number,
  66. default: 10,
  67. },
  68. },
  69. methods: {
  70. change(index, type) {
  71. while (this.state.images[0].type != type) {
  72. let a = this.state.images.pop();
  73. console.log(a);
  74. this.state.images.unshift(a);
  75. }
  76. this.$store.state.baseMapType = type;
  77. this.setLayer(type);
  78. },
  79. // 设置图层显示
  80. setLayer(type) {
  81. console.log(type, "当前的底图类型");
  82. },
  83. // 悬浮时图片右移
  84. mouseover() {
  85. this.state.rightPX = 125;
  86. },
  87. mouseleave() {
  88. this.state.rightPX = 50;
  89. },
  90. },
  91. };
  92. </script>
  93. <style lang="less" scoped>
  94. .map-change-move {
  95. transition: transform 1s;
  96. }
  97. .map-change {
  98. position: absolute;
  99. z-index: 9999;
  100. display: flex;
  101. align-items: center;
  102. background-color: #1e3968;
  103. padding: 2px;
  104. .img__box {
  105. width: 120px;
  106. height: 80px;
  107. cursor: pointer;
  108. position: absolute;
  109. bottom: 0;
  110. transition: all 0.5s;
  111. &.active {
  112. box-shadow: 0 2px 15px 3px #254486;
  113. }
  114. &:hover {
  115. width: 95px;
  116. height: 65px;
  117. box-shadow: 0 2px 15px 3px #254486;
  118. cursor: pointer;
  119. }
  120. }
  121. }
  122. </style>