blacklight-maps 0.3.0 → 0.3.1

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: e7059d890824c42ab380fe30f134bbe80c6aec34
4
- data.tar.gz: 0ce93e925097ef9a696d19722d60a46210a0130f
3
+ metadata.gz: cec8bdbdd2134f3c1f7f3762f61a91c387fcb39b
4
+ data.tar.gz: 02828cec807ece0e8564c74f6d424d3f787b9534
5
5
  SHA512:
6
- metadata.gz: e38b41d52c15e1194bb858fd74a5f121e859d41e5c2e5c2063a1ea03d4761c64a5688443d527723fb274f13481292fb77008a6a3c987113cc7e3116e03538f19
7
- data.tar.gz: 0f5bb334cea790bd339f408e00daf1100ecc8678adb011be8a72481a498274271eecb976b4e504f3381d7f7a71db8027ea541ed0e2a4aa59a46144605d212b53
6
+ metadata.gz: 9c3cb7694eb528ca1ff0d6f45454bb196591ee9c22bed67a8b74d385ac01ec072b1dd35f48cfa01a8b1fa410338ed8579694ea01aa20f9554d4b1d72343f092c
7
+ data.tar.gz: 75f2982504e7cf96e7d369e365dc7ad371342f388b274e3ea486752be3cd2138ec225a629d161fd0a2c67955cc6cbe118e0e1668a70aaad6d9f2ead52c35008e
@@ -85,9 +85,8 @@ module BlacklightMaps
85
85
  # turn bboxes into points for index view so we don't get weird mix of boxes and markers
86
86
  def build_feature_from_geojson(loc, hits = nil)
87
87
  geojson_hash = JSON.parse(loc).deep_symbolize_keys
88
-
89
88
  if @action != "show" && geojson_hash[:bbox]
90
- geojson_hash[:geometry][:coordinates] = Geometry::BoundingBox.new(geojson_hash[:bbox]).find_center
89
+ geojson_hash[:geometry][:coordinates] = Geometry::Point.new(Geometry::BoundingBox.new(geojson_hash[:bbox]).find_center).normalize_for_search
91
90
  geojson_hash[:geometry][:type] = "Point"
92
91
  geojson_hash.delete(:bbox)
93
92
  end
@@ -104,7 +103,7 @@ module BlacklightMaps
104
103
  if coords.scan(/[\s]/).length == 3 # bbox
105
104
  if @action != "show"
106
105
  geojson_hash[:geometry][:type] = "Point"
107
- geojson_hash[:geometry][:coordinates] = Geometry::BoundingBox.from_lon_lat_string(coords).find_center
106
+ geojson_hash[:geometry][:coordinates] = Geometry::Point.new(Geometry::BoundingBox.from_lon_lat_string(coords).find_center).normalize_for_search
108
107
  else
109
108
  coords_array = coords.split(' ').map { |v| v.to_f }
110
109
  geojson_hash[:bbox] = coords_array
@@ -35,5 +35,36 @@ module BlacklightMaps
35
35
  new(points.split(' '))
36
36
  end
37
37
  end
38
+
39
+ # This class contains Point objects and methods for working with them
40
+ class Point
41
+
42
+ # points is an array corresponding to the longitude and latitude values
43
+ # [long, lat]
44
+ def initialize(points)
45
+ @long = points[0].to_f
46
+ @lat = points[1].to_f
47
+ end
48
+
49
+ # returns a string that can be used as the value of solr_parameters[:pt]
50
+ # normalizes any long values >180 or <-180
51
+ def normalize_for_search
52
+ case
53
+ when @long > 180
54
+ @long -= 360
55
+ when @long < -180
56
+ @long += 360
57
+ end
58
+ [@long,@lat]
59
+ end
60
+
61
+ # Creates a new point from from a coordinate string
62
+ # "-50,100" (lat,long)
63
+ def self.from_lat_lon_string(points)
64
+ new(points.split(',').reverse)
65
+ end
66
+
67
+ end
68
+
38
69
  end
39
70
  end
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Maps
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -131,6 +131,18 @@ describe "BlacklightMaps::GeojsonExport" do
131
131
  expect(@output[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
132
132
  end
133
133
 
134
+ describe "bounding box that crosses the dateline" do
135
+
136
+ before do
137
+ @output = subject.send(:build_feature_from_coords, '1.162386 6.7535159 -179.395555 35.5044752', 1)
138
+ end
139
+
140
+ it "should set a center point with a long value between -180 and 180" do
141
+ expect(@output[:geometry][:coordinates]).to eq([90.88341550000001,21.12899555])
142
+ end
143
+
144
+ end
145
+
134
146
  end
135
147
 
136
148
  describe "catalog#show view" do
@@ -1,24 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "BlacklightMaps::Geometry::BoundingBox" do
3
+ describe BlacklightMaps::Geometry do
4
4
 
5
- let(:bbox) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-100 -50 100 50') }
6
- let(:bbox_california) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-124.4096196 32.5342321 -114.131211 42.0095169') }
7
- let(:bbox_dateline) {BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('165 30 -172 -20') }
5
+ describe "BlacklightMaps::Geometry::BoundingBox" do
8
6
 
9
- it "should instantiate Geometry::BoundingBox" do
10
- expect(bbox.class).to eq(::BlacklightMaps::Geometry::BoundingBox)
11
- end
7
+ let(:bbox) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-100 -50 100 50') }
8
+ let(:bbox_california) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-124.4096196 32.5342321 -114.131211 42.0095169') }
9
+ let(:bbox_dateline) {BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('165 30 -172 -20') }
12
10
 
13
- it "should return center of simple bounding box" do
14
- expect(bbox.find_center).to eq([0.0, 0.0])
15
- end
11
+ it "should instantiate Geometry::BoundingBox" do
12
+ expect(bbox.class).to eq(::BlacklightMaps::Geometry::BoundingBox)
13
+ end
14
+
15
+ it "should return center of simple bounding box" do
16
+ expect(bbox.find_center).to eq([0.0, 0.0])
17
+ end
16
18
 
17
- it "should return center of California bounding box" do
18
- expect(bbox_california.find_center).to eq([-119.2704153, 37.271874499999996])
19
+ it "should return center of California bounding box" do
20
+ expect(bbox_california.find_center).to eq([-119.2704153, 37.271874499999996])
21
+ end
22
+
23
+ it "should return correct dateline bounding box" do
24
+ expect(bbox_dateline.find_center).to eq([-183.5, 5])
25
+ end
19
26
  end
20
27
 
21
- it "should return correct dateline bounding box" do
22
- expect(bbox_dateline.find_center).to eq([-183.5, 5])
28
+ describe "BlacklightMaps::Geometry::Point" do
29
+
30
+ let(:point) { BlacklightMaps::Geometry::Point.from_lat_lon_string('20,120') }
31
+ let(:unparseable_point) { BlacklightMaps::Geometry::Point.from_lat_lon_string('35.86166,-184.195397') }
32
+
33
+ it "should instantiate Geometry::Point" do
34
+ expect(point.class).to eq(::BlacklightMaps::Geometry::Point)
35
+ end
36
+
37
+ it "should return a Solr-parseable coordinate if @long is > 180 or < -180" do
38
+ expect(unparseable_point.normalize_for_search).to eq([175.804603,35.86166])
39
+ end
40
+
23
41
  end
42
+
24
43
  end
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.0
4
+ version: 0.3.1
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-02-05 00:00:00.000000000 Z
12
+ date: 2015-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails