blacklight-maps 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cec8bdbdd2134f3c1f7f3762f61a91c387fcb39b
4
- data.tar.gz: 02828cec807ece0e8564c74f6d424d3f787b9534
3
+ metadata.gz: b6bffe02f056bdbd0cddc8b63f3f30b1ff7d08d9
4
+ data.tar.gz: 99876fe750aebda63112736254ea34d893f4c294
5
5
  SHA512:
6
- metadata.gz: 9c3cb7694eb528ca1ff0d6f45454bb196591ee9c22bed67a8b74d385ac01ec072b1dd35f48cfa01a8b1fa410338ed8579694ea01aa20f9554d4b1d72343f092c
7
- data.tar.gz: 75f2982504e7cf96e7d369e365dc7ad371342f388b274e3ea486752be3cd2138ec225a629d161fd0a2c67955cc6cbe118e0e1668a70aaad6d9f2ead52c35008e
6
+ metadata.gz: e37de7d922821ede6726b35bd1b2139fc72ca804000940c8411f40b1ec8320d95de79e1bc41315ecb50f10b70020da6ee02fca4b73096022734567777602be95
7
+ data.tar.gz: e7ffbbb907a95830329d2cbbc004bb0320c6a842e1adf5d9da9a2646fc4cae0d3ea36dfc5c349671e87d4416fe67a1f9399b1f3db1688033f0b4550e8caded55
data/README.md CHANGED
@@ -163,6 +163,23 @@ However, the catalog#show maplet widget must be included manually, via one of tw
163
163
  ...
