map.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. if (props.Item.key === 'homePage') mapService.getLines()
  77. })
  78. // 车位置更新
  79. watch(() => store.socektData, (v) => {
  80. if (v && v.BUS_LINE_INFO && props.Item.key === 'homePage' && checkBoxs.value.includes(1)) {
  81. const { marks } = mapService
  82. for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
  83. const el = v.BUS_LINE_INFO[k]
  84. for (let j = 0; j < el.inboundAndOutboundStations.length; j++) {
  85. const es = el.inboundAndOutboundStations[j]
  86. if (marks[props.Item.key][1][es.vehicleId]) {
  87. // 更新位置
  88. marks[props.Item.key][1][es.vehicleId].markMap.setPosition([ es.lng, es.lat ])
  89. marks[props.Item.key][1][es.vehicleId].markMap.show()
  90. } else {
  91. // 添加位置
  92. marks[props.Item.key][1][es.vehicleId] = { ...es, markMap: mapService.addMark([ es.lng, es.lat ]) }
  93. }
  94. }
  95. }
  96. }
  97. }, { deep: true })
  98. // 菜单切换显示隐藏
  99. watch(() => props.Item.key, (v) => {
  100. console.log('菜单切换', v)
  101. const { marks } = mapService
  102. for (const k in marks) {
  103. for (const j in marks[k]) {
  104. if (Object.keys(marks[k][j]).length) {
  105. for (const z in marks[k][j]) {
  106. if (k === props.Item.key) {
  107. marks[k][j][z].markMap.show()
  108. } else {
  109. marks[k][j][z].markMap.hide()
  110. }
  111. }
  112. }
  113. }
  114. }
  115. })
  116. </script>
  117. <style lang="scss" scoped>
  118. .mapContainer {
  119. width: 100%;
  120. height: 100%;
  121. mask-image: radial-gradient(circle at center, #030E25 70%, transparent 76%);
  122. &-menus {
  123. min-width: 180px;
  124. position: absolute;
  125. bottom: 240px;
  126. right: 300px;
  127. z-index: 3;
  128. border-top-left-radius: 5px;
  129. border-top-right-radius: 5px;
  130. overflow: hidden;
  131. box-sizing: border-box;
  132. font-size: 20px;
  133. &>p:first-child {
  134. color: #FFFFFF;
  135. background: rgba(33, 133, 232, 1);
  136. display: flex;
  137. align-items: center;
  138. height: 40px;
  139. padding: 0 10px;
  140. }
  141. &>div:last-child {
  142. background: rgba(25, 39, 56, 0.6);
  143. border: solid 1px rgba(33, 133, 232, 1);
  144. ;
  145. }
  146. :deep(.n-checkbox) {
  147. padding: 5px 10px;
  148. display: flex;
  149. align-items: center;
  150. .n-checkbox__label {
  151. display: flex;
  152. align-items: center;
  153. font-size: 20px;
  154. &>svg {
  155. margin-right: 5px;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. </style>