map.vue 4.3 KB

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