blacklight_allmaps 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -24
  3. data/Rakefile +2 -1
  4. data/app/assets/javascripts/blacklight/allmaps/blacklight-allmaps.esm.js +26776 -0
  5. data/app/assets/javascripts/blacklight/allmaps/blacklight-allmaps.esm.js.map +1 -0
  6. data/app/assets/javascripts/blacklight/allmaps/blacklight-allmaps.js +26783 -0
  7. data/app/assets/javascripts/blacklight/allmaps/blacklight-allmaps.js.map +1 -0
  8. data/app/assets/stylesheets/blacklight/allmaps/base.scss +9 -0
  9. data/app/javascript/blacklight/allmaps/index.js +11 -0
  10. data/app/javascript/blacklight/allmaps/initialize_blacklight_map.js +44 -0
  11. data/app/javascript/blacklight/allmaps/initialize_geoblacklight_map.js +53 -0
  12. data/app/javascript/blacklight/allmaps/leaflet_layer_opacity.js +69 -0
  13. data/app/views/allmaps/show/_blacklight.html.erb +1 -211
  14. data/app/views/allmaps/show/_geoblacklight.html.erb +1 -45
  15. data/app/views/catalog/_blacklight_allmaps.html.erb +5 -0
  16. data/app/views/catalog/_show_allmaps_tabbed_viewer_container.html.erb +53 -0
  17. data/db/migrate/{20240307155110_create_solr_document_sidecars.rb → 20240307155110_create_solr_document_sidecar_allmaps.rb} +1 -1
  18. data/lib/blacklight/allmaps/tasks/index.rake +53 -4
  19. data/lib/blacklight/allmaps/version.rb +10 -1
  20. data/lib/blacklight/allmaps.rb +1 -0
  21. data/lib/generators/blacklight/allmaps/config_generator.rb +67 -5
  22. metadata +20 -13
  23. data/app/assets/stylesheets/blacklight_allmaps/application.css +0 -15
  24. data/app/javascripts/map_controller.js +0 -39
  25. data/app/views/catalog/_show_default_viewer_container.html.erb +0 -52
  26. data/app/views/catalog/_show_main_content.html.erb +0 -58
