| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <div
- id="container"
- class="mapContainer"
- />
- <div
- v-if="Item.contrlSelect.option.length"
- class="mapContainer-menus"
- >
- <p>
- <icon
- :name="Item.contrlSelect.icon"
- :size="22"
- style="margin-right: 10px;"
- />
- {{ Item.contrlSelect.title }}
- </p>
- <n-checkbox-group
- v-model:value="checkBoxs"
- checked
- @update:value="checkBoxsChange"
- >
- <n-checkbox
- v-for="(item, index) in Item.contrlSelect.option"
- :key="index"
- :value="item.value"
- >
- <icon
- :name="item.icon"
- :size="20"
- />
- {{ item.label }}
- </n-checkbox>
- </n-checkbox-group>
- </div>
- </template>
- <script setup lang='ts'>
- import { onMounted, ref, watch } from 'vue'
- import useStore from '@/pages/store/index'
- import MapService from './map.service'
- const store = useStore()
- const mapService = new MapService()
- const props = withDefaults(defineProps<{
- zoom?: number,
- Item?: { contrlSelect: { title: string, option: Any[], icon: string, checked:number[] }, key:string }
- }>(), {
- zoom: 13,
- Item: () => ({
- key: '',
- contrlSelect: {
- title: '', option: [], icon: '', checked: []
- }
- })
- })
- const emit = defineEmits<{(evt: 'update:contrlSelect', value: Any): void
- }>()
- const checkBoxs = ref(props.Item.contrlSelect.checked)
- // checkBox勾选
- function checkBoxsChange(params:number[], mate:{actionType:string, value:number}) {
- const { marks } = mapService
- console.log('勾选', marks[props.Item.key][mate.value])
- if (!Object.keys(marks[props.Item.key][mate.value]).length) return
- for (const key in marks[props.Item.key][mate.value]) {
- if (marks[props.Item.key][mate.value][key] && marks[props.Item.key][mate.value][key].markMap) {
- if (mate.actionType === 'check') {
- marks[props.Item.key][mate.value][key].markMap.show()
- } else {
- marks[props.Item.key][mate.value][key].markMap.hide()
- }
- }
- }
- }
- onMounted(() => {
- mapService._initMap(props.zoom)
- mapService._initMarks(props.Item.key, props.Item.contrlSelect.checked)
- })
- // 车位置更新
- watch(() => store.socektData, (v) => {
- if (v && v.BUS_LINE_INFO && props.Item.key === 'homePage' && checkBoxs.value.includes(1)) {
- const { marks } = mapService
- for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
- const el = v.BUS_LINE_INFO[k]
- for (let j = 0; j < el.inboundAndOutboundStations.length; j++) {
- const es = el.inboundAndOutboundStations[j]
- if (marks[props.Item.key][1][es.vehicleId]) {
- // 更新位置
- marks[props.Item.key][1][es.vehicleId].markMap.setPosition([ es.lng, es.lat ])
- marks[props.Item.key][1][es.vehicleId].markMap.show()
- } else {
- // 添加位置
- marks[props.Item.key][1][es.vehicleId] = { ...es, markMap: mapService.addMark([ es.lng, es.lat ]) }
- }
- }
- }
- }
- }, { deep: true })
- // 菜单切换显示隐藏
- watch(() => props.Item.key, (v) => {
- console.log('菜单切换', v)
- const { marks } = mapService
- for (const k in marks) {
- for (const j in marks[k]) {
- if (Object.keys(marks[k][j]).length) {
- for (const z in marks[k][j]) {
- if (k === props.Item.key) {
- marks[k][j][z].markMap.show()
- } else {
- marks[k][j][z].markMap.hide()
- }
- }
- }
- }
- }
- })
- </script>
- <style lang="scss" scoped>
- .mapContainer {
- width: 100%;
- height: 100%;
- mask-image: radial-gradient(circle at center, #030E25 70%, transparent 76%);
- &-menus {
- min-width: 180px;
- position: absolute;
- bottom: 240px;
- right: 300px;
- z-index: 3;
- border-top-left-radius: 5px;
- border-top-right-radius: 5px;
- overflow: hidden;
- box-sizing: border-box;
- font-size: 20px;
- &>p:first-child {
- color: #FFFFFF;
- background: rgba(33, 133, 232, 1);
- display: flex;
- align-items: center;
- height: 40px;
- padding: 0 10px;
- }
- &>div:last-child {
- background: rgba(25, 39, 56, 0.6);
- border: solid 1px rgba(33, 133, 232, 1);
- ;
- }
- :deep(.n-checkbox) {
- padding: 5px 10px;
- display: flex;
- align-items: center;
- .n-checkbox__label {
- display: flex;
- align-items: center;
- font-size: 20px;
- &>svg {
- margin-right: 5px;
- }
- }
- }
- }
- }
- </style>
|