-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapline10.html
127 lines (101 loc) · 3.79 KB
/
mapline10.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
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>CanvasLayer</title>
<script src="jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=您的密钥"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=jF9S7N9GfhoukfD6rGehm8phoiXwcWh5Q"></script>
<script src="gps.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
body, html,#container {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
</head>
<body>
<label>城市</label><input type="text" name="" id="city" value="" placeholder="城市" disabled="disabled"/>
<label>起始站点</label><input type="text" name="" id="start" value="" placeholder="起始站点"/>
<label>结束站点</label><input type="text" name="" id="end" value="" placeholder="结束站点"/>
<button onclick="getgps()">获取站点</button>
<div id="container"></div>
</body>
</html>
<script type="text/javascript">
var mp = new BMap.Map("container");
mp.centerAndZoom(new BMap.Point(116.3964,39.9093), 10);
mp.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
mp.addControl(new BMap.ScaleControl()); // 添加比例尺控件
mp.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
mp.enableScrollWheelZoom(true); //启用滚轮放大缩小
mp.disable3DBuilding();
//background
mp.setMapStyle({
styleJson:[
{
"featureType": "all",
"elementType": "all",
"stylers": {
"color": "#254247ff",
"visibility": "on"
}
},
{
"featureType": "administrative",
"elementType": "all",
"stylers": {
"visibility": "off"
}
},
{
"featureType": "poilabel",
"elementType": "all",
"stylers": {
"visibility": "on"
}
},
{
"featureType": "highway",
"elementType": "all",
"stylers": {
"visibility": "off"
}
}
]
});
var canvasLayer = new BMap.CanvasLayer({
update: update
});
var data = [
new BMap.Point(116.42352915955,39.994148222486),
new BMap.Point(116.42352915955,39.994148222486),
new BMap.Point(116.42396932925,39.984370524385),
new BMap.Point(116.42403221064,39.983271740814),
new BMap.Point(116.42352915955,39.994148222486),
];
console.log(data)
function update() {
var ctx = this.canvas.getContext("2d");
if (!ctx) {
return;
}
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
var temp = {};
ctx.fillStyle = "rgba(50, 50, 255, 0.7)";
ctx.beginPath();
// ctx.strokeStyle = "bule"//可以选用CSS颜色字符串
// ctx.fillStyle = "#FF0000"//设置填充颜色
// var pixel0 = mp.pointToPixel(data['1']);
// ctx.moveTo(pixel0.x, pixel0.y);
for (var i = 0, len = data.length; i < len; i++) {
var pixel = mp.pointToPixel(data[i]);
ctx.fillRect(pixel.x, pixel.y, 6, 6);
// ctx.lineTo(mp.pointToPixel(data[i+1]).x, mp.pointToPixel(data[i+1]).y);
// ctx.fill();//填充
// ctx.stroke();//画线
}
}
var polyline = new BMap.Polyline(data,
{strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5}
);
mp.addOverlay(polyline);
mp.addOverlay(canvasLayer);
</script>