@@ -0,0 +1,9 @@
1
+ @charset "UTF-8";
2
+
3
+ // Blacklight::Allmaps
4
+ @import "leaflet";
5
+ @import "leaflet.fullscreen";
6
+ @import "leaflet.opacity";
7
+
8
+ #blacklight-allmaps-map { height: 400px; }
9
+ #geoblacklight-allmaps-map { height: 400px; }
@@ -0,0 +1,11 @@
1
+ import L from "leaflet";
2
+ import "leaflet-fullscreen";
3
+ import { WarpedMapLayer } from "@allmaps/leaflet"
4
+ import LayerOpacityControl from "leaflet_layer_opacity";
5
+
6
+
7
+ import { initializeGeoBlacklightMap } from "./initialize_geoblacklight_map";
8
+ initializeGeoBlacklightMap();
9
+
10
+ import { initializeBlacklightMap } from "./initialize_blacklight_map";
11
+ initializeBlacklightMap();
@@ -0,0 +1,44 @@
1
+ // initialize_blacklight_map.js
2
+ import L from 'leaflet';
3
+ import 'leaflet-fullscreen';
4
+ import LayerOpacityControl from 'leaflet_layer_opacity';
5
+ import { WarpedMapLayer } from '@allmaps/leaflet';
6
+
7
+ export function initializeBlacklightMap() {
8
+ document.addEventListener("DOMContentLoaded", () => {
9
+ if (document.getElementById("blacklight-allmaps-map") != null) {
10
+ const element = document.getElementById("blacklight-allmaps-map");
11
+ const allmaps_id = element.getAttribute("data-allmaps-id");
12
+ if (!element) return; // Exit if the element doesn't exist
13
+
14
+ const map = L.map("blacklight-allmaps-map", {
15
+ center: [0, 0],
16
+ zoom: 15,
17
+ zoomAnimationThreshold: 1
18
+ });
19
+
20
+ // Basemap and Attribution
21
+ L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
22
+ attribution: "&copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors",
23
+ maxZoom: 18
24
+ }).addTo(map);
25
+
26
+ // Fullscreen control
27
+ map.addControl(new L.Control.Fullscreen({
28
+ position: "topright"
29
+ }));
30
+
31
+ // Annotation URL assumes the ID is passed dynamically to this function
32
+ const annotationUrl = `https://annotations.allmaps.org/manifests/${allmaps_id}`;
33
+ const warpedMapLayer = new WarpedMapLayer(annotationUrl).addTo(map);
34
+
35
+ // Layer opacity control
36
+ map.addControl(new LayerOpacityControl(warpedMapLayer));
37
+
38
+ map.on("warpedmapadded", () => {
39
+ map.fitBounds(warpedMapLayer.getBounds());
40
+ });
41
+ }
42
+ });
43
+ }
44
+ // app/javascript/blacklight/allmaps/initialize_blacklight_map.js
@@ -0,0 +1,53 @@
1
+ // initialize_geoblacklight_map.js
2
+ import L from 'leaflet';
3
+ import 'leaflet-fullscreen';
4
+ import LayerOpacityControl from 'leaflet_layer_opacity';
5
+ import { WarpedMapLayer } from '@allmaps/leaflet';
6
+
7
+ export function initializeGeoBlacklightMap() {
8
+ document.addEventListener("DOMContentLoaded", () => {
9
+ if (document.getElementById("geoblacklight-allmaps-map") != null) {
10
+ const element = document.getElementById("geoblacklight-allmaps-map");
11
+ const allmaps_id = element.getAttribute("data-allmaps-id");
12
+ const geoTab = document.getElementById("georeferenced-tab");
13
+ if (!element) return; // Exit if the element doesn't exist
14
+
15
+ const map = L.map("geoblacklight-allmaps-map", {
16
+ center: [0, 0],
17
+ zoom: 15,
18
+ zoomAnimationThreshold: 1
19
+ });
20
+
21
+ // Basemap and Attribution
22
+ L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
23
+ attribution: "&copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors",
24
+ maxZoom: 18
25
+ }).addTo(map);
26
+
27
+ // Fullscreen control
28
+ map.addControl(new L.Control.Fullscreen({
29
+ position: "topright"
30
+ }));
31
+
32
+ // Annotation URL assumes the ID is passed dynamically to this function
33
+ const annotationUrl = `https://annotations.allmaps.org/manifests/${allmaps_id}`;
34
+ const warpedMapLayer = new WarpedMapLayer(annotationUrl).addTo(map);
35
+
36
+ // Layer opacity control
37
+ map.addControl(new LayerOpacityControl(warpedMapLayer));
38
+
39
+ // Watch DOM to see active tab and
40
+ // Resize map to render correctly
41
+ const observer = new MutationObserver(function() {
42
+ if (geoTab.style.display !== "none") {
43
+ map.invalidateSize();
44
+ warpedMapLayer.addTo(map);
45
+ map.fitBounds(warpedMapLayer.getBounds());
46
+ }
47
+ });
48
+
49
+ observer.observe(geoTab, { attributes: true });
50
+ }
51
+ });
52
+ }
53
+ // app/javascript/blacklight/allmaps/initialize_geoblacklight_map.js
@@ -0,0 +1,69 @@
1
+ // leaflet_layer_opacity.js
2
+ import L from 'leaflet';
3
+
4
+ class LayerOpacityControl extends L.Control {
5
+ initialize(layer) {
6
+ super.initialize();
7
+ let options = { position: 'topleft' };
8
+
9
+ // Check if the layer is actually a layer group and adjust accordingly
10
+ if (typeof layer.getLayers !== 'undefined') {
11
+ options.layer = layer.getLayers()[0];
12
+ } else {
13
+ options.layer = layer;
14
+ }
15
+
16
+ L.Util.setOptions(this, options);
17
+ }
18
+
19
+ onAdd(map) {
20
+ const container = L.DomUtil.create('div', 'opacity-control unselectable');
21
+ const controlArea = L.DomUtil.create('div', 'opacity-area', container);
22
+ const handle = L.DomUtil.create('div', 'opacity-handle', container);
23
+ const handleArrowUp = L.DomUtil.create('div', 'opacity-arrow-up', handle);
24
+ const handleText = L.DomUtil.create('div', 'opacity-text', handle);
25
+ const handleArrowDown = L.DomUtil.create('div', 'opacity-arrow-down', handle);
26
+ const bottom = L.DomUtil.create('div', 'opacity-bottom', container);
27
+
28
+ L.DomEvent.stopPropagation(container);
29
+ L.DomEvent.disableClickPropagation(container);
30
+
31
+ this.setListeners(handle, bottom, handleText);
32
+ handle.style.top = `${handle.offsetTop - 13 + 50}px`;
33
+ handleText.innerHTML = `${parseInt(this.options.layer.options.opacity * 100, 10)}%`;
34
+
35
+ return container;
36
+ }
37
+
38
+ setListeners(handle, bottom, handleText) {
39
+ let start = false;
40
+ let startTop;
41
+
42
+ L.DomEvent.on(document, 'mousemove', (e) => {
43
+ if (!start) return;
44
+ const percentInverse = Math.max(0, Math.min(200, startTop + parseInt(e.clientY, 10) - start)) / 2;
45
+ handle.style.top = `${(percentInverse * 2) - 13}px`;
46
+ handleText.innerHTML = `${Math.round((1 - (percentInverse / 100)) * 100)}%`;
47
+ bottom.style.height = `${Math.max(0, ((100 - percentInverse) * 2) - 13)}px`;
48
+ bottom.style.top = `${Math.min(200, (percentInverse * 2) + 13)}px`;
49
+ this.options.layer.setOpacity(1 - (percentInverse / 100));
50
+ });
51
+
52
+ L.DomEvent.on(handle, 'mousedown', (e) => {
53
+ start = parseInt(e.clientY, 10);
54
+ startTop = handle.offsetTop - 12;
55
+ return false;
56
+ });
57
+
58
+ L.DomEvent.on(document, 'mouseup', () => {
59
+ start = null;
60
+ });
61
+ }
62
+ }
63
+
64
+ // Extend Leaflet's control factory to include this new control
65
+ L.Control.layerOpacity = function(layer, options) {
66
+ return new LayerOpacityControl(layer, options);
67
+ };
68
+
69
+ export default LayerOpacityControl;
@@ -1,213 +1,3 @@
1
1
  <!-- Georeferenced Map -->
