map.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div
  3. id="container"
  4. class="mapContainer"
  5. />
  6. <div
  7. v-if="Item.contrlSelect.option.length"
  8. class="mapContainer-menus"
  9. >
  10. <p>
  11. <icon
  12. :name="Item.contrlSelect.icon"
  13. :size="22"
  14. style="margin-right: 10px;"
  15. />
  16. {{ Item.contrlSelect.title }}
  17. </p>
  18. <n-checkbox-group
  19. v-model:value="checkBoxs"
  20. checked
  21. @update:value="checkBoxsChange"
  22. >
  23. <n-checkbox
  24. v-for="(item, index) in Item.contrlSelect.option"
  25. :key="index"
  26. :value="item.value"
  27. >
  28. <icon
  29. :name="item.icon"
  30. :size="20"
  31. />
  32. {{ item.label }}
  33. </n-checkbox>
  34. </n-checkbox-group>
  35. </div>
  36. </template>
  37. <script setup lang='ts'>
  38. import {
  39. onMounted, onUnmounted, ref, watch
  40. } from 'vue'
  41. import useStore from '@/pages/store/index'
  42. import MapService from './map.service'
  43. const store = useStore()
  44. const mapService = new MapService()
  45. const props = withDefaults(defineProps<{
  46. zoom?: number,
  47. Item?: { contrlSelect: { title: string, option: Any[], icon: string, checked:string[] }, key:string }
  48. }>(), {
  49. zoom: 13,
  50. Item: () => ({
  51. key: '',
  52. contrlSelect: {
  53. title: '', option: [], icon: '', checked: []
  54. }
  55. })
  56. })
  57. const emit = defineEmits<{(evt: 'update:contrlSelect', value: Any): void
  58. }>()
  59. const checkBoxs = ref(props.Item.contrlSelect.checked)
  60. // checkBox勾选
  61. function checkBoxsChange(params:string[], mate:{actionType:string, value:string}) {
  62. const { marks } = mapService
  63. console.log('勾选', marks[props.Item.key][mate.value])
  64. if (!Object.keys(marks[props.Item.key][mate.value]).length) return
  65. for (const key in marks[props.Item.key][mate.value]) {
  66. if (marks[props.Item.key][mate.value][key] && marks[props.Item.key][mate.value][key].markMap) {
  67. if (mate.actionType === 'check') {
  68. marks[props.Item.key][mate.value][key].markMap.show()
  69. } else {
  70. marks[props.Item.key][mate.value][key].markMap.hide()
  71. }
  72. }
  73. }
  74. }
  75. onMounted(async () => {
  76. await mapService._initMap(props.zoom)
  77. mapService._initMarks(props.Item.key, props.Item.contrlSelect.checked, props.Item.contrlSelect)
  78. })
  79. // 车位置更新
  80. watch(() => store.socektData, (v) => {
  81. if (v && v.BUS_LINE_INFO && props.Item.key === 'homePage' && checkBoxs.value.includes('bus')) {
  82. const { marks } = mapService
  83. for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
  84. const el = v.BUS_LINE_INFO[k]
  85. for (let j = 0; j < el.inboundAndOutboundStations.length; j++) {
  86. const es = el.inboundAndOutboundStations[j]
  87. if (marks[props.Item.key].bus[es.vehicleId]) {
  88. // 更新位置
  89. // console.log(123, marks[props.Item.key][1][es.vehicleId])
  90. marks[props.Item.key].bus[es.vehicleId].markMap?.setPosition([ es.lng, es.lat ])
  91. marks[props.Item.key].bus[es.vehicleId].markMap?.show()
  92. } else {
  93. // 添加位置
  94. marks[props.Item.key].bus[es.vehicleId] = { ...es, markMap: mapService.addMark([ es.lng, es.lat ]) }
  95. }
  96. }
  97. }
  98. }
  99. }, { deep: true })
  100. // 菜单切换显示隐藏
  101. watch(() => props.Item.key, (v) => {
  102. console.log('菜单切换需要重新初始化mark', v)
  103. const { marks } = mapService
  104. for (const k in marks) {
  105. for (const j in marks[k]) {
  106. if (Object.keys(marks[k][j]).length) {
  107. for (const z in marks[k][j]) {
  108. if (k === props.Item.key) {
  109. marks[k][j][z].markMap.show()
  110. } else {
  111. marks[k][j][z].markMap.hide()
  112. }
  113. }
  114. }
  115. }
  116. }
  117. })
  118. onUnmounted(() => mapService.destory())
  119. </script>
  120. <style lang="scss" scoped>
  121. .mapContainer {
  122. width: 100%;
  123. height: 100%;
  124. mask-image: radial-gradient(circle at center, #030E25 70%, transparent 76%);
  125. &-menus {
  126. min-width: 180px;
  127. position: absolute;
  128. bottom: 240px;
  129. right: 300px;
  130. z-index: 3;
  131. border-top-left-radius: 5px;
  132. border-top-right-radius: 5px;
  133. overflow: hidden;
  134. box-sizing: border-box;
  135. font-size: 20px;
  136. &>p:first-child {
  137. color: #FFFFFF;
  138. background: rgba(33, 133, 232, 1);
  139. display: flex;
  140. align-items: center;
  141. height: 40px;
  142. padding: 0 10px;
  143. }
  144. &>div:last-child {
  145. background: rgba(25, 39, 56, 0.6);
  146. border: solid 1px rgba(33, 133, 232, 1);
  147. ;
  148. }
  149. :deep(.n-checkbox) {
  150. padding: 5px 10px;
  151. display: flex;
  152. align-items: center;
  153. .n-checkbox__label {
  154. display: flex;
  155. align-items: center;
  156. font-size: 20px;
  157. &>svg {
  158. margin-right: 5px;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>