File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ <h1><a href="/">OpenHack</a></h1>
3131 < h2 > Cities</ h2 >
3232 < ul id ="cities ">
3333 {% for city in site.cities %}
34- < li id ="{{city.first.first}} " data-latitude ="{{city.first.last.latitude}} " data-longitude ="{{city.first.last.longitude}} ">
34+ < li class =" city " id ="{{city.first.first}} " data-latitude ="{{city.first.last.latitude}} " data-longitude ="{{city.first.last.longitude}} ">
3535 < a href ="/{{ city.first.first }} "> {{ city.first.last.name }}</ a >
3636 </ li >
3737 {% endfor %}
Original file line number Diff line number Diff line change 11$ ( function ( ) {
22
33
4- $ ( "#google_map" ) . addClass ( "js" ) ;
5-
6-
4+ // Parse city data into objects.
75 var cities = [ ] ;
8- $ ( "ul#cities li" ) . each ( function ( ) {
6+ $ ( "ul#cities li.city " ) . each ( function ( ) {
97 var a , li ;
108 li = $ ( this ) ;
119 a = $ ( this ) . find ( "a" ) ;
1210 cities . push ( {
1311 name : a . text ( ) ,
1412 id : li . attr ( "id" ) ,
1513 url : a . attr ( "href" ) ,
16- lat : li . attr ( "data-latitude" ) ,
17- lng : li . attr ( "data-longitude" )
14+ lat : parseFloat ( li . attr ( "data-latitude" ) ) ,
15+ lng : parseFloat ( li . attr ( "data-longitude" ) )
1816 } ) ;
1917 } )
2018
2119
20+ // Add the Google Map to the page.
21+ var canvas = $ ( "#google_map" ) ;
22+ canvas . addClass ( "js" ) ;
23+ var map = new google . maps . Map ( canvas [ 0 ] , {
24+ streetViewControl : false ,
25+ mapTypeControl : false ,
26+ zoomControl : false ,
27+ mapTypeId : google . maps . MapTypeId . ROADMAP
28+ } ) ;
29+
30+
31+ // For each city, create a marker and adjust the map bounds.
32+ var markers = [ ] ;
33+ var bounds = new google . maps . LatLngBounds ( ) ;
34+ for ( i in cities ) {
35+ var city = cities [ i ] ;
36+ var latlng = new google . maps . LatLng ( city . lat , city . lng ) ;
37+ var marker = new google . maps . Marker ( {
38+ position : latlng ,
39+ title : city . name
40+ } ) ;
41+ markers . push ( marker ) ;
42+ marker . setMap ( map ) ;
43+ bounds . extend ( latlng ) ;
44+ }
45+ map . fitBounds ( bounds ) ;
46+
47+
2248} ) ;
You can’t perform that action at this time.
0 commit comments