Skip to content

Commit edbb8a6

Browse files
committed
Initial refactor to extract some common logic
1 parent 336210b commit edbb8a6

File tree

5 files changed

+45
-43
lines changed

5 files changed

+45
-43
lines changed

app/views/record/_record_geo.html.erb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@
6363
<!-- We only care about geospatial locations for this, as place names are also subjects. -->
6464
<% if geospatial_coordinates?(@record['locations']) %>
6565
<h3 class="section-title">Geospatial coordinates</h3>
66-
<% content_for :additional_meta_tag do %>
67-
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
68-
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
69-
crossorigin=""/>
70-
71-
<!-- Make sure you put this AFTER Leaflet's CSS -->
72-
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
73-
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
74-
crossorigin=""></script>
75-
<% end %>
7666

7767
<div id="map" style="height: 180px"></div>
7868
<script>

app/views/record/view.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
<% if @record.nil? %>
1010
<%= render('record_empty') %>
1111
<% elsif Flipflop.enabled?(:gdt) %>
12+
<% content_for :additional_meta_tag do %>
13+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
14+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
15+
crossorigin=""/>
16+
17+
<!-- Make sure you put this AFTER Leaflet's CSS -->
18+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
19+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
20+
crossorigin=""></script>
21+
<% end %>
22+
1223
<%= render('record_geo') %>
1324
<% else %>
1425
<%= render('record') %>

app/views/search/_result_geo.html.erb

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,8 @@
2424

2525
<!-- We only care about geospatial locations for this, as place names are also subjects. -->
2626
<% if geospatial_coordinates?(result_geo['locations']) %>
27-
<% content_for :additional_meta_tag do %>
28-
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
29-
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
30-
crossorigin=""/>
31-
32-
<!-- Make sure you put this AFTER Leaflet's CSS -->
33-
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
34-
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
35-
crossorigin=""></script>
36-
<% end %>
37-
<div id=<%= "map_#{result_geo_counter}" %> style="height: 180px"></div>
38-
39-
<script>
40-
var <%= "map_#{result_geo_counter}" %> = L.map('<%= "map_#{result_geo_counter}" %>');
41-
42-
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
43-
maxZoom: 19,
44-
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
45-
}).addTo(<%= "map_#{result_geo_counter}" %>);
46-
47-
// define rectangle geographical bounds
48-
// -71.158693, -71.064796, 42.395972, 42.351993
49-
// var bounds = [[42.395972, -71.158693],[42.351993, -71.064796]];
50-
51-
console.log('#<%= bounding_box_to_coords(result_geo) %>');
52-
var bounds = <%= bounding_box_to_coords(result_geo) %>;
53-
54-
// create an orange rectangle
55-
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(<%= "map_#{result_geo_counter}" %>);
56-
57-
// zoom the map to the rectangle bounds
58-
<%= "map_#{result_geo_counter}" %>.fitBounds(bounds);
59-
</script>
27+
28+
<%= render partial: 'shared/map', locals: { result_geo_counter: result_geo_counter, result_geo: result_geo} %>
6029

6130
<p>
6231
<ul>

app/views/search/results.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<%= content_for(:title, results_page_title(@enhanced_query)) %>
22

3+
<% content_for :additional_meta_tag do %>
4+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
5+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
6+
crossorigin=""/>
7+
8+
<!-- Make sure you put this AFTER Leaflet's CSS -->
9+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
10+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
11+
crossorigin=""></script>
12+
<% end %>
13+
314
<div class="space-wrap">
415

516
<%= render partial: "shared/site_title" %>

app/views/shared/_map.html.erb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div id=<%= "map_#{result_geo_counter}" %> style="height: 180px"></div>
2+
3+
<script>
4+
var <%= "map_#{result_geo_counter}" %> = L.map('<%= "map_#{result_geo_counter}" %>');
5+
6+
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
7+
maxZoom: 19,
8+
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
9+
}).addTo(<%= "map_#{result_geo_counter}" %>);
10+
11+
// define rectangle geographical bounds
12+
var bounds = <%= bounding_box_to_coords(result_geo) %>;
13+
14+
// console.log(bounds);
15+
16+
// create an orange rectangle
17+
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(<%= "map_#{result_geo_counter}" %>);
18+
19+
// zoom the map to the rectangle bounds
20+
<%= "map_#{result_geo_counter}" %>.fitBounds(bounds);
21+
</script>

0 commit comments

Comments
 (0)