Skip to content

Instantly share code, notes, and snippets.

@thuss

thuss/_map.html.haml

Created Jun 27, 2011
Embed
What would you like to do?
Google maps haml partial
/ Partial used on http://www.fanclasstic.com for mapping organizations
- organizations = organizations.delete_if{|o| o.latitude.nil? || o.longitude.nil?}
- if organizations.size > 0
- center = Geocoder::Calculations.geographic_center(organizations.clone)
#google-map
%script{:src => "http://maps.google.com/maps/api/js?sensor=false"}
%script{:type => "text/javascript"}
//<![CDATA[
function initialize() {
var myOptions = {
zoom: #{(organizations.size == 1) ? '15':'10'},
center: new google.maps.LatLng(#{center[0]}, #{center[1]}),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("google-map"), myOptions);
- for organization in organizations
var marker = new google.maps.Marker({
position: new google.maps.LatLng(#{organization.latitude}, #{organization.longitude}),
map: map,
title:"#{organization.name}"
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&key=#{Geocoder::Configuration.api_key}&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
//]]>
... haml ...
#map-column
= render :partial => "shared/map", :locals => { :organizations => [@organization] }
... haml ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment