80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/iruby/output/html.rb', line 80
def self.heatmap(o)
data = o.delete(:points)
raise "Missing :points parameter" if not data
points = points2latlng(data)
zoom = o.delete(:zoom)
center = o.delete(:center)
map_type = o.delete(:map_type)
r = <<E
<div id='map-canvas' style='width: 500px; height: 500px;'></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=visualization&callback=initialize"></script>
<script>
function initialize() {
var points = #{points};
var latlngbounds = new google.maps.LatLngBounds();
var zoom = #{zoom.to_json};
var center = #{center.to_json};
var map_type = #{map_type.to_json} || google.maps.MapTypeId.SATELLITE;
var mapOptions = {
mapTypeId: map_type
};
if (zoom){
mapOptions.zoom = zoom
}
if (center){
mapOptions.center = new google.maps.LatLng(center.lat, center.lon)
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
if (! zoom){
for (var i = 0; i < points.length; i++) {
latlngbounds.extend(points[i].location);
}
map.fitBounds(latlngbounds);
}
var pointArray = new google.maps.MVCArray(points);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
}
console.log("finished pre- init!")
</script>
E
STDERR.write("#{r}\n\n")
r
end
|