2
2
  <h3 class="h6">Georeferenced Map</h3>
3
- <div id="allmaps-map" class="mt-3 mb-3" style="height: 400px;"></div>
4
-
5
- <!-- Leaflet -->
6
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.min.css">
7
- <script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.min.js"></script>
8
-
9
- <!-- Leaflet Fullscreen -->
10
- <script src="https://cdn.jsdelivr.net/npm/leaflet-fullscreen@1.0.2/dist/Leaflet.fullscreen.min.js"></script>
11
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-fullscreen@1.0.2/dist/leaflet.fullscreen.min.css">
12
-
13
- <!-- Leaflet Layer Opacity -->
14
- <script>
15
- // Adopts the Mapbox opacity control into a Leaflet plugin
16
-
17
- !function(global) {
18
- 'use strict';
19
-
20
- L.Control.LayerOpacity = L.Control.extend({
21
- initialize: function(layer) {
22
- var options = { position: 'topleft' };
23
-
24
- // check if layer is actually a layer group
25
- if (typeof layer.getLayers !== 'undefined') {
26
-
27
- // add first layer from layer group to options
28
- options.layer = layer.getLayers()[0];
29
- } else {
30
-
31
- // add layer to options
32
- options.layer = layer;
33
- }
34
-
35
- L.Util.setOptions(this, options);
36
- },
37
-
38
- onAdd: function(map) {
39
- var container = L.DomUtil.create('div', 'opacity-control unselectable'),
40
- controlArea = L.DomUtil.create('div', 'opacity-area', container),
41
- handle = L.DomUtil.create('div', 'opacity-handle', container),
42
- handleArrowUp = L.DomUtil.create('div', 'opacity-arrow-up', handle),
43
- handleText = L.DomUtil.create('div', 'opacity-text', handle),
44
- handleArrowDown = L.DomUtil.create('div', 'opacity-arrow-down', handle),
45
- bottom = L.DomUtil.create('div', 'opacity-bottom', container);
46
-
47
- L.DomEvent.stopPropagation(container);
48
- L.DomEvent.disableClickPropagation(container);
49
-
50
- this.setListeners(handle, bottom, handleText);
51
- handle.style.top = handle.offsetTop - 13 + 50 + 'px';
52
- handleText.innerHTML = parseInt(this.options.layer.options.opacity * 100) + '%';
53
- return container;
54
- },
55
-
56
- setListeners: function(handle, bottom, handleText) {
57
- var _this = this,
58
- start = false,
59
- startTop;
60
-
61
- L.DomEvent.on(document, 'mousemove', function(e) {
62
- if (!start) return;
63
- var percentInverse = Math.max(0, Math.min(200, startTop + parseInt(e.clientY, 10) - start)) / 2;
64
- handle.style.top = ((percentInverse * 2) - 13) + 'px';
65
- handleText.innerHTML = Math.round((1 - (percentInverse / 100)) * 100) + '%';
66
- bottom.style.height = Math.max(0, (((100 - percentInverse) * 2) - 13)) + 'px';
67
- bottom.style.top = Math.min(200, (percentInverse * 2) + 13) + 'px';
68
- _this.options.layer.setOpacity(1 - (percentInverse / 100));
69
- });
70
-
71
- L.DomEvent.on(handle, 'mousedown', function(e) {
72
- start = parseInt(e.clientY, 10);
73
- startTop = handle.offsetTop - 12;
74
- return false;
75
- });
76
-
77
- L.DomEvent.on(document, 'mouseup', function(e) {
78
- start = null;
79
- });
80
- }
81
- });
82
- }(this);
83
- </script>
84
- <style>
85
- .leaflet-control.opacity-control {
86
- background-color: #a9acb1;
87
- border-radius: 15px;
88
- color: black;
89
- font: bold 18px 'Lucida Console', Monaco, monospace;
90
- display: block;
91
- height: 200px;
92
- left: 11px;
93
- position: relative;
94
- top: 15px;
95
- width: 5px;
96
-
97
- .opacity-handle {
98
- background-color: #fff;
99
- border-radius: 4px;
100
- border: 1px solid #eee;
101
- cursor: ns-resize;
102
- font-size: 10px;
103
- height: 26px;
104
- left: -11px;
105
- line-height: 26px;
106
- position: absolute;
107
- text-align: center;
108
- top: 0;
109
- width: 26px;
110
- @include map-control-shadow;
111
-
112
- &:hover {
113
- background-color: #f4f4f4;
114
- }
115
- }
116
-
117
- .opacity-arrow-up {
118
- color: #aaa;
119
- position: absolute;
120
- top: -11px;
121
- text-align: center;
122
- width: 100%;
123
-
124
- &:before {
125
- content: '=';
126
- }
127
- }
128
-
129
- .opacity-arrow-down {
130
- bottom: -10px;
131
- color: #aaa;
132
- position: absolute;
133
- text-align: center;
134
- width: 100%;
135
-
136
- &:before {
137
- content: '=';
138
- }
139
- }
140
-
141
- .opacity-bottom {
142
- background-color: #017afd;
143
- border-radius: 15px;
144
- display: block;
145
- height: 137px;
146
- left: 0px;
147
- position: relative;
148
- top: 63px;
149
- width: 5px;
150
- }
151
-
152
- // Area underneath slider to prevent unintentioned map clicks
153
- .opacity-area {
154
- padding: 14px;
155
- cursor: default;
156
- height: 200px;
157
- left: -11px;
158
- position: absolute;
159
- top: 0px;
160
- width: 20px;
161
- }
162
- }
163
-
164
- .opacity-control.unselectable {
165
- -webkit-touch-callout: none;
166
- -webkit-user-select: none;
167
- -khtml-user-select: none;
168
- -moz-user-select: none;
169
- -ms-user-select: none;
170
- user-select: none;
171
- }
172
- </style>
173
-
174
- <!-- Allmaps -->
175
- <script src="https://cdn.jsdelivr.net/npm/@allmaps/leaflet/dist/bundled/allmaps-leaflet-1.9.umd.js"></script>
176
-
177
- <script>
178
- document.addEventListener("DOMContentLoaded", () => {
179
- const element = document.getElementById("allmaps-map");
180
-
181
- const map = L.map("allmaps-map", {
182
- center: [0, 0],
183
- zoom: 15,
184
- zoomAnimationThreshold: 1
185
- });
186
-
187
- // Basemap and Attribution
188
- L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
189
- attribution: "&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
190
- maxZoom: 18
191
- }).addTo(map);
192
-
193
- // Fullscreen control
194
- map.addControl(new L.Control.Fullscreen({
195
- position: "topright"
196
- }));
197
-
198
- const annotationUrl = "https://annotations.allmaps.org/manifests/<%= document.sidecar_allmaps.allmaps_id %>";
199
- const warpedMapLayer = new Allmaps.WarpedMapLayer(annotationUrl)
200
- .addTo(map);
201
-
202
- // Layer opacity control
203
- map.addControl(new L.Control.LayerOpacity(warpedMapLayer));
204
-
205
- map.on(
206
- "warpedmapadded",
207
- (event) => {
208
- map.fitBounds(warpedMapLayer.getBounds());
209
- },
210
- map
211
- );
212
- });
213
- </script>
3
+ <div id="blacklight-allmaps-map" data-allmaps-id="<%= document.sidecar_allmaps.allmaps_id %>" class="mt-3 mb-3"></div>
@@ -1,47 +1,3 @@
1
1
  <!-- Georeferenced Map -->
