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| %> <%- if venue.lat && venue.lng %> var location = new google.maps.LatLng("<%= venue.lat %>","<%= venue.lng %>") add_marker(map, { title : "<%= escape_javascript(venue.title) %>", position : location, <% if Radiant::Config['event_map.use_calendar_icons?'] && slug = slug_for_venue(venue) %> image : "/images/map_icons/<%= slug %>.png", shadow : "/images/map_icons/<%= slug %>_shadow.png", <% end %> description : "<%= escape_javascript(render :partial => 'venue', :object => venue) %>" }); bounds.extend(location); <% end %> <% 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); }); }