Skip to content

Commit 791e78a

Browse files
committed
Holy heck this might work?
1 parent bef75b5 commit 791e78a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

app/controllers/record_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@ def view
1616
# Manipulation of returned record would go here...
1717

1818
@record = response&.data&.to_h&.dig('recordId')
19+
@rectangle = bounding_box_to_coords
1920
end
2021

2122
private
2223

24+
def bounding_box_to_coords
25+
return unless geospatial_coordinates?(@record['locations'])
26+
27+
raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first
28+
bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')
29+
bbox_array = bbox.split(', ')
30+
coords = [[bbox_array[2].to_f, bbox_array[0].to_f], [bbox_array[3].to_f, bbox_array[1].to_f]]
31+
Rails.logger.info("Raw BBox: #{raw_bbox}")
32+
Rails.logger.info("Rectangle: #{coords}")
33+
coords
34+
end
35+
2336
def validate_id!
2437
return if params[:id]&.strip.present?
2538

app/views/record/_record_geo.html.erb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,39 @@
7979
<% end %>
8080
<% end %>
8181
</ul>
82+
83+
<% content_for :additional_meta_tag do %>
84+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
85+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
86+
crossorigin=""/>
87+
88+
<!-- Make sure you put this AFTER Leaflet's CSS -->
89+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
90+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
91+
crossorigin=""></script>
92+
<% end %>
93+
94+
<div id="map" style="height: 180px"></div>
95+
<script>
96+
var map = L.map('map');
97+
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
98+
maxZoom: 19,
99+
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
100+
}).addTo(map);
101+
102+
// define rectangle geographical bounds
103+
// -71.158693, -71.064796, 42.395972, 42.351993
104+
// var bounds = [[42.395972, -71.158693],[42.351993, -71.064796]];
105+
106+
console.log('#<%= @rectangle %>');
107+
var bounds = <%= @rectangle %>;
108+
109+
// create an orange rectangle
110+
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
111+
112+
// zoom the map to the rectangle bounds
113+
map.fitBounds(bounds);
114+
</script>
82115
<% end %>
83116

84117
<% if @record['notes'].present? %>

0 commit comments

Comments
 (0)