Skip to content

Business intelligence made simple

Added partial for maps [skip ci]

Andrew Kane58d37a1178d0
diff --git a/app/views/blazer/queries/_map.html.erb b/app/views/blazer/queries/_map.html.erb
new file mode 100644
index 00000000..020b11db
--- /dev/null
+++ b/app/views/blazer/queries/_map.html.erb
@@ -0,0 +1,8 @@
+<% map_id = SecureRandom.hex %>
+<%= tag.div id: map_id, style: "height: #{@only_chart ? 300 : 500}px;" %>
+<%= javascript_tag nonce: true do %>
+ (function () {
+ <%= blazer_js_var "map", {type: type, id: map_id, data: data, options: options} %>
+ new Mapkick[map.type](map.id, map.data, map.options);
+ })()
+<% end %>
diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erb
index 38fd2a3f..71446b77 100644
--- a/app/views/blazer/queries/run.html.erb
+++ b/app/views/blazer/queries/run.html.erb
@@ -71,24 +71,11 @@
<% color = "#54a3ee" %>
<% series_library[1] = {borderDash: [8], borderColor: color, pointBackgroundColor: color, backgroundColor: color, pointHoverBackgroundColor: color} %>
<% end %>
+ <% map_options = {accessToken: Blazer.mapbox_access_token, tooltips: {hover: false, html: true}} %>
<% if @markers.any? %>
- <% map_id = SecureRandom.hex %>
- <%= tag.div id: map_id, style: "height: #{@only_chart ? 300 : 500}px;" %>
- <%= javascript_tag nonce: true do %>
- <%= blazer_js_var "mapboxAccessToken", Blazer.mapbox_access_token %>
- <%= blazer_js_var "markers", @markers %>
- <%= blazer_js_var "mapId", map_id %>
- new Mapkick.Map(mapId, markers, {accessToken: mapboxAccessToken, tooltips: {hover: false, html: true}});
- <% end %>
+ <%= render partial: "map", locals: {type: "Map", data: @markers, options: map_options} %>
<% elsif @geojson.any? %>
- <% map_id = SecureRandom.hex %>
- <%= tag.div id: map_id, style: "height: #{@only_chart ? 300 : 500}px;" %>
- <%= javascript_tag nonce: true do %>
- <%= blazer_js_var "mapboxAccessToken", Blazer.mapbox_access_token %>
- <%= blazer_js_var "geojson", @geojson %>
- <%= blazer_js_var "mapId", map_id %>
- new Mapkick.AreaMap(mapId, geojson, {accessToken: mapboxAccessToken, tooltips: {hover: false, html: true}});
- <% end %>
+ <%= render partial: "map", locals: {type: "AreaMap", data: @geojson, options: map_options} %>
<% elsif chart_type == "line" %>
<% chart_data = @columns[1..-1].each_with_index.map { |k, i| {name: blazer_series_name(k), data: @rows.map { |r| [r[0], r[i + 1]] }, library: series_library[i]} } %>
<%= render partial: "chart", locals: {type: "LineChart", data: chart_data, options: chart_options} %>