Skip to content

Holy heck this might work? #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
@@ -146,6 +146,39 @@ def deduplicate_subjects(subjects)
subjects.map { |subject| subject['value'].uniq(&:downcase) }.uniq { |values| values.map(&:downcase) }
end

# Converts a bounding box into a top left, bottom right set of coordinates
def bounding_box_to_coords(record)
return unless record.present?
return unless geospatial_coordinates?(record['locations'])

# Our preference is to use the `Bounding Box` kind
raw_bbox = record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first

# If we had no `Bounding Box` kind, see if we have a `Geometry kind`
if raw_bbox.blank?
raw_bbox = record['locations'].select { |l| l if l['kind'] == 'Geometry' }.first
end

return unless raw_bbox.present?

# extract just the geo coordinates and remove the extra syntax
bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')

# conver the string into an array of floats
bbox_array = bbox.split(',').map!(&:strip).map!(&:to_f)

# Protect against unexpected data
if bbox_array.count != 4
Rails.logger.info("Unexpected Bounding Box: #{raw_bbox}")
return
end

coords = [[bbox_array[2], bbox_array[0]], [bbox_array[3], bbox_array[1]]]
Rails.logger.info("Raw BBox: #{raw_bbox}")
Rails.logger.info("Rectangle: #{coords}")
coords
end

private

def render_kind_value(list)
28 changes: 28 additions & 0 deletions app/javascript/controllers/map_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// app/javascript/controllers/map_controller.js
import { Controller } from "@hotwired/stimulus"
// import L from 'leaflet'
export default class extends Controller {
static values = {
coords: Array,
id: String
}
connect() {
// Map logic goes here
// console.log(this.identifier)
// console.log(this.coordsValue)
// console.log(this.idValue)

var map = L.map(this.idValue);

L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

// create an orange rectangle
L.rectangle(this.coordsValue, {color: "#ff7800", weight: 1}).addTo(map);

// // zoom the map to the rectangle bounds
map.fitBounds(this.coordsValue);
}
}
20 changes: 20 additions & 0 deletions app/models/timdex_search.rb
Original file line number Diff line number Diff line change
@@ -67,6 +67,11 @@ class TimdexSearch < TimdexBase
text
url
}
locations {
geoshape
kind
value
}
notes {
kind
value
@@ -199,6 +204,11 @@ class TimdexSearch < TimdexBase
text
url
}
locations {
geoshape
kind
value
}
notes {
kind
value
@@ -325,6 +335,11 @@ class TimdexSearch < TimdexBase
text
url
}
locations {
geoshape
kind
value
}
notes {
kind
value
@@ -461,6 +476,11 @@ class TimdexSearch < TimdexBase
text
url
}
locations {
geoshape
kind
value
}
notes {
kind
value
28 changes: 16 additions & 12 deletions app/views/record/_record_geo.html.erb
Original file line number Diff line number Diff line change
@@ -60,6 +60,22 @@
<% end %>
<% end %>

<!-- We only care about geospatial locations for this, as place names are also subjects. -->
<% if geospatial_coordinates?(@record['locations']) %>
<h3 class="section-title">Geospatial coordinates</h3>

<div id="map" style="height: 180px" data-controller="map" data-map-coords-value=<%= bounding_box_to_coords(@record).to_json %> data-map-id-value="map"></div>
<p>
<ul>
<% parse_nested_field(@record['locations']).each do |location| %>
<% if location['geoshape'].present? %>
<li><%= "#{location['kind']}: #{location['geoshape']}" %></li>
<% end %>
<% end %>
</ul>
</p>
<% end %>

<% if @record['subjects'].present? %>
<h3 class="section-title">Subjects</h3>
<ul>
@@ -69,18 +85,6 @@
</ul>
<% end %>

<!-- We only care about geospatial locations for this, as place names are also subjects. -->
<% if geospatial_coordinates?(@record['locations']) %>
<h3 class="section-title">Geospatial coordinates</h3>
<ul>
<% parse_nested_field(@record['locations']).each do |location| %>
<% if location['geoshape'].present? %>
<li><%= "#{location['kind']}: #{location['geoshape']}" %></li>
<% end %>
<% end %>
</ul>
<% end %>

<% if @record['notes'].present? %>
<h3 class="section-title">Notes</h3>
<ul>
11 changes: 11 additions & 0 deletions app/views/record/view.html.erb
Original file line number Diff line number Diff line change
@@ -9,6 +9,17 @@
<% if @record.nil? %>
<%= render('record_empty') %>
<% elsif Flipflop.enabled?(:gdt) %>
<% content_for :additional_meta_tag do %>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>

<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<% end %>

<%= render('record_geo') %>
<% else %>
<%= render('record') %>
17 changes: 17 additions & 0 deletions app/views/search/_result_geo.html.erb
Original file line number Diff line number Diff line change
@@ -21,6 +21,23 @@
</p>
<% end %>


<!-- We only care about geospatial locations for this, as place names are also subjects. -->
<% if geospatial_coordinates?(result_geo['locations']) %>

<div id=<%= "map_#{result_geo_counter}" %> style="height: 180px" data-controller="map" data-map-coords-value=<%= bounding_box_to_coords(result_geo).to_json %> data-map-id-value=<%= "map_#{result_geo_counter}" %>></div>

<p>
<ul>
<% parse_nested_field(result_geo['locations']).each do |location| %>
<% if location['geoshape'].present? %>
<li><%= "#{location['kind']}: #{location['geoshape']}" %></li>
<% end %>
<% end %>
</ul>
</p>
<% end %>

<% if result_geo['highlight'] %>
<div class="result-highlights">
<%= render partial: 'search/highlights', locals: { result: result_geo } %>
11 changes: 11 additions & 0 deletions app/views/search/results.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<%= content_for(:title, results_page_title(@enhanced_query)) %>

<% content_for :additional_meta_tag do %>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>

<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<% end %>

<div class="space-wrap">

<%= render partial: "shared/site_title" %>
1 change: 1 addition & 0 deletions app/views/shared/_map.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@