Skip to content

Commit

Permalink
Merge 9835475 into 0832c34
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenenglish committed Aug 3, 2015
2 parents 0832c34 + 9835475 commit b9c6035
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 63 deletions.
6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -8,12 +8,6 @@ gemspec
# it'll want sprockets 2.11.0 and we'll have a conflict
gem 'sprockets', '2.11.0'

# If we don't specify 3.2.15 we'll end up with sass 3.3.2 in the main
# Gemfile.lock but since sass-rails gets generated (rails new) into the test app
# it'll want sass 3.2.0 and we'll have a conflict
gem 'sass', '~> 3.2.0'
gem 'bootstrap-sass', ">= 3.1.1.1"

group :test do
gem 'simplecov', require: false
gem 'coveralls', require: false
Expand Down
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -15,6 +15,8 @@ Maplet widget in item detail view:

## Installation

(See [Blacklight Version Compatibility](#blacklight-compatibility) below to make sure you're using a version of the gem that works with the version of Blacklight you're using.)

Add this line to your application's Gemfile:

gem 'blacklight-maps'
Expand Down Expand Up @@ -181,14 +183,21 @@ Option | Type | Default | Description
`catalogpath` | String | `'catalog'` | the search path for the search control
`placenamefield` | String | `'placename_field'` | the name of the Solr field containing the location names
`searchctrlcue` | String | `'Search for all items within the current map window'` | the hover text to display when the mouse hovers over the ![search control](docs/blacklight-maps_search-control.png) search control
`searchresultsview` | String | `'list'` | the view type for the search results on the catalog#index page after the ![search control](docs/blacklight-maps_search-control.png) search control is used
`searchresultsview` | String | `'list'` | the view type for the search results on the catalog#index page after the map ![search control](docs/blacklight-maps_search-control.png) search control is used
`singlemarkermode` | Boolean | `true` | whether locations should be clustered
`clustercount` | String | `'locations'` | whether clusters should display the location count or the number of hits (`'hits'` or `'locations'`)
`maxzoom` | Integer | 18 | the maxZoom [property of the map](http://leafletjs.com/reference.html#map-maxzoom)
`tileurl` | String | `'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'` | a [tileLayer url](http://leafletjs.com/reference.html#tilelayer-l.tilelayer) to change the basemap
`mapattribution` | String | ``Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'` | an [attribution string](http://leafletjs.com/reference.html#tilelayer-attribution) to describe the basemap layer
`nodata` | String | `'Sorry, there is no data for this location.'` | a message to display in the Leaflet popup when the "popup" member is not present in the properties hash in the GeoJSON Feature for a location.
### <a name="blacklight-compatibility"></a>Blacklight Version Compatibility
The table below indicates which versions of Blacklight Maps are compatible with which versions of Blacklight.
Blacklight Maps version | works with Blacklight version
----------------------- | ---------------------
>= 0.4.0 | >= 5.12.0 to < 6.*
<= 0.3.3 | >= 5.1 to <= 5.11.2
## Contributing
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/blacklight_maps_helper_behavior.rb
Expand Up @@ -61,8 +61,8 @@ def map_facet_field

# return an array of Blacklight::SolrResponse::Facets::FacetItem items
def map_facet_values
if @response.facet_by_field_name(map_facet_field)
@response.facet_by_field_name(map_facet_field).items
if @response.aggregations[map_facet_field]
@response.aggregations[map_facet_field].items
else
[]
end
Expand Down
4 changes: 2 additions & 2 deletions blacklight-maps.gemspec
Expand Up @@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "rails"
spec.add_dependency "blacklight", ">= 5.1.0"
spec.add_dependency "bootstrap-sass", "~> 3.0"
spec.add_dependency "blacklight", ">= 5.12.0"
spec.add_dependency "bootstrap-sass", "~> 3.2"
spec.add_dependency "leaflet-rails"
spec.add_dependency "leaflet-markercluster-rails"

Expand Down
1 change: 1 addition & 0 deletions lib/blacklight/maps.rb
Expand Up @@ -7,6 +7,7 @@ module Maps
require 'blacklight/maps/engine'
require 'blacklight/maps/export'
require 'blacklight/maps/geometry'
require 'blacklight/maps/maps_search_builder'

def self.inject!
CatalogController.send(:include, BlacklightMaps::ControllerOverride)
Expand Down
32 changes: 15 additions & 17 deletions lib/blacklight/maps/controller_override.rb
Expand Up @@ -2,32 +2,30 @@ module BlacklightMaps
module ControllerOverride
extend ActiveSupport::Concern
included do
solr_search_params_logic << :add_spatial_search_to_solr

if self.respond_to? :search_params_logic
search_params_logic << :add_spatial_search_to_solr
end

if self.blacklight_config.search_builder_class
self.blacklight_config.search_builder_class.send(:include,
BlacklightMaps::MapsSearchBuilder
) unless
self.blacklight_config.search_builder_class.include?(
BlacklightMaps::MapsSearchBuilder
)
end

end

def map
(@response, @document_list) = get_search_results
(@response, @document_list) = search_results(params, search_params_logic)
params[:view] = 'maps'
respond_to do |format|
format.html
end
end

# add spatial search params to solr
def add_spatial_search_to_solr(solr_parameters, user_parameters)
if user_parameters[:spatial_search_type] && user_parameters[:coordinates]
solr_parameters[:fq] ||= []
if user_parameters[:spatial_search_type] == 'bbox'
solr_parameters[:fq] << blacklight_config.view.maps.coordinates_field + ":" + user_parameters[:coordinates]
else
solr_parameters[:fq] << "{!geofilt sfield=#{blacklight_config.view.maps.coordinates_field}}"
solr_parameters[:pt] = user_parameters[:coordinates]
solr_parameters[:d] = blacklight_config.view.maps.spatial_query_dist
end
end
solr_parameters
end

end

end
20 changes: 20 additions & 0 deletions lib/blacklight/maps/maps_search_builder.rb
@@ -0,0 +1,20 @@
module BlacklightMaps
module MapsSearchBuilder

# add spatial search params to solr
def add_spatial_search_to_solr(solr_parameters = {})
if blacklight_params[:spatial_search_type] && blacklight_params[:coordinates]
solr_parameters[:fq] ||= []
if blacklight_params[:spatial_search_type] == 'bbox'
solr_parameters[:fq] << blacklight_config.view.maps.coordinates_field + ":" + blacklight_params[:coordinates]
else
solr_parameters[:fq] << "{!geofilt sfield=#{blacklight_config.view.maps.coordinates_field}}"
solr_parameters[:pt] = blacklight_params[:coordinates]
solr_parameters[:d] = blacklight_config.view.maps.spatial_query_dist
end
end
solr_parameters
end

end
end
2 changes: 1 addition & 1 deletion spec/helpers/blacklight_maps_helper_spec.rb
Expand Up @@ -23,7 +23,7 @@ def create_response
@catalog.request = @request
@catalog.action_name = "index"
helper.instance_variable_set(:@_controller, @catalog)
@docs = r.facet_by_field_name(blacklight_config.view.maps.geojson_field).items
@docs = r.aggregations[blacklight_config.view.maps.geojson_field].items
end

describe "blacklight_map_tag" do
Expand Down
34 changes: 0 additions & 34 deletions spec/lib/blacklight/maps/controller_override_spec.rb

This file was deleted.

55 changes: 55 additions & 0 deletions spec/lib/blacklight/maps/maps_search_builder_spec.rb
@@ -0,0 +1,55 @@
require 'spec_helper'

describe BlacklightMaps::MapsSearchBuilder do

class MapsSearchBuilderTestClass
cattr_accessor :blacklight_config, :blacklight_params

include Blacklight::SearchHelper
include BlacklightMaps::MapsSearchBuilder

def initialize blacklight_config, blacklight_params
self.blacklight_config = blacklight_config
self.blacklight_params = blacklight_params
end

end

let(:blacklight_config) { Blacklight::Configuration.new }
let(:blacklight_params) { Hash.new }
let(:solr_parameters) { Blacklight::Solr::Request.new }

describe "add_spatial_search_to_solr" do

before { @obj = MapsSearchBuilderTestClass.new blacklight_config, blacklight_params }

describe "coordinate search" do

before do
@obj.blacklight_params[:coordinates] = "35.86166,104.195397"
@obj.blacklight_params[:spatial_search_type] = "point"
end

it "should return a coordinate point spatial search if coordinates are given" do
expect(@obj.add_spatial_search_to_solr(solr_parameters)[:fq].first).to include('geofilt')
expect(@obj.add_spatial_search_to_solr(solr_parameters)[:pt]).to eq(@obj.blacklight_params[:coordinates])
end

end

describe "bbox search" do

before do
@obj.blacklight_params[:coordinates] = "[6.7535159,68.162386 TO 35.5044752,97.395555]"
@obj.blacklight_params[:spatial_search_type] = "bbox"
end

it "should return a bbox spatial search if a bbox is given" do
expect(@obj.add_spatial_search_to_solr(solr_parameters)[:fq].first).to include(blacklight_config.view.maps.coordinates_field)
end

end

end

end

0 comments on commit b9c6035

Please sign in to comment.