Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HydraConnect refactor #55

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
af87abe
ignore Rubymine .idea/* files
ebenenglish Oct 14, 2014
1fd0ccd
initial work on map for catalog#show view
ebenenglish Oct 15, 2014
336c7f9
updated config
ebenenglish Oct 17, 2014
fce5c9f
create geojson features using geojson or coordinates field
ebenenglish Oct 17, 2014
08cd600
display placenames and search links in Leaflet popups
ebenenglish Oct 20, 2014
9724cec
content for coordinate search leaflet popups
ebenenglish Oct 21, 2014
a849954
add logic to Solr params for spatial search
ebenenglish Oct 22, 2014
963509d
inject BlacklightMaps::ControllerOverride for adding spatial params t…
ebenenglish Oct 23, 2014
59f96b9
inital work on injecting constraints methods for spatial searches
ebenenglish Nov 7, 2014
d296f11
inject constraints helpers; helper methods for determining map viewpoint
ebenenglish Nov 10, 2014
7e3f3e9
pluralize mapped locations label
ebenenglish Nov 12, 2014
ed039f5
more work on catalog#index map view using geo facet data
ebenenglish Nov 13, 2014
620c6d3
more work on coordinate facets in catalog#index map view
ebenenglish Nov 14, 2014
f636268
include facet.hits so values can be rendered in partials
ebenenglish Nov 17, 2014
b0fe407
display facet counts for locations in catalog#index map view
ebenenglish Nov 18, 2014
121ac17
remove or deactivate inappropriate search result controls in catalog#…
ebenenglish Nov 18, 2014
ff4947a
CSS for map in catalog#show view
ebenenglish Nov 19, 2014
b2b6786
use helper funcs to rewnder facet values; mimic Blacklight pattern fo…
ebenenglish Nov 19, 2014
aa11167
fixing merge conflicts
ebenenglish Jan 14, 2015
e130a9b
clustering fixes and initial work on a dedicated maps view
ebenenglish Nov 20, 2014
d0c5159
'browse-everything' maps view up and running
ebenenglish Nov 21, 2014
3548d92
fixing more merge conflicts
ebenenglish Jan 14, 2015
02ca650
clusters should show item counts, not location counts
ebenenglish Nov 24, 2014
90d7832
replace page_links with mapped items info; simplify BlacklightMaps::R…
ebenenglish Nov 25, 2014
86ff971
initial work on map search function
ebenenglish Nov 25, 2014
c9247ab
more work on search control for map
ebenenglish Nov 26, 2014
5486e26
show map search bounds onmouseover of search control
ebenenglish Dec 2, 2014
430a140
use config for excluding geofacet field from leaflet search control; …
ebenenglish Dec 3, 2014
d37fdd0
resolve merge conflict
ebenenglish Dec 12, 2014
aa9ca30
make solr dist spatial query param configurable
ebenenglish Dec 5, 2014
c7837a4
use bbox bounds for set_viewpoint if only feature is a bbox
ebenenglish Dec 5, 2014
f0e65fa
fix for c1c7730ae63cb6a9a0bec1c72d11395fa9f0e200
ebenenglish Dec 5, 2014
c5c7493
portrait tablet layout adjustments for catalog#index map view
ebenenglish Dec 9, 2014
14154d1
set_viewpoint and fitBounds should not override options.maxzoom
ebenenglish Dec 9, 2014
2bb6523
less padding for fitBounds; update .page-entries layout for basic des…
ebenenglish Dec 9, 2014
725c4d0
revert version for easier rebase
ebenenglish Dec 12, 2014
24c7d76
initial work on specs for BlacklightMaps::GeojsonExport
ebenenglish Dec 15, 2014
e35a758
test coverage and slight refactoring for BlacklightMaps::GeojsonExport
ebenenglish Dec 18, 2014
20ae508
tests for BlacklightMaps::ControllerOverride -- some still pending
ebenenglish Dec 19, 2014
4973ad0
tests for BlacklightMaps::RenderConstraintsOverride - some still pending
ebenenglish Dec 19, 2014
ed0660e
initial work on specs for BlacklightMapsHelper
ebenenglish Dec 19, 2014
bcf8abb
more specs for BlacklightMapsHelper
ebenenglish Dec 22, 2014
146ed6c
initial work on feature specs for map views
ebenenglish Dec 23, 2014
acbb727
setup schema and faceting for feature specs
ebenenglish Dec 23, 2014
69692ac
more work on specs for catalog#index map view
ebenenglish Dec 24, 2014
f82c1f3
further work on feature specs for catalog#index map view
ebenenglish Dec 30, 2014
78bf826
wrapping up specs for catalog#map and catalog#show views
ebenenglish Jan 2, 2015
0a14e51
allow coordinates that begin with a decimal point
ebenenglish Jan 2, 2015
b351f7f
polishing up specs
ebenenglish Jan 5, 2015
0bbe515
new images for README
ebenenglish Jan 5, 2015
24c9008
remove '_facet' from placename field references; initial work on README
ebenenglish Jan 5, 2015
5790acd
updated README
ebenenglish Jan 6, 2015
8a971df
further improvements to README
ebenenglish Jan 6, 2015
df7f687
more improvements to README
ebenenglish Jan 6, 2015
c47a9cf
_search() should not pass long values <-180 or >180
ebenenglish Jan 6, 2015
a69322c
remove unused gems; bump rspec to ~> 3.0
ebenenglish Jan 9, 2015
7a99c6d
fixes for failing tests with ruby-1.9.3
ebenenglish Jan 30, 2015
6762c2b
remove references to unused leaflet-sidebar-rails gem
ebenenglish Jan 30, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,3 +18,4 @@ tmp
spec/internal
jetty
.DS_Store
.idea/
162 changes: 120 additions & 42 deletions README.md
Expand Up @@ -2,10 +2,16 @@

[![Build Status](https://travis-ci.org/sul-dlss/blacklight-maps.png?branch=master)](https://travis-ci.org/sul-dlss/blacklight-maps)

Provides a map view for Blacklight search results.
Provides map views for Blacklight for items with geospatial coordinate (latitude/longitude) metadata.

![Screen shot](docs/map-view.png)
![Screen shot](docs/map-sidebar.png)
Browse all records by 'Map' view:
![Screen shot](docs/blacklight-maps_map-view.png)

Map results view for search results (coordinate data as facet):
![Screen shot](docs/blacklight-maps_index-view.png)

Maplet widget in item detail view:
![Screen shot](docs/blacklight-maps_show-view.png)

## Installation

Expand All @@ -27,69 +33,141 @@ Run Blacklight-Maps generator:

## Usage

Blacklight-Maps adds a map view capability for a results set that contains geospatial coordinates (latitude/longitude).
Blacklight-Maps integrates [Leaflet](http://leafletjs.com/) to add map view capabilities for items with geospatial data in their corresponding Solr record.

For now, Blacklight-Maps requires that your Solr index include one of the following two types of fields:
In the map views, locations are represented as markers (or marker clusters, depending on the zoom level). Clicking on a marker opens a popup which (depending on config settings) displays the location name or coordinates, and provides a link to search for other items with the same location name/coordinates.

1. A `location_rpt` field that contains a bounding box for the document. For more on `location_rpt` see [Solr help](https://cwiki.apache.org/confluence/display/solr/Spatial+Search). This field can be multivalued.
```
place_bbox: 44.0318907 25.0594286 63.3333366 39.7816755
# minX minY maxX maxY
```
Users can also run a search using the map bounds as coordinate parameters by clicking the ![search control](docs/blacklight-maps_search-control.png) search control in the map view. Any items with coordinates or bounding boxes that are contained within the current map window will be returned.

In the catalog#map and catalog#index views, the geospatial data to populate the map comes from the facet component of the Solr response. Bounding boxes are represented as points corresponding to the center of the box.

In the catalog#show view, the data simply comes from the main document. Points are represented as markers and bounding boxes are represented as polygons. Clicking on a polygon opens a popup that allows the user to search for any items intersecting the bounding box.

### Solr Requirements

Blacklight-Maps requires that your Solr index include at least one (but preferably BOTH) of the following two types of fields:

1. A `location_rpt` field that contains coordinates or a bounding box. For more on `location_rpt` see [Solr help](https://cwiki.apache.org/confluence/display/solr/Spatial+Search). This field can be multivalued.

```
# coordinates: lon lat or lat,lon
# bounding box: minX minY maxX maxY
coordinates_field:
- 78.96288 20.593684
- 20.593684,78.96288
- 68.162386 6.7535159 97.395555 35.5044752
```

2. An indexed, stored string field containing a properly-formatted [GeoJSON](http://geojson.org) feature object for a point or bounding box that includes the coordinates and (preferably) location name. This field can be multivalued.

```
# first example below is for coordinate point, second is for bounding box
geojson_ssim:
- {"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]}
```

If you have #2 above and you want the popup search links to use the location name as a search parameter, you also need:

3. An indexed, stored text or string field containing location names. This field can be multivalued.

```
placename_field: India
```

##### Why so complicated?
Blacklight-Maps can be used with either field type (#1 or #2), however to take advantage of the full feature set, it is preferred that both field types exist for each item with geospatial metadata.

* The GeoJSON field (#2 above) provides reliable association of place names with coordinates, so the map marker popups can display the location name
* The Location name field (#3 above) allows users to run meaningful searches for locations found on the map
* The Coordinate field (#1 above) provides for the "Search" function on the map in the catalog#map and catalog#index views


**Important:** If you are NOT using the geojson field (#2), you should create a `copyField` in your Solr schema.xml to copy the coordinates from the `location_rpt` field to a string field that is stored, indexed, and multivalued to allow for proper faceting of the coordinate values in the catalog#map and catalog#index views.

2. A field containing placenames with latitude and longitude coordinates delimited by `-|-`. The delimiter can be configured in `app/controllers/catalog_controller.rb`. This field can be multivalued.
```
placename_coords:
- China-|-35.86166-|-104.195397
- Tibet-|-29.646923-|-91.117212
- India-|-20.593684-|-78.96288
```
<!-- Solr4 location_rpt field for coordinates, shapes, etc. -->
<dynamicField name="geospatial" type="location_rpt" indexed="true" stored="true" multiValued="true" />
<!-- copy geospatial to string field for faceting -->
<copyField source="geospatial" dest="geospatial_facet" />
```

Note: We are looking at implementing support for additional fields.
Support for additional field types may be added in the future.

### Configuration

#### Required
Blacklight-Maps expects you to provide:

- the type of location field you are using, `placename_coord` or `bbox` (`bbox` is default)
- a field to map the placename coordinates or bbox field
Blacklight-Maps expects you to provide these configuration options:

+ `facet_mode` = the type of field containing the data to use to display locations on the map (values: `'geojson'` or `'coordinates'`)
- if `'geojson'`:
+ `geojson_field` = the name of the Solr field containing the GeoJSON data
+ `placename_property` = the key in the GeoJSON properties hash representing the location name
- if `'coordinates'`
+ `coordinates_facet_field` = the name of the Solr field containing coordinate data in string format (`<copyField>` of `coordinates_field`)
+ `search_mode` = the type of search to run when clicking a link in the map popups (values: `'placename'` or `'coordinates'`)
- if `'placename'`:
+ `placename_field` = the name of the Solr field containing the location names
+ `coordinates_field` = the name of the Solr `location_rpt` type field containing geospatial coordinate data

#### Optional

- the maxZoom [property of the map](http://leafletjs.com/reference.html#map-maxzoom)
- a [tileLayer url](http://leafletjs.com/reference.html#tilelayer-l.tilelayer) to change the basemap
- an [attribution string](http://leafletjs.com/reference.html#tilelayer-attribution) to describe the basemap layer
- a custom delimiter field (used to delimit placename_coord values)
- `show_initial_zoom` = the zoom level to be used in the catalog#show view map (zoom levels for catalog#map and catalog#index map views are computed automatically)
- `maxzoom` = the maxZoom [property of the map](http://leafletjs.com/reference.html#map-maxzoom)
- `tileurl` = a [tileLayer url](http://leafletjs.com/reference.html#tilelayer-l.tilelayer) to change the basemap
- `mapattribution` = an [attribution string](http://leafletjs.com/reference.html#tilelayer-attribution) to describe the basemap layer
- `spatial_query_dist` = the radial distance, in kilometers, to search from a supplied coordinate point in a spatial search. This corresponds to the `d` [Spatial Filter](https://cwiki.apache.org/confluence/display/solr/Spatial+Search) parameter in Solr.


All of these options can easily be configured in `CatalogController.rb` in the `config` block.

```
```ruby
...
configure_blacklight do |config|
## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params
config.default_solr_params = {
:qt => 'search',
:rows => 10,
:fl => '*'
}

## Default values
config.view.maps.type = "bbox" # also accepts 'placename_coord' to use the placename coordinate type
config.view.maps.bbox_field = "place_bbox"
config.view.maps.placename_coord_field = "placename_coords"
## blacklight-maps configuration default values
config.view.maps.geojson_field = "geojson"
config.view.maps.placename_property = "placename"
config.view.maps.coordinates_field = "coordinates"
config.view.maps.search_mode = "placename" # or "coordinates"
config.view.maps.spatial_query_dist = 0.5
config.view.maps.placename_field = "placename_field"
config.view.maps.coordinates_facet_field = "coordinates_facet_field"
config.view.maps.facet_mode = "geojson" # or "coordinates"
config.view.maps.tileurl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
config.view.maps.attribution = '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>'
config.view.maps.placename_coord_delimiter = '-|-'
config.view.maps.mapattribution = '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>'
config.view.maps.maxzoom = 18
config.view.maps.show_initial_zoom = 5
...

```

### Implementation

The catalog#map and catalog#index map views are available by default. The "browse everything" Map view will be available in your app at `/map`, and in your app using routing helper `map_path`.

However, the catalog#show maplet widget must be included manually, via one of two ways:

1. Include the catalog/show_maplet_default partial explicitly. This option gives you the most flexibility, as you can choose where the partial gets rendered.

```ruby
<%= render partial: 'catalog/show_maplet_default' %>
```

2. Add `:show_maplet` to the list of partials to be rendered automatically by Blacklight in `CatalogController.rb` in the `config` block. This option is less work up front, but it may be more difficult to customize how the maplet is integrated into the page layout.

```
...
configure_blacklight do |config|
# add :show_maplet to the show partials array
config.show.partials << :show_maplet
...
```

## Contributing

1. Fork it ( http://github.com/<my-github-username>/blacklight-maps/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
3. Make some changes (with [tests](https://github.com/projectblacklight/blacklight/wiki/testing), please)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create new Pull Request
3 changes: 1 addition & 2 deletions app/assets/javascripts/blacklight-maps.js
Expand Up @@ -3,6 +3,5 @@

//= require leaflet
//= require leaflet.markercluster
//= require L.Control.Sidebar

//= require_tree './blacklight-maps'
//= require_tree .