initMap() {标签:style,聚合,let,AMap,版本,var,new,div,高德 From: https://www.cnblogs.com/licxwww/p/17516258.html
let that = this
let points = []
try {
let level = that.mapLevel === 'null' || null === that.mapLevel ? 10 : this.mapLevel
let centerPoint = that.mapCenter.split(',')
that.map = new AMap.Map('container', {
center: [parseFloat(centerPoint[0]), parseFloat(centerPoint[1])],
// center: [112.164625,24.113956],
mapStyle: 'amap://styles/b125cc30f48d58a2a34912540fb4291a',
//mapStyle: 'amap://styles/e01743cfe3dc2f1c80db46171c621fa6',
showLabel: true,
viewMode: '3D',
pitch: 0,
resizeEnable: true,
rotateEnable: true,
zoom: level,
zooms: [5, 20]//地图显示的缩放级别范围
})
console.log(this.map)
//限制地图显示范围
// let bounds = this.map.getBounds()
// this.map.setLimitBounds(bounds)
let startIcon = new AMap.Icon({
// 图标尺寸
size: new AMap.Size(55, 54),
// 图标的取图地址
image: gongdan1,
// 图标所用图片大小
imageSize: new AMap.Size(25, 30),
// 图标取图偏移量
imageOffset: new AMap.Pixel(0, 0)
});
that.workTicketList.forEach(function(item) {
let marker = new AMap.Marker({
zIndex: 111,
position: new AMap.LngLat(item.latitude,item.longitude),
icon: startIcon,
});
points.push(marker)
// that.map.add(marker)
marker.on("mouseover", function (p) {
let info = ""
info+="<div class='infowindowCss'> ";
info+="<p class='input-item'>工单号 :"+item.workTickets+"</p>";
info+="<p class='input-item'>工单类型 :"+that.getOrderStatus(item.status)+"</p></div></div>";
that.infoWindow.setContent(info);
that.infoWindow.open(that.map,[item.latitude, item.longitude])
});
marker.on("mouseout", function () {
that.infoWindow.close();
});
})
/* that.cluster=new AMap.MarkerCluster(that.map, points, {
gridSize: 60, // 设置网格像素大小
renderClusterMarker: _renderClusterMarker, // 自定义聚合点样式
renderMarker: _renderMarker, // 自定义非聚合点样式
});*/
/* let count = points.length
var _renderClusterMarker = function (context) {
var factor = Math.pow(context.count / count, 1 / 18);
var div = document.createElement('div');
var Hue = 180 - factor * 180;
var bgColor = 'hsla(' + Hue + ',100%,40%,0.7)';
var fontColor = 'hsla(' + Hue + ',100%,90%,1)';
var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
var shadowColor = 'hsla(' + Hue + ',100%,90%,1)';
div.style.backgroundColor = bgColor;
var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
div.style.width = div.style.height = size + 'px';
div.style.border = 'solid 1px ' + borderColor;
div.style.borderRadius = size / 2 + 'px';
div.style.boxShadow = '0 0 5px ' + shadowColor;
div.innerHTML = context.count;
div.style.lineHeight = size + 'px';
div.style.color = fontColor;
div.style.fontSize = '14px';
div.style.textAlign = 'center';
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
context.marker.setContent(div)
};
var _renderMarker = function(context) {
var content = '<div style=" height: 18px; width: 18px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 3px;"></div>';
var offset = new AMap.Pixel(-9, -9);
context.marker.setContent(content)
context.marker.setOffset(offset)
}*/
// 点聚合样式
that.cluster = new AMap.MarkerClusterer(that.map,points, {
gridSize: 80
});
} catch (e) {
console.log(e)
}
}