Skip to content

Commit

Permalink
slight modifications to iiif-viewer pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Dec 9, 2014
1 parent 15e2a3e commit fbaa06d
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 60 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/geoblacklight/geoblacklight.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param {String} bbox Space-separated string of sw-lng sw-lat ne-lng ne-lat
* @return {L.LatLngBounds} Converted Leaflet LatLngBounds object
*/
L.bboxToBounds = function(bbox) {
L.bboxToBounds = function(bbox) {
bbox = bbox.split(' ');
if (bbox.length === 4) {
return L.latLngBounds([[bbox[1], bbox[0]], [bbox[3], bbox[2]]]);
Expand Down Expand Up @@ -38,4 +38,4 @@

global.GeoBlacklight = GeoBlacklight;

}(this);
}(this);
15 changes: 4 additions & 11 deletions app/assets/javascripts/geoblacklight/modules/home.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
Blacklight.onLoad(function () {
Blacklight.onLoad(function() {
$('[data-map="home"]').each(function(i, element) {
var options = {
/**
* Initial bounds of map
* @type {L.LatLngBounds}
*/
bbox: [[-85, -180], [85, 180]]
};

var geoblacklight = new GeoBlacklight.Viewer.Leaflet(this, options),
var geoblacklight = new GeoBlacklight.Viewer.Leaflet(this),
data = $(this).data();
geoblacklight.map.addControl(L.control.geosearch({
baseUrl: data.catalogPath,
dynamic: false,
searcher: function() {
window.location.href = this.getSearchUrl();
window.location.href = this.getSearchUrl();
},
staticButton: '<a class="btn btn-primary">Search Here</a>'
}));
});
});
});
13 changes: 6 additions & 7 deletions app/assets/javascripts/geoblacklight/modules/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ Blacklight.onLoad(function() {
var viewerName = $(element).data().protocol;
viewerName = viewerName.charAt(0).toUpperCase() + viewerName.substring(1);

// get new viewer instance from modulejs and pass in element
// get new viewer instance and pass in element
try {
var viewer = new window["GeoBlacklight"]["Viewer"][viewerName](element);
// viewer.load();
} catch(err) {
var viewer = new window['GeoBlacklight']['Viewer'][viewerName](element);
} catch (err) {
console.info('Error loading viewer');
};
}
});

$('.truncate-abstract').readmore({
maxHeight: 60
maxHeight: 60
});
});
});
10 changes: 5 additions & 5 deletions app/assets/javascripts/geoblacklight/viewers/iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