2
2
  <h3 class="h6">Georeferenced Map</h3>
3
- <div id="allmaps-map" data-map-geom="<%= document.geometry.geojson %>" style="height: 400px;"></div>
4
-
5
- <script src="https://cdn.jsdelivr.net/npm/@allmaps/leaflet/dist/bundled/allmaps-leaflet-1.9.umd.js"></script>
6
- <script>
7
- document.addEventListener("DOMContentLoaded", () => {
8
- const element = document.getElementById("allmaps-map");
9
- const value = element.getAttribute("data-map-geom");
10
- const layer = L.geoJSON();
11
- layer.addData(JSON.parse(value));
12
- const bounds = layer.getBounds();
13
- const annotationUrl = "https://annotations.allmaps.org/manifests/<%= document.sidecar_allmaps.allmaps_id %>";
14
- const warpedMapLayer = new Allmaps.WarpedMapLayer(annotationUrl);
15
- const geoTab = document.getElementById("georeferenced-tab");
16
- const map = L.map("allmaps-map");
17
-
18
- // Basemap and Attribution
19
- L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
20
- attribution: "&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
21
- maxZoom: 18
22
- }).addTo(map);
23
-
24
- // Fullscreen control
25
- map.addControl(new L.Control.Fullscreen({
26
- position: "topright"
27
- }));
28
-
29
- // Layer opacity control
30
- map.addControl(new L.Control.LayerOpacity(warpedMapLayer));
31
-
32
- // Leaflet: Multiple maps on the same page is a challenge...
33
- // 1. Need to watch the page DOM mutate
34
- // 2. When the georeferenced tab is visible, invalidate the map size
35
- // 3. Add the WarpedMapLayer to the map
36
- // 4. Fit the map to the GeoJSON bounds
37
- const observer = new MutationObserver(function(){
38
- if(geoTab.style.display !== "none"){
39
- map.invalidateSize();
40
- warpedMapLayer.addTo(map);
41
- map.fitBounds(bounds);
42
- }
43
- });
44
-
45
- observer.observe(geoTab, { attributes: true });
46
- });
47
- </script>
3
+ <div id="geoblacklight-allmaps-map" data-map-geom="<%= document.geometry.geojson %>" data-allmaps-id="<%= document.sidecar_allmaps.allmaps_id %>"></div>
@@ -0,0 +1,5 @@
1
+ <% unless defined?(Geoblacklight) %>
2
+ <% if @document.sidecar_allmaps.georeferenced? %>
3
+ <%= render partial: 'allmaps/show/blacklight', locals: { document: @document } %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,53 @@
1
+ <% document ||= @document %>
2
+ <div class='row'>
3
+ <div id='viewer-container' class="col-md-12">
4
+
5
+ <span class="sr-only">Georeferenced: <%= document.sidecar_allmaps.georeferenced? %></span>
6
+
7
+ <ul class="nav nav-tabs mt-3" id="myTab" role="tablist">
8
+ <li class="nav-item" role="presentation">
9
+ <button class="nav-link active" id="item-viewer" data-toggle="tab" data-target="#item-viewer-tab" type="button" role="tab" aria-controls="home" aria-selected="true">Item Viewer</button>
10
+ </li>
11
+ <% if document.sidecar_allmaps.georeferenced? %>
12
+ <li class="nav-item" role="presentation">
13
+ <button class="nav-link" id="georeferenced-viewer" data-toggle="tab" data-target="#georeferenced-tab" type="button" role="tab" aria-controls="profile" aria-selected="false">Georeferenced Map</button>
14
+ </li>
15
+ <% end %>
16
+ </ul>
17
+
18
+ <div class="tab-content mt-3">
19
+ <div class="tab-pane active" id="item-viewer-tab" role="tabpanel" aria-labelledby="item-viewer-tab">
20
+ <div id="viewer-wrapper">
21
+ <% if show_help_text?('viewer_protocol', document.viewer_protocol) %>
22
+ <%= render_help_text_entry('viewer_protocol', document.viewer_protocol) %>
23
+ <% end %>
24
+
25
+ <% if document.item_viewer.index_map %>
26
+ <div class="index-map-legend">
27
+ <div class="index-map-legend-info">
28
+ <span class="index-map-legend-default"></span>
29
+ <p><span class="sr-only">Green tile indicates </span>Map held by collection</p>
30
+ </div>
31
+ <div class="index-map-legend-info">
32
+ <span class="index-map-legend-unavailable"></span>
33
+ <p><span class="sr-only">Yellow tile indicates </span>Map not held by collection</p>
34
+ </div>
35
+ <div class="index-map-legend-info">
36
+ <span class="index-map-legend-selected"></span>
37
+ <p><span class="sr-only">Blue tile indicates </span>Selected map tile</p>
38
+ </div>
39
+ </div>
40
+ <% end %>
41
+
42
+ <%= viewer_container %>
43
+ </div>
44
+ </div>
45
+
46
+ <% if document.sidecar_allmaps.georeferenced? %>
47
+ <div class="tab-pane" id="georeferenced-tab" role="tabpanel" aria-labelledby="georeferenced-tab">
48
+ <%= render partial: 'allmaps/show/geoblacklight', locals: { document: document } %>
49
+ </div>
50
+ <% end %>
51
+ </div>
52
+ </div>
53
+ </div>
@@ -1,4 +1,4 @@
1
- class CreateSolrDocumentSidecars < ActiveRecord::Migration[7.0]
1
+ class CreateSolrDocumentSidecarAllmaps < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :blacklight_allmaps_sidecars do |t|
4
4
  t.string :solr_document_id, index: true
