-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
270 lines (245 loc) · 8.21 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!doctype html>
<html>
<head>
<title>Sample gmap-features code</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
}
</style>
</head>
<body>
<h1>Demo of gmap-features</h1>
<ul class="maps">
<li>
<p>Parsing JSON data file</p>
<div id="map1" style="width:500px;height:300px;"></div>
</li>
<li>
<p>Parsing KML data file</p>
<div id="map2" style="width:500px;height:300px;"></div>
</li>
<li>
<p>Supports features with holes and multiple parts</p>
<div id="map3" style="width:500px;height:300px;"></div>
</li>
<li>
<p>Highlighting/selecting/unselecting colors are based on feature data, via responsive_*_opts callbacks</p>
<div id="map4" style="width:500px;height:300px;"></div>
</li>
</ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="gmap-features.js"></script>
<script type="text/javascript">
// example using json data
function map1() {
var map, features;
map = new google.maps.Map(document.getElementById("map1"), {
center: new google.maps.LatLng(40.731368,-73.975071),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
});
$.getJSON("sampledata/data.json", function(data) {
var BLUES = ["#E9F6FF", "#B3D6FF", "#7BB1FF", "#4C89E0", "#4073BC", "#284A72"];
/*
* invoke load_polygons
*/
features = gmap.load_polygons({
map: map,
data: data, //required. all other params are optional
data_type: "json", // 'json' is default. can also use 'kml' in which case pass the kml document as data as a string
getColor: function(data) {
// runs in the scope of each feature. returns the color to set it to
// has access to the data in this.fields
var perc;
if (data.totpop != 0) {
perc = Number(data.totpop_wnh)/Number(data.totpop);
} else { perc = 0; }
return BLUES[(Math.floor(perc * 5)) % 5]; // maps [0,1) into 0 to 4. buckets of .2
},
unselected_opts: {
"fillOpacity": .75
},
highlighted_opts: {
strokeWeight: 3.0,
strokeColor: "#FF0000"
},
selected_opts: {
strokeWeight: 2.0,
strokeColor: "#0000FF"
},
highlightCallback: function(e) {
console.log("highlighted "+this.id);
},
selectCallback: function(e) {
console.log(this.fields);
}
});
});
}
// example using KML data
function map2() {
var map, features;
map = new google.maps.Map(document.getElementById("map2"), {
center: new google.maps.LatLng(40.8765,-73.9095),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
});
$.get("sampledata/data.kml", function(data) {
var BLUES = ["#E9F6FF", "#B3D6FF", "#7BB1FF", "#4C89E0", "#4073BC", "#284A72"];
features = gmap.load_polygons({
map: map,
data: data, //required. all other params are optional
data_type: "kml", // 'json' is default. can also use 'kml' in which case pass the kml document as data as a string
getColor: function(data) {
// runs in the scope of each feature. returns the color to set it to
// has access to the data in this.fields
var perc;
if (data.totpop != 0) {
perc = Number(data.totpop_wnh)/Number(data.totpop);
} else { perc = 0; }
return BLUES[(Math.floor(perc * 5)) % 5]; // maps [0,1) into 0 to 4. buckets of .2
},
unselected_opts: {
"fillOpacity": .75
},
highlighted_opts: {
strokeWeight: 3.0,
strokeColor: "#FF0000"
},
selected_opts: {
strokeWeight: 2.0,
strokeColor: "#0000FF"
},
highlightCallback: function(e) {
console.log("highlighted "+this.id);
},
selectCallback: function(e) {
console.log(this.fields);
}
});
});
}
// example using KML data
function map3() {
var map, features;
map = new google.maps.Map(document.getElementById("map3"), {
center: new google.maps.LatLng(40.8765,-73.9095),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
});
$.get("sampledata/data2.kml", function(data) {
var BLUES = ["#E9F6FF", "#B3D6FF", "#7BB1FF", "#4C89E0", "#4073BC", "#284A72"];
features = gmap.load_polygons({
map: map,
data: data, //required. all other params are optional
data_type: "kml", // 'json' is default. can also use 'kml' in which case pass the kml document as data as a string
getColor: function(data) {
// runs in the scope of each feature. returns the color to set it to
// has access to the data in this.fields
var perc;
if (data.totpop != 0) {
perc = Number(data.totpop_wnh)/Number(data.totpop);
} else { perc = 0; }
return BLUES[(Math.floor(perc * 5)) % 5]; // maps [0,1) into 0 to 4. buckets of .2
},
unselected_opts: {
"fillOpacity": .75
},
highlighted_opts: {
strokeWeight: 3.0,
strokeColor: "#FF0000"
},
selected_opts: {
strokeWeight: 2.0,
strokeColor: "#0000FF"
},
highlightCallback: function(e) {
console.log("highlighted "+this.id);
},
selectCallback: function(e) {
console.log(this.fields);
}
});
});
}
// example using json data and responsive callbacks for highlighted/selected/unselected states
function map4() {
var map, features;
map = new google.maps.Map(document.getElementById("map4"), {
center: new google.maps.LatLng(40.731368,-73.975071),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
});
$.getJSON("sampledata/data.json", function(data) {
var BLUES = ["#E9F6FF", "#B3D6FF", "#7BB1FF", "#4C89E0", "#4073BC", "#284A72"];
/*
* invoke load_polygons
*/
features = gmap.load_polygons({
map: map,
data: data, //required. all other params are optional
data_type: "json", // 'json' is default. can also use 'kml' in which case pass the kml document as data as a string
unselected_opts: {
"fillOpacity": .75
},
highlighted_opts: {
strokeWeight: 2.0,
strokeColor: "#000000"
},
selected_opts: {
strokeWeight: 2.0,
strokeColor: "#000000"
},
responsive_unselected_opts: function() {
if(this.fields.totpop_wnh > 100) {
return { fillColor: "#8DEEEE" };
} else {
return { fillColor: "#EE1289" };
}
},
responsive_highlighted_opts: function() {
if(this.fields.totpop_wnh > 100) {
return { fillColor: "#8DEE00" };
} else {
return { fillColor: "#EE1200" };
}
},
responsive_selected_opts: function() {
if(this.fields.totpop_wnh > 100) {
return { strokeWeight: 5, strokeColor: "#00EE00" };
} else {
// You can also just let it inherit the default
return { };
}
},
highlightCallback: function(e) {
console.log("highlighted "+this.id);
},
selectCallback: function(e) {
console.log(this.fields);
}
});
});
}
function initialize() {
map1();
map2();
map3();
map4();
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>