-
Notifications
You must be signed in to change notification settings - Fork 2
/
map.html
95 lines (87 loc) · 2.53 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body, #map-canvas { height: 100%; margin: 0; padding: 0;}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?v=3.exp">
</script>
<script type="text/javascript">
var map = null;
var markers = {};
var selection = null;
var paths = []
function initialize() {
var mapOptions = {mapTypeId: google.maps.MapTypeId.ROADMAP};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': 'US'}, function (results, status) {
map.fitBounds(results[0].geometry.viewport);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function getMarkerImage(color) {
return new google.maps.MarkerImage(
"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + color,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
}
function addMarker(latlng, title, color) {
if (map == null) return;
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: title,
icon: getMarkerImage(color)
});
markers[title] = marker;
}
function addMarkers(locations, color) {
for (var loc in locations) {
if (locations.hasOwnProperty(loc))
addMarker(locations[loc], loc, color);
}
}
function setLocation(name) {
if (selection != null)
selection.marker.setIcon(selection.icon);
if (name == null) {
selection = null;
return;
}
marker = markers[name];
selection = {'marker': marker, 'icon': marker.icon};
marker.setIcon(getMarkerImage("ff0000"));
}
var arrow = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
function addPath(path) {
if (map == null) return;
return new google.maps.Polyline({
path: path,
icons: [{
icon: arrow,
offset: '100%'
}],
map: map
});
}
function addPaths(newPaths) {
var numPaths = paths.length;
for (var i = 0; i < numPaths; i++)
paths[i].setMap(null);
paths = []
numPaths = newPaths.length;
for (var i = 0; i < numPaths; i++)
paths.push(addPath(newPaths[i]));
}
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>