vue 点标记 高德地图_vue高德地图多点标记,点击出现弹窗

该博客展示了如何在Vue项目中使用高德地图API创建多点标记,并实现点击标记时弹出信息窗口。通过设置图标、监听点击事件,实现了地图上的医院位置标记,并传递点击的标记ID。
摘要由CSDN通过智能技术生成

占坑预警

先展示效果:

image.png

image.png

代码:

import AMap from "AMap";

export default {

props:["allCopmpony"],

data() {

return {

map: null,

mapStyle: [],

marker: {},

markerList: []

};

},

watch: {},

created() {

console.log(this.allCopmpony)

},

mounted() {

this.mapInit();

this.setHospitalMarker(this);

},

methods: {

mapInit() {

let _self = this;

_self.weXinAmapMap = new AMap.Map("container", {

center: [118.54436, 33.011971],

layers: [new AMap.TileLayer.Satellite(), new AMap.TileLayer.RoadNet()],

zooms: [1, 18],

zoom: 12

});

this.clickIcon = new AMap.Icon({

image: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",

size: new AMap.Size(24, 30), //图标大小

imageSize: new AMap.Size(24, 30)

});

},

setHospitalMarker(_this) {

this.icon = new AMap.Icon({

size: new AMap.Size(36, 36),

image:

"//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",

imageSize: new AMap.Size(24, 30),

imageOffset: new AMap.Pixel(0, 0)

});

let markerList = [];

this.allCopmpony.forEach((element, index) => {

let marker = new AMap.Marker({

map: this.weXinAmapMap,

zIndex: 9999999,

position: [element.longi, element.lati]

});

marker.id = element.enterNumber;

marker.on("click", this.controlHospitalMarker);

_this.weXinAmapMap.add(marker);

this.markerList.push(marker);

});

var content = [

`

医院信息

名称:章广人民医院

地址:滁州市南谯区章广镇003县道

`

];

this.infoWindow1 = new AMap.InfoWindow({

anchor: "top-left",

content: content.join("
") //传入 dom 对象,或者 html 字符串

});

this.infoWindow1.open(_this.weXinAmapMap, [118.54436, 33.011971]);

var newCenter = this.weXinAmapMap.setFitView();

},

//控制医院标记的信息窗体的显示

controlHospitalMarker(e) {

// console.log('111',this.markerList)

console.log(e);

this.infoWindow1.open(this.weXinAmapMap, [e.lnglat.M, e.lnglat.O]);

this.markerList.forEach(item=>{

item.setIcon(this.icon)

})

e.target.setIcon(this.clickIcon);

this.$emit('changeTraceNumber',e.target.id)

}

}

};

.map {

width: 600px;

height: 600px;

}

.context_menu {

position: relative;

min-width: 12rem;

padding: 0;

}

.btn {

position: absolute;

top: 0px;

}

.context_menu p {

cursor: pointer;

color: red;

padding: 0.25rem 1.25rem;

}

.context_menu p:hover {

background: #ccc;

}

.amap-markers .amap-marker .amap-marker-content .location {

width: 100px;

height: 30px;

background: #fff;

}

有空会将坑填上!并附上详细讲解!祝各位生活愉快!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值