_google_maps.rhtml
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<%= content_tag('script', '', :src => GoogleMaps.api_url(environment.default_hostname), :type => 'text/javascript') %>
<div style='text-align: center;'>
<div id="map"></div>
</div>
<script type='text/javascript'>
var points = {};
function putMarker(lat, lng, title, summary) {
var point_str = lat + ":" + lng;
if (points[point_str]) {
lng += (Math.random() - 0.5) * 0.02;
lat += (Math.random() - 0.5) * 0.02;
} else {
points[point_str] = true;
}
var point = new GLatLng(lat, lng);
var options = { 'title' : title, 'icon' : icon };
var marker = new GMarker(point, options);
map.addOverlay(marker);
GEvent.addListener(marker, 'click', function() {
map.openInfoWindowHtml(point, summary);
});
bounds.extend(point);
}
window.unload = function() {
GUnload();
};
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
new GKeyboardHandler(map);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
centerPoint = new GLatLng(-15.0, -50.1419);
map.setCenter(centerPoint, <%= GoogleMaps.initial_zoom.to_json %>);
var bounds = new GLatLngBounds();
var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(32,32);
baseIcon.shadowSize=new GSize(36,32);
baseIcon.iconAnchor=new GPoint(16,32);
baseIcon.infoWindowAnchor=new GPoint(16,0);
<%
icon = default_or_themed_icon("/images/icons-map/enterprise.png")
icon_shadow = default_or_themed_icon("/images/icons-map/enterprise_shadow.png")
%>
var icon = new GIcon(baseIcon, "<%= icon %>", null, "<%= icon_shadow %>");
<%
@results.each do |name,results|
results.each do |item|
if item.lat && item.lng
%>
putMarker(<%= item.lat.to_json %>, <%= item.lng.to_json %>, <%= item.name.to_json %>, <%= display_item_map_info(item).to_json %>);
<%
end
end
end
%>
}
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
</script>