2025年04月29日09:47:14

This commit is contained in:
luojiayi 2025-04-29 09:47:17 +08:00
parent 20aa050e75
commit 49ae2970bf
2 changed files with 13 additions and 17 deletions

View File

@ -106,17 +106,12 @@ export class MapCustom {
newIcon(option) { newIcon(option) {
let data = { let data = {
size: new AMap.Size(36, 42), size: new AMap.Size(36, 42),
image: '', // Icon的图像 image: option.image, // Icon的图像
imageSize: new AMap.Size(36, 42) imageSize: new AMap.Size(36, 42)
} }
if (typeof option == 'string') { if (option.size) {
data.image = option data.size = new AMap.Size(option.size[0], option.size[1])
} else { data.imageSize = new AMap.Size(option.size[0], option.size[1])
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]),
}
} }
return new AMap.Icon({ ...data }) return new AMap.Icon({ ...data })
} }
@ -131,13 +126,14 @@ export class MapCustom {
lngLat(lng, lat) { lngLat(lng, lat) {
return new AMap.LngLat(lng, lat); return new AMap.LngLat(lng, lat);
} }
infoWindow(option = { infoWindow(option) {
return new AMap.InfoWindow({
anchor: 'bottom-center', anchor: 'bottom-center',
isCustom: true, //使用自定义窗体 isCustom: true,
content: document.querySelector('.infoBox'), content: document.querySelector('.infoBox'),
offset: new AMap.Pixel(-2, -40), offset: new AMap.Pixel(-2, -40),
}) { ...option
return new AMap.InfoWindow(option) })
} }
//绘制轨迹线条 //绘制轨迹线条

View File

@ -281,7 +281,7 @@ const getData = async () => {
map.clearMap(); map.clearMap();
map.setCenter([res.lng, res.lat]); 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] }); let marker = map.marker({ icon, position: [res.lng, res.lat] });
marker.setMap(map.map); marker.setMap(map.map);
marker.on("click", () => { marker.on("click", () => {