Skip to content

Commit

Permalink
Merge pull request #2119 from sul-dlss/2118-geojson
Browse files Browse the repository at this point in the history
add geojson files to be identified as an index map
  • Loading branch information
edsu committed Mar 5, 2024
2 parents 0cd27d5 + 1a39ce4 commit 4452c84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/viewers/embed/viewer/geo.rb
Expand Up @@ -33,7 +33,7 @@ def self.show_download?
end

def index_map
purl_object.contents.map(&:files).flatten.find { |file| file.title == 'index_map.json' }
purl_object.contents.map(&:files).flatten.find { |file| index_map_files.include? file.title }
end

def index_map?
Expand All @@ -57,6 +57,10 @@ def external_url_text

private

def index_map_files
%w[index_map.geojson index_map.json]
end

def default_height
493
end
Expand Down
42 changes: 30 additions & 12 deletions spec/features/geo_viewer_spec.rb
Expand Up @@ -87,7 +87,7 @@
build(:resource, :file, files: [
build(:resource_file, filename: 'data.zip'),
build(:resource_file, filename: 'data_EPSG_4326.zip'),
build(:resource_file, druid: 'ts545zc6250', filename: 'index_map.json')
build(:resource_file, druid: 'ts545zc6250', filename:)
]),
build(:resource, :image)
])
Expand All @@ -97,17 +97,35 @@
visit_iframe_response 'ts545zc6250'
end

describe 'loads viewer' do
it 'shows the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css '[data-index-map="https://stacks.stanford.edu/file/druid:ts545zc6250/index_map.json"]'
# only count paths within .leaflet-overlay-pane for testing
# (page.body contains SVG logos we don't care to count)
find '.leaflet-overlay-pane'
expect(Nokogiri::HTML.parse(page.body).search('.leaflet-overlay-pane').css('path').length).to eq 480
context 'when index_map.json' do
let(:filename) { 'index_map.json' }

describe 'loads viewer' do
it 'shows the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css "[data-index-map=\"https://stacks.stanford.edu/file/druid:ts545zc6250/#{filename}\"]"
# only count paths within .leaflet-overlay-pane for testing
# (page.body contains SVG logos we don't care to count)
find '.leaflet-overlay-pane'
expect(Nokogiri::HTML.parse(page.body).search('.leaflet-overlay-pane').css('path').length).to eq 480
end
end
end

context 'when index_map.geojson' do
let(:filename) { 'index_map.geojson' }

describe 'loads viewer' do
it 'lists the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css "[data-index-map=\"https://stacks.stanford.edu/file/druid:ts545zc6250/#{filename}\"]"
end
end
end
end
Expand Down

0 comments on commit 4452c84

Please sign in to comment.