提交 | 用户 | 时间
|
58d006
|
1 |
<!DOCTYPE html> |
A |
2 |
<html> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<title>GMaps.js — Custom controls</title> |
|
6 |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> |
|
7 |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> |
|
8 |
<script type="text/javascript" src="../gmaps.js"></script> |
|
9 |
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" /> |
|
10 |
<link rel="stylesheet" type="text/css" href="examples.css" /> |
|
11 |
<script type="text/javascript"> |
|
12 |
var map; |
|
13 |
$(document).ready(function(){ |
|
14 |
map = new GMaps({ |
|
15 |
el: '#map', |
|
16 |
zoom: 16, |
|
17 |
lat: -12.043333, |
|
18 |
lng: -77.028333 |
|
19 |
}); |
|
20 |
map.addControl({ |
|
21 |
position: 'top_right', |
|
22 |
content: 'Geolocate', |
|
23 |
style: { |
|
24 |
margin: '5px', |
|
25 |
padding: '1px 6px', |
|
26 |
border: 'solid 1px #717B87', |
|
27 |
background: '#fff' |
|
28 |
}, |
|
29 |
events: { |
|
30 |
click: function(){ |
|
31 |
GMaps.geolocate({ |
|
32 |
success: function(position){ |
|
33 |
map.setCenter(position.coords.latitude, position.coords.longitude); |
|
34 |
}, |
|
35 |
error: function(error){ |
|
36 |
alert('Geolocation failed: ' + error.message); |
|
37 |
}, |
|
38 |
not_supported: function(){ |
|
39 |
alert("Your browser does not support geolocation"); |
|
40 |
} |
|
41 |
}); |
|
42 |
} |
|
43 |
} |
|
44 |
}); |
|
45 |
}); |
|
46 |
</script> |
|
47 |
</head> |
|
48 |
<body> |
|
49 |
<h1>GMaps.js — Custom controls</h1> |
|
50 |
<div class="row"> |
|
51 |
<div class="span11"> |
|
52 |
<div id="map"></div> |
|
53 |
</div> |
|
54 |
<div class="span6"> |
|
55 |
<p>GMaps.js allows to add custom controls:</p> |
|
56 |
<pre>map.addControl({ |
|
57 |
position: 'top_right', |
|
58 |
text: 'Geolocate', |
|
59 |
style: { |
|
60 |
margin: '5px', |
|
61 |
padding: '1px 6px', |
|
62 |
border: 'solid 1px #717B87', |
|
63 |
background: '#fff' |
|
64 |
}, |
|
65 |
events: { |
|
66 |
click: function(){ |
|
67 |
console.log(this); |
|
68 |
} |
|
69 |
} |
|
70 |
});</pre> |
|
71 |
<p> |
|
72 |
<span class="label notice">Note: </span> You can use the following positions: |
|
73 |
<ul> |
|
74 |
<li>top_center</li> |
|
75 |
<li>top_left</li> |
|
76 |
<li>top_right</li> |
|
77 |
<li>left_top</li> |
|
78 |
<li>right_top</li> |
|
79 |
<li>left_center</li> |
|
80 |
<li>right_center</li> |
|
81 |
<li>left_bottom</li> |
|
82 |
<li>right_bottom</li> |
|
83 |
<li>bottom_center</li> |
|
84 |
<li>bottom_left</li> |
|
85 |
<li>bottom_right</li> |
|
86 |
</ul> |
|
87 |
You can learn more of custom controls <a href="https://developers.google.com/maps/documentation/javascript/controls">here</a>.</p> |
|
88 |
</div> |
|
89 |
</div> |
|
90 |
</body> |
|
91 |
</html> |