-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap_copy.html
52 lines (49 loc) · 2.07 KB
/
Map_copy.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello, World</title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#container{height:100%}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4">
//v1.4版本及以前版本的引用方式:src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
</script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
var map = new BMap.Map("container"); // 创建Map实例
map.centerAndZoom(new BMap.Point(116.323066,39.989956), 16); // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
var points = [
[116.316967,39.990748],
[116.323938,39.989919],
[116.328896,39.988039],
[116.321135,39.987072],
[116.332453,39.989007],
[116.324045,39.987984],
[116.322285,39.988316],
[116.322608,39.986381]
];
// 向地图添加标注
for( var i = 0;i < points.length; i++){
var myIcon = new BMap.Icon("http://www.personalwebhhf.cn/photo/hometown/hometown5.jpg", new BMap.Size(23, 25), {
// 指定定位位置
offset: new BMap.Size(10, 25),
// 当需要从一幅较大的图片中截取某部分作为标注图标时,需要指定大图的偏移位置
imageOffset: new BMap.Size(0, 0 - i * 25) // 设置图片偏移
});
var point = new BMap.Point(points[i][0],points[i][1]);
// 创建标注对象并添加到地图
var marker = new BMap.Marker(point,{icon: myIcon});
map.addOverlay(marker);
};
</script>
</body>
</html>