diff --git a/app/controllers/record_controller.rb b/app/controllers/record_controller.rb index f54baf7e..14e3eecc 100644 --- a/app/controllers/record_controller.rb +++ b/app/controllers/record_controller.rb @@ -16,44 +16,11 @@ def view # Manipulation of returned record would go here... @record = response&.data&.to_h&.dig('recordId') - @rectangle = bounding_box_to_coords + @rectangle = bounding_box_to_coords(@record) end private - # Converts a bounding box into a top left, bottom right set of coordinates - def bounding_box_to_coords - 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 - def validate_id! return if params[:id]&.strip.present? diff --git a/app/helpers/record_helper.rb b/app/helpers/record_helper.rb index 142ef5d6..2a86b92b 100644 --- a/app/helpers/record_helper.rb +++ b/app/helpers/record_helper.rb @@ -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) diff --git a/app/models/timdex_search.rb b/app/models/timdex_search.rb index c2dd9ee5..5520098a 100644 --- a/app/models/timdex_search.rb +++ b/app/models/timdex_search.rb @@ -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 diff --git a/app/views/record/_record_geo.html.erb b/app/views/record/_record_geo.html.erb index 9c5b239e..f52ec753 100644 --- a/app/views/record/_record_geo.html.erb +++ b/app/views/record/_record_geo.html.erb @@ -77,6 +77,7 @@
+ <% end %> +
style="height: 180px">
+ + + +

+

+

+ <% else %> + Hallo + <% end %> + <% if result_geo['highlight'] %>
<%= render partial: 'search/highlights', locals: { result: result_geo } %>