if(typeof jQuery == 'function') { jQuery.fn.populate_map = function() { this.each(function() { build_map_and_markers(this); }); }; jQuery(function() { jQuery("#map_canvas").populate_map(); }); } function build_map_and_markers(element) { if (element != null) { var map = new google.maps.Map(element, { mapTypeId: google.maps.MapTypeId.<%= (Radiant::Config['event_map.googlemap.type'] || 'ROADMAP').upcase %>, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.<%= (Radiant::Config['event_map.googlemap.controlstyle'] || 'DROPDOWN_MENU').upcase %> } }); var bounds = new google.maps.LatLngBounds(); <% venues.each do |venue| %> add_marker(map, { title : "<%= escape_javascript(venue.title) %>", position : new google.maps.LatLng("<%= venue.lat %>","<%= venue.lng %>"), description : "<%= escape_javascript(render :partial => 'venue', :object => venue) %>" }); bounds.extend(new google.maps.LatLng("<%= venue.lat %>","<%= venue.lng %>")); <% end %> map.fitBounds(bounds); } } function add_marker (map, mark) { var marker = new google.maps.Marker({ map : map, position : mark['position'], title : mark['title'], icon : mark['image'], shadow : mark['shadow'] }); var infowindow = new google.maps.InfoWindow({ content : mark['description'] , maxWidth : 400 }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); }