blacklight-maps 0.5.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +33 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +103 -0
- data/.solr_wrapper.yml +8 -0
- data/Gemfile +38 -8
- data/README.md +15 -13
- data/Rakefile +35 -32
- data/app/assets/images/blacklight/maps.svg +1 -0
- data/app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js +7 -8
- data/app/assets/javascripts/blacklight-maps.js +1 -4
- data/app/assets/stylesheets/blacklight_maps/blacklight-maps.scss +1 -2
- data/app/assets/stylesheets/blacklight_maps/default.scss +7 -10
- data/app/helpers/blacklight/blacklight_maps_helper_behavior.rb +81 -86
- data/app/helpers/blacklight_maps_helper.rb +2 -0
- data/app/views/catalog/_show_maplet_default.html.erb +8 -9
- data/app/views/catalog/map.html.erb +2 -2
- data/blacklight-maps.gemspec +27 -26
- data/config/locales/blacklight-maps-zh.yml +7 -7
- data/config/locales/blacklight-maps.ar.yml +21 -0
- data/config/locales/blacklight-maps.de.yml +21 -0
- data/config/locales/blacklight-maps.en.yml +1 -1
- data/config/locales/blacklight-maps.es.yml +21 -0
- data/config/locales/blacklight-maps.fr.yml +8 -8
- data/config/locales/blacklight-maps.hu.yml +21 -0
- data/config/locales/blacklight-maps.it.yml +8 -8
- data/config/locales/blacklight-maps.nl.yml +21 -0
- data/config/locales/blacklight-maps.pt-BR.yml +21 -0
- data/config/locales/blacklight-maps.sq.yml +21 -0
- data/config/routes.rb +3 -2
- data/lib/blacklight/maps/controller.rb +27 -0
- data/lib/blacklight/maps/engine.rb +15 -14
- data/lib/blacklight/maps/export.rb +114 -93
- data/lib/blacklight/maps/geometry.rb +30 -18
- data/lib/blacklight/maps/maps_search_builder.rb +4 -3
- data/lib/blacklight/maps/render_constraints_override.rb +63 -29
- data/lib/blacklight/maps/version.rb +3 -1
- data/lib/blacklight/maps.rb +8 -2
- data/lib/generators/blacklight_maps/install_generator.rb +38 -31
- data/lib/generators/blacklight_maps/templates/search_history_controller.rb +2 -0
- data/lib/railties/blacklight_maps.rake +10 -7
- data/spec/controllers/catalog_controller_spec.rb +20 -10
- data/spec/fixtures/sample_solr_documents.yml +909 -906
- data/spec/helpers/blacklight_maps_helper_spec.rb +60 -108
- data/spec/lib/blacklight/maps/export_spec.rb +109 -143
- data/spec/lib/blacklight/maps/geometry_spec.rb +34 -21
- data/spec/lib/blacklight/maps/maps_search_builder_spec.rb +17 -21
- data/spec/lib/blacklight/maps/render_constraints_override_spec.rb +42 -69
- data/spec/spec_helper.rb +18 -21
- data/spec/system/index_view_spec.rb +128 -0
- data/spec/system/initial_view_spec.rb +28 -0
- data/spec/system/map_view_spec.rb +50 -0
- data/spec/system/show_view_maplet_spec.rb +78 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -21
- data/vendor/assets/images/layers-2x.png +0 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/marker-icon-2x.png +0 -0
- data/vendor/assets/images/marker-icon.png +0 -0
- data/vendor/assets/images/marker-shadow.png +0 -0
- data/vendor/assets/javascripts/leaflet.js.erb +13922 -0
- data/vendor/assets/javascripts/leaflet.markercluster.js +3 -0
- data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
- data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
- data/vendor/assets/stylesheets/leaflet.css +635 -0
- metadata +85 -90
- data/.travis.yml +0 -25
- data/config/jetty.yml +0 -7
- data/lib/blacklight/maps/controller_override.rb +0 -20
- data/lib/generators/blacklight_maps/templates/saved_searches_controller.rb +0 -5
- data/spec/features/initial_view_spec.rb +0 -21
- data/spec/features/maps_spec.rb +0 -202
- data/spec/features/show_view_maplet_spec.rb +0 -93
- data/spec/test_app_templates/Gemfile.extra +0 -5
- /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/schema.xml +0 -0
- /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/solrconfig.xml +0 -0
@@ -1,170 +1,122 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe BlacklightMapsHelper do
|
5
|
-
|
6
|
+
let(:query_term) { 'Tibet' }
|
7
|
+
let(:mock_controller) { CatalogController.new }
|
6
8
|
let(:blacklight_config) { Blacklight::Configuration.new }
|
7
|
-
let(:
|
8
|
-
|
9
|
-
|
10
|
-
raw_response = eval(mock_query_response)
|
11
|
-
Blacklight::Solr::Response.new(raw_response, raw_response['params'])
|
9
|
+
let(:maps_config) { blacklight_config.view.maps }
|
10
|
+
let(:search_service) do
|
11
|
+
Blacklight::SearchService.new(config: blacklight_config, user_params: { q: query_term })
|
12
12
|
end
|
13
|
-
|
14
|
-
let(:
|
15
|
-
let(:geojson_hash) { { type: 'Feature', geometry: { type: 'Point', coordinates: [91.117212, 29.646923] }, properties: { placename: 'Tibet' } } }
|
13
|
+
let(:response) { search_service.search_results[0] }
|
14
|
+
let(:docs) { response.aggregations[maps_config.geojson_field].items }
|
16
15
|
let(:coords) { [91.117212, 29.646923] }
|
16
|
+
let(:geojson_hash) do
|
17
|
+
{ type: 'Feature', geometry: { type: 'Point', coordinates: coords }, properties: { placename: query_term } }
|
18
|
+
end
|
17
19
|
let(:bbox) { [78.3955448, 26.8548157, 99.116241, 36.4833345] }
|
18
20
|
|
19
|
-
before
|
21
|
+
before do
|
22
|
+
mock_controller.request = ActionDispatch::TestRequest.create
|
23
|
+
allow(helper).to receive_messages(controller: mock_controller, action_name: 'index')
|
20
24
|
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
allow(helper).to receive(:search_state).and_return(search_state)
|
26
|
-
@catalog.request = @request
|
27
|
-
@catalog.action_name = "index"
|
28
|
-
helper.instance_variable_set(:@_controller, @catalog)
|
29
|
-
@docs = r.aggregations[blacklight_config.view.maps.geojson_field].items
|
25
|
+
allow(helper).to receive_messages(blacklight_configuration_context: Blacklight::Configuration::Context.new(mock_controller))
|
26
|
+
allow(helper).to receive(:search_state).and_return Blacklight::SearchState.new({}, blacklight_config, mock_controller)
|
27
|
+
blacklight_config.add_facet_field 'geojson_ssim', limit: -2, label: 'GeoJSON', show: false
|
28
|
+
blacklight_config.add_facet_fields_to_solr_request!
|
30
29
|
end
|
31
30
|
|
32
|
-
describe
|
33
|
-
|
34
|
-
context "with default values" do
|
31
|
+
describe 'blacklight_map_tag' do
|
32
|
+
context 'with default values' do
|
35
33
|
subject { helper.blacklight_map_tag('blacklight-map') }
|
36
|
-
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
34
|
+
|
35
|
+
it { is_expected.to have_selector 'div#blacklight-map' }
|
36
|
+
it { is_expected.to have_selector "div[data-maxzoom='#{maps_config.maxzoom}']" }
|
37
|
+
it { is_expected.to have_selector "div[data-tileurl='#{maps_config.tileurl}']" }
|
38
|
+
it { is_expected.to have_selector "div[data-mapattribution='#{maps_config.mapattribution}']" }
|
40
39
|
end
|
41
40
|
|
42
|
-
context
|
43
|
-
|
44
|
-
|
41
|
+
context 'with custom values' do
|
42
|
+
subject { helper.blacklight_map_tag('blacklight-map', data: { maxzoom: 6, tileurl: 'http://example.com/', mapattribution: 'hello world' }) }
|
43
|
+
|
44
|
+
it { is_expected.to have_selector "div[data-maxzoom='6'][data-tileurl='http://example.com/'][data-mapattribution='hello world']" }
|
45
45
|
end
|
46
46
|
|
47
|
-
context
|
47
|
+
context 'when a block is provided' do
|
48
48
|
subject { helper.blacklight_map_tag('foo') { content_tag(:span, 'bar') } }
|
49
|
-
it { should have_selector('div > span', text: 'bar') }
|
50
|
-
end
|
51
49
|
|
50
|
+
it { is_expected.to have_selector('div > span', text: 'bar') }
|
51
|
+
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
|
56
|
-
|
57
|
-
expect(helper.serialize_geojson(@docs)).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
|
54
|
+
describe 'serialize_geojson' do
|
55
|
+
it 'returns geojson of documents' do
|
56
|
+
expect(helper.serialize_geojson(docs)).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
61
59
|
|
62
|
-
describe
|
63
|
-
|
64
|
-
|
65
|
-
expect(helper.placename_value(geojson_hash)).to eq('Tibet')
|
60
|
+
describe 'placename_value' do
|
61
|
+
it 'returns the placename value' do
|
62
|
+
expect(helper.placename_value(geojson_hash)).to eq(query_term)
|
66
63
|
end
|
67
|
-
|
68
64
|
end
|
69
65
|
|
70
|
-
describe
|
71
|
-
|
72
|
-
it "should create a spatial search link" do
|
66
|
+
describe 'link_to_bbox_search' do
|
67
|
+
it 'creates a spatial search link' do
|
73
68
|
expect(helper.link_to_bbox_search(bbox)).to include('catalog?coordinates')
|
74
69
|
expect(helper.link_to_bbox_search(bbox)).to include('spatial_search_type=bbox')
|
75
70
|
end
|
76
71
|
|
77
|
-
it
|
72
|
+
it 'includes the default_document_index_view_type in the params' do
|
78
73
|
expect(helper.link_to_bbox_search(bbox)).to include('view=list')
|
79
74
|
end
|
80
|
-
|
81
75
|
end
|
82
76
|
|
83
|
-
describe
|
77
|
+
describe 'link_to_placename_field' do
|
78
|
+
subject { helper.link_to_placename_field(query_term, maps_config.placename_field) }
|
84
79
|
|
85
|
-
it
|
86
|
-
|
87
|
-
end
|
80
|
+
it { is_expected.to include("catalog?f%5B#{maps_config.placename_field}%5D%5B%5D=Tibet") }
|
81
|
+
it { is_expected.to include('view=list') }
|
88
82
|
|
89
|
-
it
|
90
|
-
expect(helper.link_to_placename_field(
|
83
|
+
it 'creates a link to the placename field using the display value' do
|
84
|
+
expect(helper.link_to_placename_field(query_term, maps_config.placename_field, 'foo')).to include('">foo</a>')
|
91
85
|
end
|
92
|
-
|
93
|
-
it "should include the default_document_index_view_type in the params" do
|
94
|
-
expect(helper.link_to_placename_field('Tibet', blacklight_config.view.maps.placename_field)).to include('view=list')
|
95
|
-
end
|
96
|
-
|
97
86
|
end
|
98
87
|
|
99
|
-
describe
|
100
|
-
|
101
|
-
it "should create a link to a coordinate point" do
|
88
|
+
describe 'link_to_point_search' do
|
89
|
+
it 'creates a link to a coordinate point' do
|
102
90
|
expect(helper.link_to_point_search(coords)).to include('catalog?coordinates')
|
103
91
|
expect(helper.link_to_point_search(coords)).to include('spatial_search_type=point')
|
104
92
|
end
|
105
93
|
|
106
|
-
it
|
94
|
+
it 'includes the default_document_index_view_type in the params' do
|
107
95
|
expect(helper.link_to_point_search(coords)).to include('view=list')
|
108
96
|
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "map_facet_field" do
|
113
|
-
|
114
|
-
it "should return the correct facet field" do
|
115
|
-
expect(helper.map_facet_field).to eq(blacklight_config.view.maps.geojson_field)
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "map_facet_values" do
|
121
|
-
|
122
|
-
before do
|
123
|
-
@response = r
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should return an array of Blacklight::Solr::Response::Facets::FacetItem items" do
|
127
|
-
expect(helper.map_facet_values.class).to eq(Array)
|
128
|
-
expect(helper.map_facet_values.first.class).to eq(Blacklight::Solr::Response::Facets::FacetItem)
|
129
|
-
expect(helper.map_facet_values.length).to eq(5)
|
130
|
-
end
|
131
|
-
|
132
97
|
end
|
133
98
|
|
134
|
-
describe
|
135
|
-
|
136
|
-
|
137
|
-
expect(helper.render_placename_heading(geojson_hash)).to eq('Tibet')
|
99
|
+
describe 'render_placename_heading' do
|
100
|
+
it 'returns the placename heading' do
|
101
|
+
expect(helper.render_placename_heading(geojson_hash)).to eq(query_term)
|
138
102
|
end
|
139
|
-
|
140
103
|
end
|
141
104
|
|
142
|
-
describe
|
105
|
+
describe 'render_index_mapview' do
|
106
|
+
before { helper.instance_variable_set(:@response, response) }
|
143
107
|
|
144
|
-
|
145
|
-
@response = r
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should render the 'catalog/index_mapview' partial" do
|
108
|
+
it 'renders the "catalog/index_mapview" partial' do
|
149
109
|
expect(helper.render_index_mapview).to include("$('#blacklight-index-map').blacklight_leaflet_map")
|
150
110
|
end
|
151
|
-
|
152
111
|
end
|
153
112
|
|
154
|
-
describe
|
155
|
-
|
156
|
-
it "should return link_to_bbox_search if bbox coordinates are passed" do
|
113
|
+
describe 'render_spatial_search_link' do
|
114
|
+
it 'returns link_to_bbox_search if bbox coordinates are passed' do
|
157
115
|
expect(helper.render_spatial_search_link(bbox)).to include('spatial_search_type=bbox')
|
158
116
|
end
|
159
117
|
|
160
|
-
it
|
118
|
+
it 'returns link_to_point_search if point coordinates are passed' do
|
161
119
|
expect(helper.render_spatial_search_link(coords)).to include('spatial_search_type=point')
|
162
120
|
end
|
163
|
-
|
164
121
|
end
|
165
|
-
|
166
|
-
def mock_query_response
|
167
|
-
%({"responseHeader"=>{"status"=>0, "QTime"=>14, "params"=>{"q"=>"tibet", "spellcheck.q"=>"tibet", "qt"=>"search", "wt"=>"ruby", "rows"=>"10"}}, "response"=>{"numFound"=>2, "start"=>0, "maxScore"=>0.016135123, "docs"=>[{"published_display"=>["Dharamsala, H.P."], "author_display"=>"Thub-bstan-yar-ʼphel, Rnam-grwa", "lc_callnum_display"=>["DS785 .T475 2005"], "pub_date"=>["2005"], "format"=>"Book", "material_type_display"=>["a-e, iv, ii, 407 p."], "title_display"=>"Bod gaṅs can gyi rgyal rabs mdor bsdus dris lan brgya pa rab gsal śel gyi me loṅ źes bya ba bźugs so", "id"=>"2008308202", "subject_geo_facet"=>["Tibet"], "language_facet"=>["Tibetan"], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212, 29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[78.3955448, 26.8548157], [99.116241, 26.8548157], [99.116241, 36.4833345], [78.3955448, 36.4833345], [78.3955448, 26.8548157]]]},\\"bbox\\":[78.3955448,26.8548157,99.116241,36.4833345]}"], "coordinates"=>["91.117212 29.646923", "78.3955448 26.8548157 99.116241 36.4833345"], "score"=>0.016135123}, {"published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "subject_geo_facet"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[104.195397,35.86166]},\\"properties\\":{\\"placename\\":\\"China\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212,29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[78.96288,20.593684]},\\"properties\\":{\\"placename\\":\\"India\\"}}","{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},\\"bbox\\":[68.162386,6.7535159,97.395555,35.5044752]}"], "coordinates"=>["68.162386 6.7535159 97.395555 35.5044752", "104.195397 35.86166", "91.117212 29.646923", "78.96288 20.593684"], "score"=>0.0026767207}]}, "facet_counts"=>{"facet_queries"=>{}, "facet_fields"=>{"format"=>["Book", 2], "lc_1letter_facet"=>["D - World History", 1], "lc_alpha_facet"=>["DS", 1], "lc_b4cutter_facet"=>["DS785", 1], "language_facet"=>["Tibetan", 2], "pub_date"=>["2005", 1, "2007", 1], "subject_era_facet"=>[], "subject_geo_facet"=>["China", 1, "India", 1, "Tibet", 1, "Tibet (China)", 1], "coordinates"=>["91.117212 29.646923", 2, "78.3955448 26.8548157 99.116241 36.4833345", 1, "68.162386 6.7535159 97.395555 35.5044752", 1, "104.195397 35.86166", 1, "78.96288 20.593684", 1], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212, 29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", 2, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[78.3955448, 26.8548157], [99.116241, 26.8548157], [99.116241, 36.4833345], [78.3955448, 36.4833345], [78.3955448, 26.8548157]]]},\\"bbox\\":[78.3955448,26.8548157,99.116241,36.4833345]}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[104.195397,35.86166]},\\"properties\\":{\\"placename\\":\\"China\\"}}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[78.96288,20.593684]},\\"properties\\":{\\"placename\\":\\"India\\"}}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},\\"bbox\\":[68.162386,6.7535159,97.395555,35.5044752]}", 1], "subject_topic_facet"=>["Education and state", 1, "Teaching", 1, "Tibetan language", 1, "Tibetans", 1]}, "facet_dates"=>{}, "facet_ranges"=>{}}, "spellcheck"=>{"suggestions"=>["tibet", {"numFound"=>1, "startOffset"=>0, "endOffset"=>5, "origFreq"=>2, "suggestion"=>[{"word"=>"tibetan", "freq"=>6}]}, "correctlySpelled", true]}})
|
168
|
-
end
|
169
|
-
|
170
122
|
end
|
@@ -1,228 +1,194 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@controller.request = @request
|
11
|
-
@response = ActionDispatch::TestResponse.new
|
12
|
-
expect(@response).to receive(:docs).and_return([{ "published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "placename_field"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "geojson"=>["{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[104.195397,35.86166]},\"properties\":{\"placename\":\"China\"}}", "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[91.117212,29.646923]},\"properties\":{\"placename\":\"Tibet\"}}", "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[78.96288,20.593684]},\"properties\":{\"placename\":\"India\"}}"], "coordinates"=>["68.162386 6.7535159 97.395555 35.5044752", "104.195397 35.86166", "91.117212 29.646923", "20.593684,78.96288"], "score"=>0.0026767207 }])
|
5
|
+
describe BlacklightMaps::GeojsonExport do
|
6
|
+
let(:controller) { CatalogController.new }
|
7
|
+
let(:action) { :index }
|
8
|
+
let(:response_docs) do
|
9
|
+
YAML.safe_load(File.open(File.join(RSpec.configuration.fixture_paths.first, 'sample_solr_documents.yml')))
|
13
10
|
end
|
11
|
+
let(:export) { described_class.new(controller, action, response_docs, foo: 'bar') }
|
14
12
|
|
15
|
-
|
16
|
-
# then refactor build_geojson_features and to_geojson specs
|
17
|
-
subject {BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs, {foo:'bar'})}
|
13
|
+
before { controller.request = ActionDispatch::TestRequest.create }
|
18
14
|
|
19
|
-
it
|
20
|
-
expect(
|
15
|
+
it 'instantiates a GeojsonExport instance' do
|
16
|
+
expect(export.class).to eq(::BlacklightMaps::GeojsonExport)
|
21
17
|
end
|
22
18
|
|
23
|
-
describe
|
24
|
-
|
25
|
-
|
26
|
-
expect(subject.send(:blacklight_maps_config).class).to eq(::Blacklight::Configuration::ViewConfig)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should return geojson_field" do
|
30
|
-
expect(subject.send(:geojson_field)).to eq('geojson')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should return coordinates_field" do
|
34
|
-
expect(subject.send(:coordinates_field)).to eq('coordinates')
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should return search_mode" do
|
38
|
-
expect(subject.send(:search_mode)).to eq('placename')
|
19
|
+
describe 'return config settings' do
|
20
|
+
it 'returns maps config' do
|
21
|
+
expect(export.send(:maps_config).class).to eq(::Blacklight::Configuration::ViewConfig)
|
39
22
|
end
|
40
23
|
|
41
|
-
it
|
42
|
-
expect(
|
24
|
+
it 'returns geojson_field' do
|
25
|
+
expect(export.send(:geojson_field)).to eq('geojson_ssim')
|
43
26
|
end
|
44
27
|
|
45
|
-
it
|
46
|
-
expect(
|
28
|
+
it 'returns coordinates_field' do
|
29
|
+
expect(export.send(:coordinates_field)).to eq('coordinates_srpt')
|
47
30
|
end
|
48
31
|
|
49
|
-
it
|
50
|
-
expect(
|
32
|
+
it 'creates an @options instance variable' do
|
33
|
+
expect(export.instance_variable_get('@options')[:foo]).to eq('bar')
|
51
34
|
end
|
52
|
-
|
53
35
|
end
|
54
36
|
|
55
|
-
describe
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
before do
|
60
|
-
@output = subject.send(:build_feature_from_geojson, '{"type":"Feature","geometry":{"type":"Point","coordinates":[104.195397,35.86166]},"properties":{"placename":"China"}}', 1)
|
61
|
-
end
|
37
|
+
describe 'build_feature_from_geojson' do
|
38
|
+
describe 'point feature' do
|
39
|
+
let(:geojson) { '{"type":"Feature","geometry":{"type":"Point","coordinates":[104.195397,35.86166]},"properties":{"placename":"China"}}' }
|
40
|
+
let(:point_feature) { export.send(:build_feature_from_geojson, geojson, 1) }
|
62
41
|
|
63
|
-
it
|
64
|
-
expect(
|
65
|
-
expect(@output[:properties][:hits]).to eq(1)
|
42
|
+
it 'has a hits property with the right value' do
|
43
|
+
expect(point_feature[:properties][:hits]).to eq(1)
|
66
44
|
end
|
67
45
|
|
68
|
-
it
|
69
|
-
expect(
|
46
|
+
it 'has a popup property' do
|
47
|
+
expect(point_feature[:properties]).to have_key(:popup)
|
70
48
|
end
|
71
|
-
|
72
49
|
end
|
73
50
|
|
74
|
-
describe
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
before do
|
79
|
-
@output = subject.send(:build_feature_from_geojson, '{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},"bbox":[68.162386, 6.7535159, 97.395555, 35.5044752]}', 1)
|
80
|
-
end
|
51
|
+
describe 'bbox feature' do
|
52
|
+
describe 'catalog#index view' do
|
53
|
+
let(:geojson) { '{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},"bbox":[68.162386, 6.7535159, 97.395555, 35.5044752]}' }
|
54
|
+
let(:bbox_feature) { export.send(:build_feature_from_geojson, geojson, 1) }
|
81
55
|
|
82
|
-
it
|
83
|
-
expect(
|
56
|
+
it 'sets the center point as the coordinates' do
|
57
|
+
expect(bbox_feature[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
|
84
58
|
end
|
85
59
|
|
86
|
-
it "
|
87
|
-
expect(
|
88
|
-
expect(
|
60
|
+
it "changes the geometry type to 'Point'" do
|
61
|
+
expect(bbox_feature[:geometry][:type]).to eq('Point')
|
62
|
+
expect(bbox_feature[:bbox]).to be_nil
|
89
63
|
end
|
90
|
-
|
91
64
|
end
|
92
|
-
|
93
65
|
end
|
94
|
-
|
95
66
|
end
|
96
67
|
|
97
|
-
describe
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
before do
|
102
|
-
@output = subject.send(:build_feature_from_coords, '35.86166,104.195397', 1)
|
103
|
-
end
|
68
|
+
describe 'build_feature_from_coords' do
|
69
|
+
describe 'point feature' do
|
70
|
+
let(:point_feature) { export.send(:build_feature_from_coords, '35.86166,104.195397', 1) }
|
104
71
|
|
105
|
-
it
|
106
|
-
expect(
|
107
|
-
expect(
|
72
|
+
it 'creates a GeoJSON feature hash' do
|
73
|
+
expect(point_feature.class).to eq(Hash)
|
74
|
+
expect(point_feature[:type]).to eq('Feature')
|
108
75
|
end
|
109
76
|
|
110
|
-
it
|
111
|
-
expect(
|
77
|
+
it 'has the right coordinates' do
|
78
|
+
expect(point_feature[:geometry][:coordinates]).to eq([104.195397, 35.86166])
|
112
79
|
end
|
113
80
|
|
114
|
-
it
|
115
|
-
expect(
|
116
|
-
expect(@output[:properties][:hits]).to eq(1)
|
81
|
+
it 'has a hits property with the right value' do
|
82
|
+
expect(point_feature[:properties][:hits]).to eq(1)
|
117
83
|
end
|
118
84
|
|
119
|
-
it
|
120
|
-
expect(
|
85
|
+
it 'has a popup property' do
|
86
|
+
expect(point_feature[:properties]).to have_key(:popup)
|
121
87
|
end
|
122
|
-
|
123
88
|
end
|
124
89
|
|
125
|
-
describe
|
126
|
-
|
127
|
-
describe "catalog#index view" do
|
90
|
+
describe 'bbox feature' do
|
91
|
+
let(:basic_bbox) { 'ENVELOPE(68.162386, 97.395555, 35.5044752, 6.7535159)' }
|
128
92
|
|
129
|
-
|
130
|
-
|
131
|
-
end
|
93
|
+
describe 'catalog#index view' do
|
94
|
+
let(:bbox_feature) { export.send(:build_feature_from_coords, basic_bbox, 1) }
|
132
95
|
|
133
|
-
it
|
134
|
-
expect(
|
135
|
-
expect(
|
96
|
+
it 'sets the center point as the coordinates' do
|
97
|
+
expect(bbox_feature[:geometry][:type]).to eq('Point')
|
98
|
+
expect(bbox_feature[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
|
136
99
|
end
|
137
100
|
|
138
|
-
describe
|
139
|
-
|
140
|
-
|
141
|
-
|
101
|
+
describe 'bounding box that crosses the dateline' do
|
102
|
+
let(:bbox_feature) do
|
103
|
+
export.send(:build_feature_from_coords,
|
104
|
+
'ENVELOPE(1.162386, -179.395555, 35.5044752, 6.7535159)', 1)
|
142
105
|
end
|
143
106
|
|
144
|
-
it
|
145
|
-
expect(
|
107
|
+
it 'sets a center point with a long value between -180 and 180' do
|
108
|
+
expect(bbox_feature[:geometry][:coordinates]).to eq([90.88341550000001, 21.12899555])
|
146
109
|
end
|
147
|
-
|
148
110
|
end
|
149
|
-
|
150
111
|
end
|
151
112
|
|
152
|
-
describe
|
153
|
-
|
154
|
-
|
155
|
-
@action = "show"
|
156
|
-
@output = subject.send(:build_feature_from_coords, '68.162386 6.7535159 97.395555 35.5044752', 1)
|
157
|
-
end
|
113
|
+
describe 'catalog#show view' do
|
114
|
+
let(:action) { :show }
|
115
|
+
let(:show_feature) { export.send(:build_feature_from_coords, basic_bbox, 1) }
|
158
116
|
|
159
|
-
it
|
160
|
-
expect(
|
161
|
-
expect(
|
117
|
+
it 'converts the bbox string to a polygon coordinate array' do
|
118
|
+
expect(show_feature[:geometry][:type]).to eq('Polygon')
|
119
|
+
expect(show_feature[:geometry][:coordinates]).to eq(
|
120
|
+
[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]
|
121
|
+
)
|
162
122
|
end
|
163
123
|
|
164
|
-
it
|
165
|
-
expect(
|
124
|
+
it 'sets the bbox member' do
|
125
|
+
expect(show_feature[:bbox]).to eq([68.162386, 6.7535159, 97.395555, 35.5044752])
|
166
126
|
end
|
167
|
-
|
168
127
|
end
|
169
|
-
|
170
128
|
end
|
171
|
-
|
172
129
|
end
|
173
130
|
|
174
|
-
describe
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
131
|
+
describe 'render_leaflet_popup_content' do
|
132
|
+
describe 'placename_facet search_mode' do
|
133
|
+
let(:placename_popup) do
|
134
|
+
export.send(:render_leaflet_popup_content,
|
135
|
+
{ type: 'Feature',
|
136
|
+
geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
|
137
|
+
properties: { placename: 'China', hits: 1 } })
|
138
|
+
end
|
139
|
+
let(:spatial_popup) do
|
140
|
+
export.send(:render_leaflet_popup_content,
|
141
|
+
{ type: 'Feature',
|
142
|
+
geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
|
143
|
+
properties: { hits: 1 } })
|
180
144
|
end
|
181
145
|
|
182
|
-
it
|
183
|
-
expect(
|
146
|
+
it 'renders the map_placename_search partial if the placename is present' do
|
147
|
+
expect(placename_popup).to include('href="/catalog?f%5Bsubject_geo_ssim%5D%5B%5D=China')
|
184
148
|
end
|
185
149
|
|
150
|
+
it 'renders the map_spatial_search partial if the placename is not present' do
|
151
|
+
expect(spatial_popup).to include('href="/catalog?coordinates=35.86166%2C104.195397&spatial_search_type=point')
|
152
|
+
end
|
186
153
|
end
|
187
154
|
|
188
|
-
describe
|
189
|
-
|
155
|
+
describe 'coordinates search_mode' do
|
190
156
|
before do
|
191
157
|
CatalogController.configure_blacklight do |config|
|
192
158
|
config.view.maps.search_mode = 'coordinates'
|
193
159
|
end
|
194
160
|
end
|
195
161
|
|
196
|
-
|
197
|
-
|
162
|
+
let(:spatial_popup) do
|
163
|
+
export.send(:render_leaflet_popup_content,
|
164
|
+
{ type: 'Feature',
|
165
|
+
geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
|
166
|
+
properties: { hits: 1 } })
|
198
167
|
end
|
199
168
|
|
169
|
+
it 'renders the map_spatial_search partial' do
|
170
|
+
expect(spatial_popup).to include('href="/catalog?coordinates=35.86166%2C104.195397&spatial_search_type=point')
|
171
|
+
end
|
200
172
|
end
|
201
|
-
|
202
173
|
end
|
203
174
|
|
204
|
-
describe
|
205
|
-
|
206
|
-
|
207
|
-
@action = "show"
|
175
|
+
describe 'build_geojson_features' do
|
176
|
+
let(:geojson_features) do
|
177
|
+
described_class.new(controller, :show, response_docs.first).send(:build_geojson_features)
|
208
178
|
end
|
209
179
|
|
210
|
-
it
|
211
|
-
expect(
|
180
|
+
it 'creates an array of system' do
|
181
|
+
expect(geojson_features).not_to be_blank
|
212
182
|
end
|
213
|
-
|
214
183
|
end
|
215
184
|
|
216
|
-
describe
|
217
|
-
|
218
|
-
|
219
|
-
@action = "show"
|
185
|
+
describe 'to_geojson' do
|
186
|
+
let(:feature_collection) do
|
187
|
+
described_class.new(controller, :show, response_docs.first).send(:to_geojson)
|
220
188
|
end
|
221
189
|
|
222
|
-
it
|
223
|
-
expect(
|
190
|
+
it 'renders feature collection as json' do
|
191
|
+
expect(feature_collection).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
|
224
192
|
end
|
225
|
-
|
226
193
|
end
|
227
|
-
|
228
194
|
end
|