diff --git a/src/utils/mapCustom.js b/src/utils/mapCustom.js index 766fe65..259f5b2 100644 --- a/src/utils/mapCustom.js +++ b/src/utils/mapCustom.js @@ -106,17 +106,12 @@ export class MapCustom { newIcon(option) { let data = { size: new AMap.Size(36, 42), - image: '', // Icon的图像 + image: option.image, // Icon的图像 imageSize: new AMap.Size(36, 42) } - if (typeof option == 'string') { - data.image = option - } else { - data = { - image: option.image, // Icon的图像 - size: new AMap.Size(option.size[0], option.size[1]), - imageSize: new AMap.Size(option.size[0], option.size[1]), - } + if (option.size) { + data.size = new AMap.Size(option.size[0], option.size[1]) + data.imageSize = new AMap.Size(option.size[0], option.size[1]) } return new AMap.Icon({ ...data }) } @@ -131,13 +126,14 @@ export class MapCustom { lngLat(lng, lat) { return new AMap.LngLat(lng, lat); } - infoWindow(option = { - anchor: 'bottom-center', - isCustom: true, //使用自定义窗体 - content: document.querySelector('.infoBox'), - offset: new AMap.Pixel(-2, -40), - }) { - return new AMap.InfoWindow(option) + infoWindow(option) { + return new AMap.InfoWindow({ + anchor: 'bottom-center', + isCustom: true, + content: document.querySelector('.infoBox'), + offset: new AMap.Pixel(-2, -40), + ...option + }) } //绘制轨迹线条 diff --git a/src/views/incidentDispose/index.vue b/src/views/incidentDispose/index.vue index 53ddc50..942592b 100644 --- a/src/views/incidentDispose/index.vue +++ b/src/views/incidentDispose/index.vue @@ -281,7 +281,7 @@ const getData = async () => { map.clearMap(); map.setCenter([res.lng, res.lat]); - let icon = map.newIcon(location); + let icon = map.newIcon({ image: location }); let marker = map.marker({ icon, position: [res.lng, res.lat] }); marker.setMap(map.map); marker.on("click", () => {