-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp2.html
84 lines (76 loc) · 2.7 KB
/
exp2.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
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>点聚合</title>
<link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0/dist/css/bootstrap.css"/>
<script type="text/javascript" src="https://unpkg.com/jquery@3.3.1/dist/jquery.js"></script>
<script type="text/javascript" src="https://unpkg.com/moment@2.22.1/moment.js"></script>
<script type="text/javascript"
src="http://api.map.baidu.com/api?v=2.0&ak=fnrRFnHyBPzCoyOqZygwGI6OBj9Gnr2Q"></script>
<script type="text/javascript" src="https://unpkg.com/gcoord@0.1.2/dist/gcoord.js"></script>
<script type="text/javascript" src="src/MarkerClusterer.js"></script>
<script type="text/javascript" src="src/TextIconOverlay.js"></script>
<style>
#map {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div id="map"></div>
</div>
</div>
<script type="text/javascript">
var bmap;
$(function () {
$('#map').height($(window).height());
bmap = new BMap.Map('map');
// 添加带有定位的导航控件
var navigationControl = new BMap.NavigationControl({
// 靠左上角位置
anchor: BMAP_ANCHOR_TOP_LEFT,
// LARGE类型
type: BMAP_NAVIGATION_CONTROL_LARGE,
// 启用显示定位
enableGeolocation: true
});
bmap.addControl(navigationControl);
var lon = 116.397390000, lat = 39.4088600000;
bmap.centerAndZoom(new BMap.Point(lon, lat), 8);
var points = [
new BMap.Point(116.397390000, 39.4088600000),
new BMap.Point(116.397390000, 39.3088600000),
];
var markers = [];
$.each(points, function (key, item) {
var icon = new BMap.Icon('img/m0.png', new BMap.Size(18, 15));
var marker = new BMap.Marker(item, {icon: icon});
marker.data = item;
marker.addEventListener('click', function (event) {
var _marker = event.target;
var _data = event.target.data;
alert(JSON.stringify(_data));
});
markers.push(marker);
});
var markerClusterer = new BMapLib.MarkerClusterer(bmap, {
styles: [
{
url: 'img/m.png',
size: new BMap.Size(53, 53),
textColor: 'transparent'
}
],
markers: markers,
onclick: function (event, cluster) {
alert('聚合了' + cluster._markers.length + '个点');
return false;
}
});
});
</script>
</body>
</html>