GeoBlacklight.Viewer.Iiif = GeoBlacklight.Viewer.extend({
load: function() {
this.osd_config = {
this.osdConfig = {
id: this.element.id,
prefixUrl: "/assets/osd/",
prefixUrl: '/assets/osd/',
preserveViewport: true,
showNavigator: false,
visibilityRatio: 1,
Expand All @@ -14,15 +14,15 @@ GeoBlacklight.Viewer.Iiif = GeoBlacklight.Viewer.extend({
};

this.adjustLayout();
OpenSeadragon(this.osd_config);
OpenSeadragon(this.osdConfig);
},

adjustLayout: function() {

// hide attribute table
$("#table-container").hide();
$('#table-container').hide();

// expand viewer element
$(this.element).parent().attr('class', 'col-md-12');
}
});
});
23 changes: 17 additions & 6 deletions app/assets/javascripts/geoblacklight/viewers/leaflet.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
//= require geoblacklight/viewers/viewer.js

GeoBlacklight.Viewer.Leaflet = GeoBlacklight.Viewer.extend({

options: {
/**
* Initial bounds of map
* @type {L.LatLngBounds}
*/
bbox: [[-85, -180], [85, 180]]
},

basemap: L.tileLayer(
'https://otile{s}-s.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="//developer.mapquest.com/content/osm/mq_logo.png">',
maxZoom: 18,
worldCopyJump: true,
subdomains: '1234' // see http://developer.mapquest.com/web/products/open/map
attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="//developer.mapquest.com/content/osm/mq_logo.png">',
maxZoom: 18,
worldCopyJump: true,
subdomains: '1234' // see http://developer.mapquest.com/web/products/open/map
}
),

Expand All @@ -16,7 +25,9 @@ GeoBlacklight.Viewer.Leaflet = GeoBlacklight.Viewer.extend({
this.map = L.map(this.element).fitBounds(this.options.bbox);
this.map.addLayer(this.basemap);
this.map.addLayer(this.overlay);
this.addBoundsOverlay(this.options.bbox);
if (this.data.map !== 'index') {
this.addBoundsOverlay(this.options.bbox);
}
},

/**
Expand All @@ -40,4 +51,4 @@ GeoBlacklight.Viewer.Leaflet = GeoBlacklight.Viewer.extend({
removeBoundsOverlay: function() {
this.overlay.clearLayers();
}
});
});
6 changes: 3 additions & 3 deletions app/assets/javascripts/geoblacklight/viewers/viewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// base viewer
GeoBlacklight.Viewer = L.Class.extend({
// base viewer
GeoBlacklight.Viewer = L.Class.extend({
options: {},

initialize: function(el, options) {
Expand All @@ -11,4 +11,4 @@
// trigger viewer load function
this.load();
}
});
});
4 changes: 2 additions & 2 deletions app/assets/javascripts/geoblacklight/viewers/wms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ GeoBlacklight.Viewer.Wms = GeoBlacklight.Viewer.Leaflet.extend({
if (this.data.available) {
this.addPreviewLayer();
this.addOpacityControl();
} else {
} else {
this.addBoundsOverlay(this.options.bbox);
};
}
},

addPreviewLayer: function() {
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_show_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class='row'>
<div id='viewer-container' class="col-md-8">
<%= content_tag :div, id: 'map', data: { map: 'item', 'protocol' => document.viewer[:protocol], 'url' => document.viewer[:endpoint], 'layer-id' => document[:layer_id_s], 'map-bbox' => document[:solr_bbox], 'catalog-path'=> catalog_index_path, available: document_available? } do %>
<%= content_tag :div, id: 'map', data: { map: 'item', protocol: document.viewer_protocol, url: document.viewer_endpoint, 'layer-id' => document[:layer_id_s], 'map-bbox' => document[:solr_bbox], 'catalog-path'=> catalog_index_path, available: document_available? } do %>
<% end %>
</div>
<div id='table-container' class='col-md-4'><div id='attribute-table' ></div></div>
Expand Down
1 change: 1 addition & 0 deletions lib/geoblacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Geoblacklight
require 'geoblacklight/controller_override'
require 'geoblacklight/exceptions'
require 'geoblacklight/view_helper_override'
require 'geoblacklight/item_viewer'
require 'geoblacklight/solr_document'
require 'geoblacklight/wms_layer'
require 'geoblacklight/download'
Expand Down
29 changes: 29 additions & 0 deletions lib/geoblacklight/item_viewer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Geoblacklight
class ItemViewer
def initialize(references)
@references = references
end

def viewer_protocol
return 'leaflet' if viewer_preference.nil?
viewer_preference.keys.first.to_s
end

def viewer_endpoint
return '' if viewer_preference.nil?
viewer_preference.values.first.to_s
end

def wms
@references.wms
end

def iiif
@references.iiif
end

def viewer_preference
[wms, iiif].compact.map(&:to_hash).first
end
end
end
10 changes: 0 additions & 10 deletions lib/geoblacklight/references.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,5 @@ def downloads_by_format
def download_types
downloads_by_format
end

def viewer_protocol
if !wms.blank?
wms.to_hash
elsif !iiif.blank?
iiif.to_hash
else
{:leaflet => ''}
end
end
end
end
6 changes: 4 additions & 2 deletions lib/geoblacklight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module SolrDocument
extend Blacklight::Solr::Document

delegate :download_types, to: :references
delegate :viewer_protocol, to: :item_viewer
delegate :viewer_endpoint, to: :item_viewer

def available?
public? || same_institution?
Expand Down Expand Up @@ -37,8 +39,8 @@ def same_institution?
get(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
end

def viewer
{ protocol: references.viewer_protocol.keys.first.to_s, endpoint: references.viewer_protocol.values.first }
def item_viewer
ItemViewer.new(references)
end

def itemtype
Expand Down
40 changes: 40 additions & 0 deletions spec/lib/geoblacklight/item_viewer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

describe Geoblacklight::ItemViewer do
let(:document) { SolrDocument.new(document_attributes) }
let(:document_attributes) { {} }
let(:references) { document.references }
let(:item_viewer) { Geoblacklight::ItemViewer.new(references) }
describe 'viewer_preference' do
describe 'for no references' do
it 'returns nil' do
expect(item_viewer.viewer_preference).to be_nil
end
end
describe 'for wms reference' do
let(:document_attributes) {
{
dct_references_s: {
'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://www.example.com/wms',
'http://iiif.io/api/image' => 'http://www.example.com/iiif'
}.to_json
}
}
it 'wms if wms is present' do
expect(item_viewer.viewer_preference).to eq wms: 'http://www.example.com/wms'
end
end
describe 'for iiif only reference' do
let(:document_attributes) {
{
dct_references_s: {
'http://iiif.io/api/image' => 'http://www.example.com/iiif'
}.to_json
}
}
it 'returns iiif' do
expect(item_viewer.viewer_preference).to eq iiif: 'http://www.example.com/iiif'
end
end
end
end
12 changes: 6 additions & 6 deletions spec/lib/geoblacklight/references_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@
end
end
describe 'viewer_protocol' do
it 'should return iiif hash if iiif ref type is present' do
expect(simple_iiif_image.viewer_protocol[:iiif]).to eq 'http://libimages.princeton.edu/loris2/pudl0076%2Fmap_pownall%2F00000001.jp2/info.json'
end
it 'should return wms hash if wms ref type is present' do
expect(typical_ogp_shapefile.viewer_protocol[:wms]).to eq 'http://hgl.harvard.edu:8080/geoserver/wms'
end
# it 'should return iiif hash if iiif ref type is present' do
# expect(simple_iiif_image.viewer_protocol[:iiif]).to eq 'http://libimages.princeton.edu/loris2/pudl0076%2Fmap_pownall%2F00000001.jp2/info.json'
# end
# it 'should return wms hash if wms ref type is present' do
# expect(typical_ogp_shapefile.viewer_protocol[:wms]).to eq 'http://hgl.harvard.edu:8080/geoserver/wms'
# end
end
end
34 changes: 29 additions & 5 deletions spec/lib/geoblacklight/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,31 @@
expect(document.direct_download).to be_nil
end
end
describe 'viewer' do
describe 'item_viewer' do
let(:document_attributes) { {} }
it 'is a ItemViewer' do
expect(document.item_viewer).to be_an Geoblacklight::ItemViewer
end
end
describe 'viewer_protocol' do
describe 'with a wms reference' do
let(:document_attributes) {
{
dct_references_s: {
'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://www.example.com/wms'
}.to_json
}
}
it 'returns wms protocol' do
expect(document.viewer_protocol).to eq 'wms'
end
end
let(:document_attributes) { {} }
it 'returns leaflet protocol' do
expect(document.viewer_protocol).to eq 'leaflet'
end
end
describe 'viewer_endpoint' do
describe 'with a wms reference' do
let(:document_attributes) {
{
Expand All @@ -96,12 +119,13 @@
}.to_json
}
}
it 'returns wms viewer endpoint' do
expect(document.viewer[:endpoint]).to eq 'http://www.example.com/wms'
it 'returns wms endpoint' do
expect(document.viewer_endpoint).to eq 'http://www.example.com/wms'
end
end
it 'returns leaflet as default if no viewer' do
expect(document.viewer[:protocol]).to eq 'leaflet'
let(:document_attributes) { {} }
it 'returns no endpoint' do
expect(document.viewer_endpoint).to eq ''
end
end
describe 'checked_endpoint' do
Expand Down

0 comments on commit fbaa06d

Please sign in to comment.