大家好,又见面了,我是你们的朋友全栈君。
init() {
var provinces = this.provinces;
if (!provinces || provinces.length == 0) {
return false;
}
var hmap = {
resizeEnable: true,
center: [“106.687915”, “26.499209”],
zoom: 10
};
var map = new AMap.Map(“container”, hmap);
var markers = []; //province见Demo引用的JS文件
//var longitudeArr=[];//经度
//var latitudeArr=[];//纬度
for (var i = 0; i < provinces.length; i += 1) {
var marker;
var nposition = provinces[i].center.split(“,”);
//console.log(“nposition》》》》”,nposition);
if (nposition[0] == “26.571257”) {
return false;
}
if (nposition.length == 2) {
//longitudeArr.push(nposition[0]);
//latitudeArr.push(nposition[1]);
if (provinces[i].type == 0) {
var icon = new AMap.Icon({
image: “https://vdata.amap.com/icons/b18/1/2.png”,
size: new AMap.Size(24, 24)
});
marker = new AMap.Marker({
icon: icon,
position: nposition,
offset: new AMap.Pixel(-12, -12),
zIndex: 101,
title: provinces[i].name,
map: map
});
} else {
var redicon = new AMap.Icon({
image: require(“../assets/red.png”),
size: new AMap.Size(24, 24)
});
var blueicon = new AMap.Icon({
image: require(“../assets/blue.png”),
size: new AMap.Size(24, 24)
});
//判断显示那个图标
if (provinces[i].workStatus == 0) {
marker = new AMap.Marker({
position: nposition,
title: provinces[i].name,
map: map,
icon: redicon,
});
} else {
marker = new AMap.Marker({
position: nposition,
title: provinces[i].name,
map: map,
icon: blueicon,
clickable: true,
});
}
//添加参数
marker.projectId=provinces[i].projectId;
if (provinces[i].type === 2) {
var content = “
宝岛台湾”;
baodao = new AMap.Marker({
content: content,
position: nposition,
title: provinces[i].name,
offset: new AMap.Pixel(0, 0),
map: map
});
}
}
//点标注的点击事件
marker.on(‘click’, function(e) {
console.log(e.target.projectId);
});
markers.push(marker);
}
}
//在视野中显示所有的点
map.setFitView();
},
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/143151.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...