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,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module BlacklightMaps
|
3
4
|
# This class provides the ability to export a response document to GeoJSON.
|
4
5
|
# The export is formated as a GeoJSON FeatureCollection, where the features
|
5
6
|
# consist of an array of Point features. For more on the GeoJSON
|
@@ -8,146 +9,166 @@ module BlacklightMaps
|
|
8
9
|
class GeojsonExport
|
9
10
|
include BlacklightMaps
|
10
11
|
|
11
|
-
# controller
|
12
|
-
# action
|
13
|
-
# response_docs
|
12
|
+
# @param controller [CatalogController]
|
13
|
+
# @param action [Symbol] the controller action
|
14
|
+
# @param response_docs [Array || SolrDocument] either:
|
14
15
|
# - index view, map view: an array of facet values
|
15
16
|
# - show view: the document object
|
16
|
-
# options
|
17
|
-
def initialize(controller, action, response_docs, options={})
|
17
|
+
# @param options [Hash] optional hash of configuration options
|
18
|
+
def initialize(controller, action, response_docs, options = {})
|
18
19
|
@controller = controller
|
19
20
|
@action = action
|
20
21
|
@response_docs = response_docs
|
21
22
|
@options = options
|
23
|
+
@features = []
|
22
24
|
end
|
23
25
|
|
24
|
-
#
|
26
|
+
# builds the GeoJSON FeatureCollection
|
25
27
|
def to_geojson
|
26
|
-
|
27
|
-
features: build_geojson_features }
|
28
|
-
geojson_docs.to_json
|
28
|
+
{ type: 'FeatureCollection', features: build_geojson_features }.to_json
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
def
|
33
|
+
def maps_config
|
34
34
|
@controller.blacklight_config.view.maps
|
35
35
|
end
|
36
36
|
|
37
37
|
def geojson_field
|
38
|
-
|
38
|
+
maps_config.geojson_field
|
39
39
|
end
|
40
40
|
|
41
41
|
def coordinates_field
|
42
|
-
|
42
|
+
maps_config.coordinates_field
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
|
45
|
+
def build_geojson_features
|
46
|
+
if @action == :index || @action == :map
|
47
|
+
build_index_features
|
48
|
+
elsif @action == :show
|
49
|
+
build_show_features
|
50
|
+
end
|
51
|
+
@features
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
54
|
+
# build GeoJSON features array for index and map views
|
55
|
+
def build_index_features
|
56
|
+
@response_docs.each do |geofacet|
|
57
|
+
@features << if maps_config.facet_mode == 'coordinates'
|
58
|
+
build_feature_from_coords(geofacet.value, geofacet.hits)
|
59
|
+
else
|
60
|
+
build_feature_from_geojson(geofacet.value, geofacet.hits)
|
61
|
+
end
|
62
|
+
end
|
51
63
|
end
|
52
64
|
|
53
|
-
|
54
|
-
|
65
|
+
# build GeoJSON features array for show view
|
66
|
+
def build_show_features
|
67
|
+
doc = @response_docs
|
68
|
+
return unless doc[geojson_field] || doc[coordinates_field]
|
69
|
+
|
70
|
+
if doc[geojson_field]
|
71
|
+
build_features_from_geojson(doc[geojson_field])
|
72
|
+
elsif doc[coordinates_field]
|
73
|
+
build_features_from_coords(doc[coordinates_field])
|
74
|
+
end
|
55
75
|
end
|
56
76
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
when "index", "map"
|
63
|
-
@response_docs.each do |geofacet|
|
64
|
-
if facet_mode == "coordinates"
|
65
|
-
features.push(build_feature_from_coords(geofacet.value, geofacet.hits))
|
66
|
-
else
|
67
|
-
features.push(build_feature_from_geojson(geofacet.value, geofacet.hits))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
when "show"
|
71
|
-
doc = @response_docs
|
72
|
-
return unless doc[geojson_field] || doc[coordinates_field]
|
73
|
-
if doc[geojson_field]
|
74
|
-
doc[geojson_field].uniq.each do |loc|
|
75
|
-
features.push(build_feature_from_geojson(loc))
|
76
|
-
end
|
77
|
-
elsif doc[coordinates_field]
|
78
|
-
doc[coordinates_field].uniq.each do |coords|
|
79
|
-
features.push(build_feature_from_coords(coords))
|
80
|
-
end
|
81
|
-
end
|
77
|
+
def build_features_from_geojson(geojson_field_values)
|
78
|
+
return unless geojson_field_values
|
79
|
+
|
80
|
+
geojson_field_values.uniq.each do |loc|
|
81
|
+
@features << build_feature_from_geojson(loc)
|
82
82
|
end
|
83
|
-
features
|
84
83
|
end
|
85
84
|
|
86
|
-
|
85
|
+
def build_features_from_coords(coordinates_field_values)
|
86
|
+
return unless coordinates_field_values
|
87
|
+
|
88
|
+
coordinates_field_values.uniq.each do |coords|
|
89
|
+
@features << build_feature_from_coords(coords)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# build GeoJSON feature from incoming GeoJSON data
|
87
94
|
# turn bboxes into points for index view so we don't get weird mix of boxes and markers
|
95
|
+
# @param loc [Hash]
|
96
|
+
# @param hits [Integer]
|
97
|
+
# rubocop:disable Metrics/AbcSize
|
88
98
|
def build_feature_from_geojson(loc, hits = nil)
|
89
|
-
|
90
|
-
if @action !=
|
91
|
-
|
92
|
-
|
93
|
-
|
99
|
+
geojson = JSON.parse(loc).deep_symbolize_keys
|
100
|
+
if @action != :show && geojson[:bbox]
|
101
|
+
bbox = Geometry::BoundingBox.new(geojson[:bbox])
|
102
|
+
geojson[:geometry][:coordinates] = Geometry::Point.new(bbox.find_center).normalize_for_search
|
103
|
+
geojson[:geometry][:type] = 'Point'
|
104
|
+
geojson.delete(:bbox)
|
94
105
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
106
|
+
geojson[:properties] ||= {}
|
107
|
+
geojson[:properties][:hits] = hits.to_i if hits
|
108
|
+
geojson[:properties][:popup] = render_leaflet_popup_content(geojson, hits)
|
109
|
+
geojson
|
99
110
|
end
|
111
|
+
# rubocop:enable Metrics/AbcSize
|
100
112
|
|
101
|
-
# build
|
113
|
+
# build GeoJSON feature from incoming raw coordinate data
|
102
114
|
# turn bboxes into points for index view so we don't get weird mix of boxes and markers
|
115
|
+
# @param coords [String]
|
116
|
+
# @param hits [Integer]
|
103
117
|
def build_feature_from_coords(coords, hits = nil)
|
104
|
-
|
105
|
-
if coords
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
else
|
110
|
-
coords_array = coords.split(' ').map { |v| v.to_f }
|
111
|
-
geojson_hash[:bbox] = coords_array
|
112
|
-
geojson_hash[:geometry][:type] = "Polygon"
|
113
|
-
geojson_hash[:geometry][:coordinates] = [[[coords_array[0],coords_array[1]],
|
114
|
-
[coords_array[2],coords_array[1]],
|
115
|
-
[coords_array[2],coords_array[3]],
|
116
|
-
[coords_array[0],coords_array[3]],
|
117
|
-
[coords_array[0],coords_array[1]]]]
|
118
|
-
end
|
119
|
-
elsif coords.match(/^[-]?[\d]*[\.]?[\d]*[ ,][-]?[\d]*[\.]?[\d]*$/) # point
|
120
|
-
geojson_hash[:geometry][:type] = "Point"
|
121
|
-
if coords.match(/,/)
|
122
|
-
coords_array = coords.split(',').reverse
|
123
|
-
else
|
124
|
-
coords_array = coords.split(' ')
|
125
|
-
end
|
126
|
-
geojson_hash[:geometry][:coordinates] = coords_array.map { |v| v.to_f }
|
118
|
+
geojson = { type: 'Feature', properties: {} }
|
119
|
+
if coords =~ /ENVELOPE/ # bbox
|
120
|
+
geojson.merge!(build_bbox_feature_from_coords(coords))
|
121
|
+
elsif coords =~ /^-?\d*\.?\d*[ ,]-?\d*\.?\d*$/ # point
|
122
|
+
geojson[:geometry] = build_point_geometry(coords)
|
127
123
|
else
|
128
124
|
Rails.logger.error("This coordinate format is not yet supported: '#{coords}'")
|
129
125
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
geojson[:properties] = { popup: render_leaflet_popup_content(geojson, hits) } if geojson[:geometry][:coordinates]
|
127
|
+
geojson[:properties][:hits] = hits.to_i if hits
|
128
|
+
geojson
|
129
|
+
end
|
130
|
+
|
131
|
+
# @param coords [String]
|
132
|
+
def build_bbox_feature_from_coords(coords)
|
133
|
+
geojson = { geometry: {} }
|
134
|
+
bbox = Geometry::BoundingBox.from_wkt_envelope(coords)
|
135
|
+
if @action != :show
|
136
|
+
geojson[:geometry][:type] = 'Point'
|
137
|
+
geojson[:geometry][:coordinates] = Geometry::Point.new(bbox.find_center).normalize_for_search
|
138
|
+
else
|
139
|
+
coords_array = bbox.to_a
|
140
|
+
geojson[:bbox] = coords_array
|
141
|
+
geojson[:geometry][:type] = 'Polygon'
|
142
|
+
geojson[:geometry][:coordinates] = bbox.geojson_geometry_array
|
143
|
+
end
|
144
|
+
geojson
|
145
|
+
end
|
146
|
+
|
147
|
+
# @param coords [String]
|
148
|
+
def build_point_geometry(coords)
|
149
|
+
geometry = { type: 'Point' }
|
150
|
+
coords_array = coords =~ /,/ ? coords.split(',').reverse : coords.split(' ')
|
151
|
+
geometry[:coordinates] = coords_array.map(&:to_f)
|
152
|
+
geometry
|
133
153
|
end
|
134
154
|
|
135
|
-
# Render to string the partial for each individual
|
155
|
+
# Render to string the partial for each individual feature.
|
136
156
|
# For placename searching, render catalog/map_placename_search partial,
|
137
|
-
# full geojson hash
|
157
|
+
# pass the full geojson hash to the partial for easier local customization
|
138
158
|
# For coordinate searches (or features with only coordinate data),
|
139
159
|
# render catalog/map_coordinate_search partial
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
160
|
+
# @param geojson [Hash]
|
161
|
+
# @param hits [Integer]
|
162
|
+
def render_leaflet_popup_content(geojson, hits = nil)
|
163
|
+
if maps_config.search_mode == 'placename' &&
|
164
|
+
geojson[:properties][maps_config.placename_property.to_sym]
|
165
|
+
partial = 'catalog/map_placename_search'
|
166
|
+
locals = { geojson_hash: geojson, hits: hits }
|
144
167
|
else
|
145
|
-
|
146
|
-
|
147
|
-
hits: hits }
|
168
|
+
partial = 'catalog/map_spatial_search'
|
169
|
+
locals = { coordinates: geojson[:bbox].presence || geojson[:geometry][:coordinates], hits: hits }
|
148
170
|
end
|
171
|
+
@controller.render_to_string(partial: partial, locals: locals)
|
149
172
|
end
|
150
|
-
|
151
173
|
end
|
152
|
-
|
153
174
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module BlacklightMaps
|
3
4
|
# Parent class of geospatial objects used in BlacklightMaps
|
4
5
|
class Geometry
|
5
|
-
|
6
6
|
# This class contains Bounding Box objects and methods for interacting with
|
7
7
|
# them.
|
8
8
|
class BoundingBox
|
9
|
-
|
10
9
|
# points is an array containing longitude and latitude values which
|
11
10
|
# relate to the southwest and northeast points of a bounding box
|
12
|
-
# [west, south, east, north] ([
|
11
|
+
# [west, south, east, north] ([minX, minY, maxX, maxY]).
|
13
12
|
def initialize(points)
|
14
13
|
@west = points[0].to_f
|
15
14
|
@south = points[1].to_f
|
@@ -17,15 +16,24 @@ module BlacklightMaps
|
|
17
16
|
@north = points[3].to_f
|
18
17
|
end
|
19
18
|
|
19
|
+
def geojson_geometry_array
|
20
|
+
[
|
21
|
+
[
|
22
|
+
[@west, @south],
|
23
|
+
[@east, @south],
|
24
|
+
[@east, @north],
|
25
|
+
[@west, @north],
|
26
|
+
[@west, @south]
|
27
|
+
]
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
20
31
|
# Returns an array [lng, lat] which is the centerpoint of a BoundingBox.
|
21
32
|
def find_center
|
22
33
|
center = []
|
23
34
|
center[0] = (@west + @east) / 2
|
24
35
|
center[1] = (@south + @north) / 2
|
25
|
-
|
26
|
-
# Handle bounding boxes that cross the dateline
|
27
|
-
center[0] -= 180 if @west > @east
|
28
|
-
|
36
|
+
center[0] -= 180 if @west > @east # handle bboxes that cross the dateline
|
29
37
|
center
|
30
38
|
end
|
31
39
|
|
@@ -34,11 +42,21 @@ module BlacklightMaps
|
|
34
42
|
def self.from_lon_lat_string(points)
|
35
43
|
new(points.split(' '))
|
36
44
|
end
|
45
|
+
|
46
|
+
# Creates a new bounding box from from a Solr WKT Envelope string
|
47
|
+
# "ENVELOPE(34.26, 35.89, 33.33, 29.47)" (minX, maxX, maxY, minY)
|
48
|
+
def self.from_wkt_envelope(envelope)
|
49
|
+
coords = envelope.gsub(/[[A-Z]()]/, '')&.split(', ')
|
50
|
+
new([coords[0], coords[3], coords[1], coords[2]])
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_a
|
54
|
+
[@west, @south, @east, @north]
|
55
|
+
end
|
37
56
|
end
|
38
57
|
|
39
58
|
# This class contains Point objects and methods for working with them
|
40
59
|
class Point
|
41
|
-
|
42
60
|
# points is an array corresponding to the longitude and latitude values
|
43
61
|
# [long, lat]
|
44
62
|
def initialize(points)
|
@@ -49,13 +67,9 @@ module BlacklightMaps
|
|
49
67
|
# returns a string that can be used as the value of solr_parameters[:pt]
|
50
68
|
# normalizes any long values >180 or <-180
|
51
69
|
def normalize_for_search
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
when @long < -180
|
56
|
-
@long += 360
|
57
|
-
end
|
58
|
-
[@long,@lat]
|
70
|
+
@long -= 360 if @long > 180
|
71
|
+
@long += 360 if @long < -180
|
72
|
+
[@long, @lat]
|
59
73
|
end
|
60
74
|
|
61
75
|
# Creates a new point from from a coordinate string
|
@@ -63,8 +77,6 @@ module BlacklightMaps
|
|
63
77
|
def self.from_lat_lon_string(points)
|
64
78
|
new(points.split(',').reverse)
|
65
79
|
end
|
66
|
-
|
67
80
|
end
|
68
|
-
|
69
81
|
end
|
70
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BlacklightMaps
|
2
4
|
module MapsSearchBuilderBehavior
|
3
5
|
extend ActiveSupport::Concern
|
@@ -11,7 +13,7 @@ module BlacklightMaps
|
|
11
13
|
if blacklight_params[:spatial_search_type] && blacklight_params[:coordinates]
|
12
14
|
solr_parameters[:fq] ||= []
|
13
15
|
if blacklight_params[:spatial_search_type] == 'bbox'
|
14
|
-
solr_parameters[:fq] << blacklight_config.view.maps.coordinates_field
|
16
|
+
solr_parameters[:fq] << "#{blacklight_config.view.maps.coordinates_field}:#{blacklight_params[:coordinates]}"
|
15
17
|
else
|
16
18
|
solr_parameters[:fq] << "{!geofilt sfield=#{blacklight_config.view.maps.coordinates_field}}"
|
17
19
|
solr_parameters[:pt] = blacklight_params[:coordinates]
|
@@ -20,6 +22,5 @@ module BlacklightMaps
|
|
20
22
|
end
|
21
23
|
solr_parameters
|
22
24
|
end
|
23
|
-
|
24
25
|
end
|
25
|
-
end
|
26
|
+
end
|
@@ -1,61 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Meant to be applied on top of Blacklight view helpers, to over-ride
|
2
4
|
# certain methods from RenderConstraintsHelper (newish in BL),
|
3
5
|
# to affect constraints rendering
|
4
6
|
module BlacklightMaps
|
5
|
-
|
6
7
|
module RenderConstraintsOverride
|
7
|
-
|
8
|
-
#
|
9
|
-
def
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def has_spatial_parameters?
|
14
|
-
!params[:coordinates].blank?
|
8
|
+
# @param search_state [Blacklight::SearchState]
|
9
|
+
# @return [Boolean]
|
10
|
+
def has_spatial_parameters?(search_state)
|
11
|
+
search_state.params[:coordinates].present?
|
15
12
|
end
|
16
13
|
|
17
14
|
# BlacklightMaps override: check for coordinate parameters
|
18
|
-
|
19
|
-
|
15
|
+
# @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
|
16
|
+
# @return [Boolean]
|
17
|
+
def query_has_constraints?(params_or_search_state = search_state)
|
18
|
+
search_state = convert_to_search_state(params_or_search_state)
|
19
|
+
has_spatial_parameters?(search_state) || super
|
20
20
|
end
|
21
21
|
|
22
22
|
# BlacklightMaps override: include render_spatial_query() in rendered constraints
|
23
|
-
|
24
|
-
|
23
|
+
# @param localized_params [Hash] localized_params query parameters
|
24
|
+
# @param local_search_state [Blacklight::SearchState]
|
25
|
+
# @return [String]
|
26
|
+
def render_constraints(localized_params = params, local_search_state = search_state)
|
27
|
+
params_or_search_state = if localized_params != params
|
28
|
+
localized_params
|
29
|
+
else
|
30
|
+
local_search_state
|
31
|
+
end
|
32
|
+
render_spatial_query(params_or_search_state) + super
|
25
33
|
end
|
26
34
|
|
27
35
|
# BlacklightMaps override: include render_search_to_s_coord() in rendered constraints
|
28
36
|
# Simpler textual version of constraints, used on Search History page.
|
37
|
+
# @param params [Hash]
|
38
|
+
# @return [String]
|
29
39
|
def render_search_to_s(params)
|
30
40
|
render_search_to_s_coord(params) + super
|
31
41
|
end
|
32
42
|
|
33
43
|
##
|
34
44
|
# Render the search query constraint
|
45
|
+
# @param params [Hash]
|
46
|
+
# @return [String]
|
35
47
|
def render_search_to_s_coord(params)
|
36
|
-
return
|
37
|
-
|
48
|
+
return ''.html_safe if params[:coordinates].blank?
|
49
|
+
|
50
|
+
render_search_to_s_element(spatial_constraint_label(params),
|
51
|
+
render_filter_value(params[:coordinates]))
|
38
52
|
end
|
39
53
|
|
40
54
|
# Render the spatial query constraints
|
41
|
-
|
55
|
+
# @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
|
56
|
+
# @return [String]
|
57
|
+
def render_spatial_query(params_or_search_state = search_state)
|
58
|
+
search_state = convert_to_search_state(params_or_search_state)
|
59
|
+
|
42
60
|
# So simple don't need a view template, we can just do it here.
|
43
|
-
return ''.html_safe if
|
61
|
+
return ''.html_safe if search_state.params[:coordinates].blank?
|
44
62
|
|
45
|
-
render_constraint_element(spatial_constraint_label(
|
46
|
-
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:spatial_search_type=>nil,
|
50
|
-
:action=>'index')))
|
63
|
+
render_constraint_element(spatial_constraint_label(search_state),
|
64
|
+
search_state.params[:coordinates],
|
65
|
+
classes: ['coordinates'],
|
66
|
+
remove: remove_spatial_params(search_state)) # _params.except!(:coordinates, :spatial_search_type)
|
51
67
|
end
|
52
68
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
69
|
+
##
|
70
|
+
#
|
71
|
+
# @param search_state [Blacklight::SearchState]
|
72
|
+
# @return [String]
|
73
|
+
# remove the spatial params from params
|
74
|
+
def remove_spatial_params(search_state)
|
75
|
+
search_action_path(search_state.params.dup.except!(:coordinates, :spatial_search_type))
|
57
76
|
end
|
58
77
|
|
78
|
+
##
|
79
|
+
# render the label for the spatial constraint
|
80
|
+
# @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
|
81
|
+
# @return [String]
|
82
|
+
def spatial_constraint_label(params_or_search_state)
|
83
|
+
search_params = if params_or_search_state.is_a?(Blacklight::SearchState)
|
84
|
+
params_or_search_state.params
|
85
|
+
else
|
86
|
+
params_or_search_state
|
87
|
+
end
|
88
|
+
if search_params[:spatial_search_type] && search_params[:spatial_search_type] == 'bbox'
|
89
|
+
t('blacklight.search.filters.coordinates.bbox')
|
90
|
+
else
|
91
|
+
t('blacklight.search.filters.coordinates.point')
|
92
|
+
end
|
93
|
+
end
|
59
94
|
end
|
60
|
-
|
61
|
-
end
|
95
|
+
end
|
data/lib/blacklight/maps.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'blacklight/maps/version'
|
2
4
|
|
3
5
|
module Blacklight
|
4
6
|
module Maps
|
5
|
-
require 'blacklight/maps/
|
7
|
+
require 'blacklight/maps/controller'
|
6
8
|
require 'blacklight/maps/render_constraints_override'
|
7
9
|
require 'blacklight/maps/engine'
|
8
10
|
require 'blacklight/maps/export'
|
9
11
|
require 'blacklight/maps/geometry'
|
10
12
|
require 'blacklight/maps/maps_search_builder'
|
11
13
|
|
14
|
+
# returns the full path to the blacklight plugin installation
|
15
|
+
def self.root
|
16
|
+
@root ||= File.expand_path(File.dirname(File.dirname(File.dirname(__FILE__))))
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
@@ -1,61 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/generators'
|
2
4
|
|
3
5
|
module BlacklightMaps
|
4
6
|
class Install < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc 'Install Blacklight-Maps'
|
5
10
|
|
6
|
-
|
11
|
+
def verify_blacklight_installed
|
12
|
+
return if IO.read('app/controllers/application_controller.rb').include?('include Blacklight::Controller')
|
7
13
|
|
8
|
-
|
14
|
+
say_status('info', 'BLACKLIGHT NOT INSTALLED; GENERATING BLACKLIGHT', :blue)
|
15
|
+
generate 'blacklight:install'
|
16
|
+
end
|
9
17
|
|
10
18
|
def assets
|
11
|
-
copy_file
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
//
|
19
|
-
// Required by Blacklight-Maps
|
20
|
-
//= require blacklight-maps}
|
21
|
-
end
|
19
|
+
copy_file 'blacklight_maps.css.scss', 'app/assets/stylesheets/blacklight_maps.css.scss'
|
20
|
+
return if IO.read('app/assets/javascripts/application.js').include?('blacklight-maps')
|
21
|
+
|
22
|
+
marker = '//= require blacklight/blacklight'
|
23
|
+
insert_into_file 'app/assets/javascripts/application.js', after: marker do
|
24
|
+
"\n// Required by BlacklightMaps" \
|
25
|
+
"\n//= require blacklight-maps"
|
22
26
|
end
|
27
|
+
append_to_file 'config/initializers/assets.rb',
|
28
|
+
"\nRails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'images')\n"
|
23
29
|
end
|
24
30
|
|
25
31
|
def inject_search_builder
|
26
|
-
inject_into_file 'app/models/search_builder.rb',
|
32
|
+
inject_into_file 'app/models/search_builder.rb',
|
33
|
+
after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
|
27
34
|
"\n include BlacklightMaps::MapsSearchBuilderBehavior\n"
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
38
|
def install_catalog_controller_mixin
|
32
|
-
inject_into_file
|
33
|
-
|
39
|
+
inject_into_file 'app/controllers/catalog_controller.rb',
|
40
|
+
after: /include Blacklight::Catalog.*$/ do
|
41
|
+
"\n include BlacklightMaps::Controller\n"
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
37
45
|
def install_search_history_controller
|
38
|
-
target_file =
|
39
|
-
if File.
|
40
|
-
inject_into_file target_file,
|
46
|
+
target_file = 'app/controllers/search_history_controller.rb'
|
47
|
+
if File.exist?(target_file)
|
48
|
+
inject_into_file target_file,
|
49
|
+
after: /include Blacklight::SearchHistory/ do
|
41
50
|
"\n helper BlacklightMaps::RenderConstraintsOverride\n"
|
42
51
|
end
|
43
52
|
else
|
44
|
-
copy_file
|
53
|
+
copy_file 'search_history_controller.rb', target_file
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
# TODO: inject Solr configuration (if needed)
|
58
|
+
def inject_solr_configuration
|
59
|
+
target_file = 'solr/conf/schema.xml'
|
60
|
+
return unless File.exist?(target_file)
|
61
|
+
|
62
|
+
inject_into_file target_file,
|
63
|
+
after: %r{<copyField source="title_tsim" dest="title_spell"/>} do
|
64
|
+
"\n <copyField source=\"coordinates_srpt\" dest=\"coordinates_ssim\" />\n"
|
56
65
|
end
|
57
66
|
end
|
58
|
-
|
59
|
-
|
60
67
|
end
|
61
|
-
end
|
68
|
+
end
|