Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (47 sloc) 1.65 KB
<%-
map = item.maps.first
return '' unless map
return '' if map.map_lat.blank? || map.map_lng.blank?
markers = map.markers
google_api = request.ssl? ? "https://maps-api-ssl.google.com/maps/api/js?sensor=false&region=jp" : "http://maps.google.com/maps/api/js?sensor=false&region=jp"
-%>
<script type="text/javascript" src="<%= google_api %>"></script>
<script type="text/javascript">
//<![CDATA[
function addEvent(element, listener, func) {
try {
element.addEventListener(listener, func, false);
} catch (e) {
element.attachEvent('on' + listener, func);
}
}
addEvent(window, 'load', function() {
var mapOptions = {
center: new google.maps.LatLng(<%= map.map_lat %>, <%= map.map_lng %>),
zoom: <%= map.map_zoom %>,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true,
scrollwheel: false
};
var map = new google.maps.Map(document.getElementById("map1"), mapOptions);
<% markers.each_with_index do |marker, idx| %>
var marker<%= idx %> = new google.maps.Marker({
//title: '<%= marker.name.gsub(/'/, "\\\\'") %>'
position: new google.maps.LatLng(<%= marker.lat %>, <%= marker.lng %>),
map: map
});
var infowindow<%= idx %> = new google.maps.InfoWindow({
content: '<%= marker.name.gsub(/'/, "\\\\'").gsub(/\r\n|\r|\n/, "<br />") %>',
disableAutoPan: false
});
google.maps.event.addListener(marker<%= idx %>, 'click', function() {
infowindow<%= idx %>.open(map, marker<%= idx %>);
});
<% end %>
});
//]]>
</script>
<div style="padding: 0px 10px;">
<%= "#{h map.title}<br />".html_safe if map.title.present? %>
<div id="map1" style="width: 100%; height: 400px"></div>
</div>
You can’t perform that action at this time.