@@ -6,15 +6,14 @@ namespace :blacklight_allmaps do
6
6
  namespace :index do
7
7
  desc "Index - add Allmaps fixture data to Blacklight solr"
8
8
  task :bl_fixtures do
9
- # @TODO: JSON works when pasted into Solr, but fails here?
10
- docs = Dir["spec/fixtures/solr_documents/bl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
9
+ docs = Dir["#{Blacklight::Allmaps.root}/spec/fixtures/solr_documents/blacklight/bl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
11
10
  Blacklight.default_index.connection.add docs
12
11
  Blacklight.default_index.connection.commit
13
12
  end
14
13
 
15
14
  desc "Index - add Allmaps fixture data to GeoBlacklight solr"
16
15
  task :gbl_fixtures do
17
- docs = Dir["spec/fixtures/solr_documents/gbl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
16
+ docs = Dir["#{Blacklight::Allmaps.root}/spec/fixtures/solr_documents/geoblacklight/gbl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
18
17
  Blacklight.default_index.connection.add docs
19
18
  Blacklight.default_index.connection.commit
20
19
  end
@@ -44,7 +43,7 @@ namespace :blacklight_allmaps do
44
43
  response["response"]["docs"].each do |doc|
45
44
  # 2. Determine which documents have georeferenced data
46
45
  solr_document = SolrDocument.find(doc["id"])
47
- if solr_document.sidecar.present? && solr_document.sidecar.annotated?
46
+ if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?
48
47
 
49
48
  # 3. Clean JSON for re-indexing
50
49
  keys_for_deletion = %w[
@@ -73,5 +72,55 @@ namespace :blacklight_allmaps do
73
72
  end
74
73
  Blacklight.default_index.connection.commit
75
74
  end
75
+
76
+ desc "Index - add Allmaps facet data to Blacklight solr"
77
+ task bl_georeferenced_facet: [:environment] do
78
+ # Steps
79
+ # 1. Use cursor to paginate all documents in Solr
80
+ # 2. Determine which documents have georeferenced data
81
+ # 3. Clean JSON for re-indexing
82
+ # 4. Add bl_georeferenced_bsi values
83
+ # 5. Re-index the georeferenced documents
84
+
85
+ # 1. Get all the documents from Solr
86
+ cursor_mark = "*"
87
+ loop do
88
+ response = Blacklight.default_index.connection.get(
89
+ "select", params: {
90
+ q: "*:*", # all docs
91
+ fl: "*", # all fields
92
+ cursorMark: cursor_mark, # use the cursor mark to handle paging
93
+ rows: 1000,
94
+ sort: "id asc" # must sort by id to use the cursor mark
95
+ }
96
+ )
97
+
98
+ response["response"]["docs"].each do |doc|
99
+ # 2. Determine which documents have georeferenced data
100
+ solr_document = SolrDocument.find(doc["id"])
101
+ if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?
102
+
103
+ # 3. Clean JSON for re-indexing
104
+ keys_for_deletion = %w[
105
+ _version_
106
+ timestamp
107
+ ]
108
+
109
+ cleaned_doc = doc.except!(*keys_for_deletion)
110
+
111
+ # 4. Add gbl_georeferenced_b value
112
+ # @TODO: add allmaps_id?
113
+ cleaned_doc["bl_georeferenced_bsi"] = true
114
+
115
+ # 5. Re-index the georeferenced documents
116
+ Blacklight.default_index.connection.add cleaned_doc
117
+ end
118
+ end
119
+
120
+ break if response["nextCursorMark"] == cursor_mark # this means the result set is finished
121
+ cursor_mark = response["nextCursorMark"]
122
+ end
123
+ Blacklight.default_index.connection.commit
124
+ end
76
125
  end
77
126
  end
@@ -1,5 +1,14 @@
1
1
  module Blacklight
2
2
  module Allmaps
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
+
5
+ def self.version
6
+ @version ||= VERSION
7
+ end
8
+
9
+ # returns the full path the the plugin installation
10
+ def self.root
11
+ @root ||= File.expand_path(File.dirname(__FILE__, 4))
12
+ end
4
13
  end
5
14
  end
@@ -3,5 +3,6 @@ require "blacklight"
3
3
  module Blacklight
4
4
  module Allmaps
5
5
  require "blacklight/allmaps/engine"
6
+ require "blacklight/allmaps/version"
6
7
  end
7
8
  end