-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
112 lines (97 loc) · 3.64 KB
/
index.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
111
112
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>State Foo</title>
<script src="coords.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js" type="text/javascript"></script>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
.label {
color: red;
background-color: white;
font-family: "Lucida Grande", "Arial", sans-serif;
font-size: 11px;
font-weight: bold;
text-align: center;
border: 2px solid black;
white-space: nowrap;
padding: 2px 5px;
}
</style>
<script type="text/javascript">
function createPolygonWithLabel(map, label, points) {
// The state outline polygon, drawn by coordinates..
var polygon = new google.maps.Polygon({
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
paths: points ,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3
});
// The label that pops up when the mouse moves within each polygon.
var marker = new MarkerWithLabel({
labelContent: label,
labelClass: 'label',
labelStyle: {
opacity: 1.0
},
position: new google.maps.LatLng(0, 0), // a LatLng is required
draggable: false,
raiseOnDrag: false,
map: map,
icon: 'http://placehold.it/1x1', // disable marker pin icon
visible: false
});
// When the mouse moves within the polygon, display the label and change the BG color.
google.maps.event.addListener(polygon, "mousemove", function(event) {
marker.setPosition(event.latLng);
marker.setVisible(true);
polygon.setOptions({
fillColor: "#00FF00"
});
});
// WHen the mouse moves out of the polygon, hide the label and change the BG color.
google.maps.event.addListener(polygon, "mouseout", function(event) {
marker.setVisible(false);
polygon.setOptions({
fillColor: "#FF0000"
});
});
return polygon;
}
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(23, -101),
mapTypeId: google.maps.MapTypeId.TERRAIN
},
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions),
j;
for (var i = 0; i < stateCoords.length; i++) {
var coords = [],
label = stateCoords[i][0],
points = stateCoords[i][1];
for (j = 0; j < points.length; j++) {
coords.push(
new google.maps.LatLng(points[j][0], points[j][1])
)
}
createPolygonWithLabel(map, label, coords);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>