| | |
| | | <img src="@/assets/img/sslk.png" alt="" class="item-tb-img"> |
| | | <p class="item-tb-p">实时路况</p> |
| | | </div> |
| | | </div> |
| | | |
| | | <!-- 导入自定义弹窗 --> |
| | | <div class="dialog-container dialog"> |
| | | <DialogType1 ref="dtype1"></DialogType1> |
| | | <DialogType2 ref="dtype2"></DialogType2> |
| | | <DialogType3 ref="dtype3"></DialogType3> |
| | | <DialogType4 ref="dtype4"></DialogType4> |
| | | <DialogType5 ref="dtype5"></DialogType5> |
| | | <DialogType6 ref="dtype6"></DialogType6> |
| | | <DialogType7 ref="dtype7"></DialogType7> |
| | | <DialogType8 ref="dtype8"></DialogType8> |
| | | <DialogType9 ref="dtype9"></DialogType9> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, ref } from 'vue'; |
| | | import { onMounted, ref,getCurrentInstance } from 'vue'; |
| | | import AMapLoader from '@amap/amap-jsapi-loader'; |
| | | |
| | | import { require } from '@/utils/require.js'; |
| | | import DialogType1 from './dialog/dialog-type1.vue'; |
| | | import DialogType2 from './dialog/dialog-type2.vue'; |
| | | import DialogType3 from './dialog/dialog-type3.vue'; |
| | | import DialogType4 from './dialog/dialog-type4.vue'; |
| | | import DialogType5 from './dialog/dialog-type5.vue'; |
| | | import DialogType6 from './dialog/dialog-type6.vue'; |
| | | import DialogType7 from './dialog/dialog-type7.vue'; |
| | | import DialogType8 from './dialog/dialog-type8.vue'; |
| | | import DialogType9 from './dialog/dialog-type9.vue'; |
| | | |
| | | import icon1 from '@/assets/img/icon/icon1.png'; |
| | | import icon2 from '@/assets/img/icon/icon2.png'; |
| | |
| | | import icon8 from '@/assets/img/icon/icon8.png'; |
| | | import icon9 from '@/assets/img/icon/icon9.png'; |
| | | |
| | | const dtype1 = ref(null); |
| | | const dtype2 = ref(null); |
| | | const dtype3 = ref(null); |
| | | const dtype4 = ref(null); |
| | | const dtype5 = ref(null); |
| | | const dtype6 = ref(null); |
| | | const dtype7 = ref(null); |
| | | const dtype8 = ref(null); |
| | | const dtype9 = ref(null); |
| | | |
| | | const map = ref(null); |
| | | |
| | | // dialog集合 |
| | | const dialogList = ref({}); |
| | | // 获取当前实例 |
| | | const {ctx} = getCurrentInstance(); |
| | | |
| | | let mapInstance = null; |
| | | let trafficLayer = null;; |
| | | |
| | |
| | | |
| | | // 地图的图标数组 |
| | | const markers = []; |
| | | |
| | | // 信息弹窗 |
| | | let infoWindow = null; |
| | | |
| | | // 图列 |
| | | const legendList = ref([ |
| | |
| | | // 过滤图列 |
| | | const filterLegend = (item) => { |
| | | const { icon, positions, type } = item; |
| | | const dialog = dialogList.value[type].$refs.dialog; |
| | | const tempList = []; |
| | | positions.map(position => { |
| | | const markerIcon = createIcon(icon); |
| | | const marker = ceateMarker(markerIcon, position); |
| | | const marker = ceateMarker(type, markerIcon, position); |
| | | tempList.push(marker); |
| | | marker.on('click', (markerEvent) => { |
| | | infoWindow.setContent(dialog); |
| | | infoWindow.open(mapInstance, markerEvent.target.getPosition()); |
| | | // console.log(dialogList.value[type]); |
| | | }); |
| | | }); |
| | | markers.push({ type: type, markerList: tempList }) |
| | | mapInstance.add(tempList); |
| | | } |
| | | |
| | | // 创建弹窗 |
| | | const createInfoWindow = () => { |
| | | infoWindow = new AMap.InfoWindow({ |
| | | isCustom: true, |
| | | closeWhenClickMap: true, |
| | | offset: new AMap.Pixel(20, -20), |
| | | }); |
| | | } |
| | | |
| | | // 创建图标 |
| | |
| | | |
| | | |
| | | // 创建marker |
| | | const ceateMarker = (icon, position) => { |
| | | const ceateMarker = (type, icon, position) => { |
| | | return new AMap.Marker({ |
| | | icon: icon, |
| | | position: new AMap.LngLat(position[0], position[1]), |
| | | zooms: [2, 20], |
| | | extData: type |
| | | }); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | // 弹窗与组件映射 |
| | | const mapComponentInstance = () => { |
| | | legendList.value.map((item) => { |
| | | dialogList.value[item.id] = ctx.$refs[`dtype${item.id}`]; |
| | | }) |
| | | } |
| | | |
| | | |
| | | onMounted(() => { |
| | | AMapLoader.load({ |
| | | key: "2898109c22191c3969957500934169dc", //申请好的 Web 端开发者 Key,首次调用 load 时必填 |
| | |
| | | |
| | | trafficLayer.setMap(mapInstance); |
| | | |
| | | |
| | | // 限制一个区域轮廓 |
| | | const options = { |
| | | subdistrict: 0, |
| | | extensions: "all", |
| | | level: "district", |
| | | }; |
| | | |
| | | // 限制一个区域轮廓 |
| | | AMap.plugin("AMap.DistrictSearch", function () { |
| | | //在回调函数中实例化插件,并使用插件功能 |
| | | const district = new AMap.DistrictSearch(options); |
| | |
| | | mapInstance.add(polygon); |
| | | }); |
| | | }); |
| | | |
| | | // 创建infowindow |
| | | createInfoWindow(); |
| | | // 映射组件 |
| | | mapComponentInstance(); |
| | | }) |
| | | .catch((e) => { |
| | | console.log(e); |
| | |
| | | :deep(.amap-copyright) { |
| | | visibility: hidden !important; |
| | | } |
| | | |
| | | .dialog { |
| | | opacity: 0; |
| | | position: absolute; |
| | | left: -500px; |
| | | } |
| | | </style> |