164
164
  ```
165
165
 
166
+ ### Customization
167
+
168
+ The ```blacklight_map_tag``` helper takes an options hash as one of its arguments that can be used to provide customization options for the Leaflet map functionality via data attributes. (See ```app/views/catalog/index_map``` for an example.) The available options include:
169
+
170
+ - ```viewpoint``` = the center point of the map (```[lat,long]```)
171
+ - ```searchcontrol``` = whether to display the search control on the map (```boolean```)
172
+ - ```catalogpath``` = the search path for the search control (e.g. ```catalog_index_path```)
173
+ - ```placenamefield``` = the name of the Solr field containing the location names (e.g. ```"placename_field"```)
174
+ - ```searchctrlcue``` = the hover text to display when the mouse hovers over the search control
175
+ - ```singlemarkermode``` = whether locations should be clustered (```boolean```)
176
+ - ```clustercount``` = whether clusters should display the location count or the number of hits (```"hits" || "locations"```)
177
+ - ```maxzoom``` = the maxZoom [property of the map](http://leafletjs.com/reference.html#map-maxzoom)
178
+ - ```tileurl``` = a [tileLayer url](http://leafletjs.com/reference.html#tilelayer-l.tilelayer) to change the basemap
179
+ - ```mapattribution``` = an [attribution string](http://leafletjs.com/reference.html#tilelayer-attribution) to describe the basemap layer
180
+ - ```nodata``` = 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.
181
+
182
+
166
183
  ## Contributing
167
184
 
168
185
  1. Fork it ( http://github.com/<my-github-username>/blacklight-maps/fork )
@@ -3,6 +3,24 @@
3
3
  $.fn.blacklight_leaflet_map = function(geojson_docs, arg_opts) {
4
4
  var map, sidebar, markers, geoJsonLayer, currentLayer;
5
5
 
6
+ // Configure default options and those passed via the constructor options
7
+ var options = $.extend({
8
+ tileurl : 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
9
+ 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>',
10
+ viewpoint: [0,0],
11
+ initialzoom: 2,
12
+ singlemarkermode: true,
13
+ searchcontrol: false,
14
+ catalogpath: 'catalog',
15
+ searchctrlcue: 'Search for all items within the current map window',
16
+ placenamefield: 'placename_field',
17
+ nodata: 'Sorry, there is no data for this location.',
18
+ clustercount:'locations'
19
+ }, arg_opts );
20
+
21
+ // Extend options from data-attributes
22
+ $.extend(options, this.data());
23
+
6
24
  var mapped_items = '<span class="mapped-count"><span class="badge">' + geojson_docs.features.length + '</span> location' + (geojson_docs.features.length !== 1 ? 's' : '') + ' mapped</span>';
7
25
 
8
26
  var mapped_caveat = '<span class="mapped-caveat">Only items with location data are shown below</span>';
@@ -15,8 +33,12 @@
15
33
  var result_count = page_links.find('.page_entries').find('strong').last().html();
16
34
  page_links.html('<span class="page_entries"><strong>' + result_count + '</strong> items found</span>' + mapped_items + mapped_caveat);
17
35
  sortAndPerPage.find('.dropdown-toggle').hide();
36
+ } else { // catalog#show view
37
+ $(this.selector).before(mapped_items);
38
+ }
18
39
 
19
- // clusters should show item result count in #index and #map views
40
+ // determine whether to use item location or result count in cluster icon display
41
+ if (options.clustercount == 'hits') {
20
42
  var clusterIconFunction = function (cluster) {
21
43
  var markers = cluster.getAllChildMarkers();
22
44
  var childCount = 0;
@@ -33,28 +55,10 @@
33
55
  }
34
56
  return new L.divIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
35
57
  };
36
- } else { // catalog#show view
37
- $(this.selector).before(mapped_items);
58
+ } else {
38
59
  var clusterIconFunction = this._defaultIconCreateFunction;
39
60
  }
40
61
 
41
- // Configure default options and those passed via the constructor options
42
- var options = $.extend({
43
- tileurl : 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
44
- 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>',
45
- viewpoint: [0,0],
46
- initialzoom: 2,
47
- singlemarkermode: true,
48
- searchcontrol: false,
49
- catalogpath: 'catalog',
50
- searchctrlcue: 'Search for all items within the current map window',
51
- placenamefield: 'placename_field',
52
- nodata: 'Sorry, there is no data for this location.'
53
- }, arg_opts );
54
-
55
- // Extend options from data-attributes
56
- $.extend(options, this.data());
57
-
58
62
  // Display the map
59
63
  this.each(function() {
60
64
  options.id = this.id;
@@ -88,10 +88,11 @@ module Blacklight::BlacklightMapsHelperBehavior
88
88
  end
89
89
 
90
90
  # pass the document or facet values to BlacklightMaps::GeojsonExport
91
- def serialize_geojson(documents)
91
+ def serialize_geojson(documents, options={})
92
92
  export = BlacklightMaps::GeojsonExport.new(controller,
93
93
  controller.action_name,
94
- documents)
94
+ documents,
95
+ options)
95
96
  export.to_geojson
96
97
  end
97
98
 
@@ -2,6 +2,7 @@
2
2
  {data:{viewpoint: set_viewpoint(geojson_features),
3
3
  searchcontrol: true,
4
4
  catalogpath: catalog_index_path,
5
- placenamefield: blacklight_config.view.maps.placename_field
5
+ placenamefield: blacklight_config.view.maps.placename_field,
6
+ clustercount:'hits'
6
7
  }}) %>
7
8
  <%= javascript_tag "$('#blacklight-index-map').blacklight_leaflet_map(#{geojson_features});" %>
@@ -13,10 +13,12 @@ module BlacklightMaps
13
13
  # response_docs is passed by a helper, and is either:
14
14
  # - index view, map view: an array of facet values
15
15
  # - show view: the document object
16
- def initialize(controller, action, response_docs)
16
+ # options is an optional hash of possible configuration options
17
+ def initialize(controller, action, response_docs, options={})
17
18
  @controller = controller
18
19
  @action = action
19
20
  @response_docs = response_docs
21
+ @options = options
20
22
  end
21
23
 
22
24
  # build the GeoJSON FeatureCollection
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Maps
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -14,7 +14,7 @@ describe "BlacklightMaps::GeojsonExport" do
14
14
 
15
15
  # TODO: use @response.facet_by_field_name('geojson').items instead of @response
16
16
  # then refactor build_geojson_features and to_geojson specs
17
- subject {BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs)}
17
+ subject {BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs, {foo:'bar'})}
18
18
 
19
19
  it "should instantiate GeojsonExport" do
20
20
  expect(subject.class).to eq(::BlacklightMaps::GeojsonExport)
@@ -46,6 +46,10 @@ describe "BlacklightMaps::GeojsonExport" do
46
46
  expect(subject.send(:placename_property)).to eq('placename')
47
47
  end
48
48
 
49
+ it "should create an @options instance variable" do
50
+ expect(subject.instance_variable_get("@options")[:foo]).to eq('bar')
51
+ end
52
+
49
53
  end
50
54
 
51
55
  describe "build_feature_from_geojson" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-03 00:00:00.000000000 Z
12
+ date: 2015-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  version: '0'
257
257
  requirements: []
258
258
  rubyforge_project:
259
- rubygems_version: 2.4.5
259
+ rubygems_version: 2.2.2
260
260
  signing_key:
261
261
  specification_version: 4
262
262
  summary: Maps for Blacklight