Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (49 sloc) 1.91 KB
<%
map = item.maps.find(:first)
markers = map ? map.markers : []
return render(:text => "") unless map
return render(:text => "") if map.map_lat.blank? || map.map_lng.blank?
%><script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&region=jp"></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
});
<%- if item.content.respond_to?(:map_content_marker) && (map_content = item.content.map_content_marker) -%>
marker<%= idx %>.setIcon('<%= map_content.icon_image(item.marker_icon_category || item.marker_categories.first) %>');
<%- end -%>
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 class="maps">
<h2>地図</h2>
<% if !map.title.blank? %><h3><%= map.title %></h3><% end %>
<div id="map1" class="map" style="width: 100%; height: 400px"></div>
</div>
You can’t perform that action at this time.