vue高德地图点击放大Maker
效果图:点击图标变大,之前图标恢复正常状态。
loadMap() {
var map = new AMap.Map('yzMap', {
zoom: 18, // 级别
center: [119.598372,25.885029] // 中心点坐标
})
var icon = require('../../assets/images/map/i4.png');
var icon1 = require('../../assets/images/map/i3.png');
var styleName = "amap://styles/darkblue"
map.setMapStyle(styleName);
var marker;
for (var i = 0; i < 2; i++){
var jfong = [119.608372,26.600029];
if(i == 1){
jfong = [119.598372,25.885029];
}
marker = new AMap.Marker({
position: jfong,
icon: icon,
zIndex: 101,
extData:icon,
map: map
});
var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, -30),
});
marker.setMap(map);
marker.content = `<ul class='main' style="width:340px">
<li><span style='color:blue'>站点名:</span></li>
<li><span style='color:blue'>经纬度:</span></li>
<li><span style='color:blue'>启用时间:</span></li>
</ul>`;
marker.on("click", markerClick);
}
function markerClick(e) {
infoWindow.setContent(e.target.content); // 自定义窗口添加一个盒子去展示对应Marker(地图上的图标)所要展示的信息
infoWindow.open(map, e.target.getPosition()); // Marker(地图上的图标) 打开自定义窗口的事件
// e.target.setIcon(icon1);
console.log(e.target.getExtData())
self.selectedMarkerStore = e.target.getExtData()
//判断是第否点击过
if (self.lastClickedMarker) {
let icon = self.lastClickedMarker.getIcon()
self.lastClickedMarker.setOffset(new AMap.Pixel(-10, -30))
self.lastClickedMarker.setIcon(
new AMap.Icon({
size: new AMap.Size(25, 30), // 图标尺寸
image: icon.Ce.image, // Icon的图像
imageSize: new AMap.Size(25, 30)
})
)
}
let icon2 = e.target.getIcon()
e.target.setIcon(
new AMap.Icon({
size: new AMap.Size(80, 90), // 图标尺寸
image: e.target.getExtData(), // Icon的图像
imageSize: new AMap.Size(80, 90)
})
)
// e.target.setOffset(new AMap.Pixel(-18, -50))
//有点击就给他加进去这样就能获取上一次数据
self.lastClickedMarker = e.target
}
map.setFitView();
},