-
Notifications
You must be signed in to change notification settings - Fork 3
/
amap_massmarker.html
127 lines (126 loc) · 5.19 KB
/
amap_massmarker.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>点聚合</title>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script src="http://webapi.amap.com/maps?v=1.4.6&key=93fc94012de7fd139283557b8d04534d&plugin=AMap.MarkerClusterer"></script>
</head>
<body>
<div id="container"></div>
<div class="button-group">
<input type="button" class="button" value="默认样式" id="add0" onclick = 'addCluster(0)'/>
<input type="button" class="button" value="自定义图标" id="add1" onclick = 'addCluster(1)'/>
<input type="button" class="button" value="完全自定义" id="add2" onclick = 'addCluster(2)'/>
</div>
<script>
var points = [
{'lnglat': ['113.864691', '22.942327']},
{'lnglat': ['113.370643', '22.938827']},
{'lnglat': ['112.985037', '23.15046']},
{'lnglat': ['110.361899', '20.026695']},
{'lnglat': ['121.434529', '31.215641']},
{'lnglat': ['120.682502', '28.011099']},
{'lnglat': ['126.687123', '45.787618']},
{'lnglat': ['103.970724', '30.397931']},
{'lnglat': ['117.212164', '31.831641']},
{'lnglat': ['121.411101', '31.059407']},
{'lnglat': ['104.137953', '30.784276']},
{'lnglat': ['120.499683', '30.042305']},
{'lnglat': ['108.94686', '34.362975']},
{'lnglat': ['112.873295', '22.920901']},
{'lnglat': ['113.373916', '23.086728']},
{'lnglat': ['113.250159', '23.075847']},
{'lnglat': ['116.675933', '39.986343']},
{'lnglat': ['120.75997', '31.734934']},
{'lnglat': ['118.314741', '32.26999']},
{'lnglat': ['111.723311', '34.771838']},
{'lnglat': ['119.537126', '26.200017']},
{'lnglat': ['113.830123', '23.00734']},
{'lnglat': ['119.273795', '26.060002']}]
var cluster, markers = [];
var map = new AMap.Map("container", {
resizeEnable: true,
center:[105,34],
zoom: 4
});
for(var i=0;i<points.length;i+=1){
markers.push(new AMap.Marker({
position:points[i]['lnglat'],
content: '<div style="background-color: hsla(180, 100%, 50%, 0.7); height: 24px; width: 24px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 1px;"></div>',
offset: new AMap.Pixel(-15,-15)
}))
}
console.log(markers)
// var count = markers.length;
/*
var _renderCluserMarker = 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%,50%,0.7)';
var fontColor = 'hsla('+Hue+',100%,20%,1)';
var borderColor = 'hsla('+Hue+',100%,40%,1)';
var shadowColor = 'hsla('+Hue+',100%,50%,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 1px '+ 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)
}
*/
// addCluster(2);
// addCluster();
cluster = new AMap.MarkerClusterer(map, markers,{gridSize:80});
function addCluster(tag) {
if (cluster) {
cluster.setMap(null);
}
if (tag == 2) {//完全自定义
cluster = new AMap.MarkerClusterer(map,markers,{
gridSize:80,
renderCluserMarker:_renderCluserMarker
});
} else if (tag == 1) {//自定义图标
var sts = [{
url: "http://a.amap.com/jsapi_demos/static/images/blue.png",
size: new AMap.Size(32, 32),
offset: new AMap.Pixel(-16, -16)
}, {
url: "http://a.amap.com/jsapi_demos/static/images/green.png",
size: new AMap.Size(32, 32),
offset: new AMap.Pixel(-16, -16)
}, {
url: "http://a.amap.com/jsapi_demos/static/images/orange.png",
size: new AMap.Size(36, 36),
offset: new AMap.Pixel(-18, -18)
},{
url: "http://a.amap.com/jsapi_demos/static/images/red.png",
size: new AMap.Size(48, 48),
offset: new AMap.Pixel(-24, -24)
},{
url: "http://a.amap.com/jsapi_demos/static/images/darkRed.png",
size: new AMap.Size(48, 48),
offset: new AMap.Pixel(-24, -24)
}];
cluster = new AMap.MarkerClusterer(map, markers, {
styles: sts,
gridSize:80
});
} else {//默认样式
cluster = new AMap.MarkerClusterer(map, markers,{gridSize:80});
}
}
</script>
</body>
</html>