spherical_mercator 1.1.0 → 1.1.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 +5 -5
- data/.travis.yml +5 -4
- data/README.md +4 -1
- data/lib/spherical_mercator.rb +7 -2
- data/lib/spherical_mercator/version.rb +1 -1
- data/spec/spherical_mercator/spherical_mercator_spec.rb +5 -0
- data/spherical_mercator.gemspec +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 665ccb30651f974478815cbfc896ee76d310c99c9bf270378c2078033bb4da0c
|
4
|
+
data.tar.gz: 8406e7fa6f88d8812e6ccd355a1ccbf67a805fb8a74665ac28a1a0945b0b6eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e834ae96fce835a4965040e1dd8696241d7222db5e275c4f61c7eec59b28cbec8e4f7a3a90e73b51e66ab0ca7bb6b1c9fda5396040bb84fa877d4574288cc5
|
7
|
+
data.tar.gz: 4e7a044bc20704dcf933dcd87ebfc5a1fcac1077fe2ac9ed1812d61d682a81f292d5ef020fe39850ca52a0a76d41fb67855065cd3eb8347c32c86bd792a1cab4
|
data/.travis.yml
CHANGED
@@ -3,10 +3,11 @@ before_install: gem install bundler
|
|
3
3
|
bundler_args: --without yard guard benchmarks
|
4
4
|
script: "rake spec"
|
5
5
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
|
+
- 2.7
|
10
|
+
- 3.0
|
10
11
|
- jruby-9.0.5.0
|
11
12
|
- jruby-9.1.5.0
|
12
13
|
- jruby-9.1.6.0
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Ruby port of Mapbox Spherical Mercator
|
2
2
|
[](http://badge.fury.io/rb/spherical_mercator)
|
3
3
|
[](https://travis-ci.org/nbulaj/spherical_mercator)
|
4
|
-
[](https://gemnasium.com/nbulaj/spherical_mercator)
|
5
4
|
[](https://coveralls.io/github/nbulaj/spherical_mercator)
|
6
5
|
[](#license)
|
7
6
|
|
@@ -32,6 +31,8 @@ Some datatypes are assumed to be arrays: `ll` is `[lon, lat]`, `xy` and `px` are
|
|
32
31
|
```ruby
|
33
32
|
# By default, precomputes up to z30
|
34
33
|
mercator = SphericalMercator.new(size: 256)
|
34
|
+
# Whether to round pixel values at integer zoom levels. Defaults to true.
|
35
|
+
mercator = SphericalMercator.new(round: false)
|
35
36
|
```
|
36
37
|
|
37
38
|
### `px(lon_lat, zoom)`
|
@@ -39,6 +40,8 @@ mercator = SphericalMercator.new(size: 256)
|
|
39
40
|
Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level.
|
40
41
|
The inverse of `ll`
|
41
42
|
|
43
|
+
Screen pixel values are rounded, unless the zoom level is a floating point value. To disable rounding on integer zoom levels, specify `round: false` when creating the SphericalMercator.
|
44
|
+
|
42
45
|
### `ll(px, zoom)`
|
43
46
|
|
44
47
|
Convert screen pixel value to lon, lat, at a certain zoom level. The inverse
|
data/lib/spherical_mercator.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'spherical_mercator/version'
|
2
2
|
|
3
3
|
class SphericalMercator
|
4
|
+
|
4
5
|
attr_reader :options
|
6
|
+
attr_accessor :size, :round
|
7
|
+
|
5
8
|
# Closures including constants and other precalculated values.
|
6
9
|
|
7
10
|
EPSLN = 1.0e-10
|
@@ -11,7 +14,7 @@ class SphericalMercator
|
|
11
14
|
A = 6_378_137.0
|
12
15
|
MAX_EXTENT = 20_037_508.342_789_244
|
13
16
|
|
14
|
-
attr_accessor :
|
17
|
+
attr_accessor :cache
|
15
18
|
|
16
19
|
attr_accessor :ac, :bc, :cc, :zc
|
17
20
|
|
@@ -22,6 +25,8 @@ class SphericalMercator
|
|
22
25
|
@options = opts || {}
|
23
26
|
|
24
27
|
self.size = (options[:size] || 256).to_f
|
28
|
+
# Whether to round output values for integer zoom levels. Defaults to true.
|
29
|
+
self.round = (options[:round].nil?) ? true : options[:round]
|
25
30
|
|
26
31
|
if cache[size].nil?
|
27
32
|
size = self.size
|
@@ -60,7 +65,7 @@ class SphericalMercator
|
|
60
65
|
# - `ll` {Array} `[lon, lat]` array of geographic coordinates.
|
61
66
|
# - `zoom` {Number} zoom level.
|
62
67
|
def px(lon_lat, zoom)
|
63
|
-
if float?(zoom)
|
68
|
+
if float?(zoom) || !self.round
|
64
69
|
size = @size * (2**zoom)
|
65
70
|
d = size / 2
|
66
71
|
bc = (size / 360)
|
@@ -18,6 +18,7 @@ end
|
|
18
18
|
|
19
19
|
describe SphericalMercator do
|
20
20
|
let!(:sm) { SphericalMercator.new }
|
21
|
+
let!(:sm_round) { SphericalMercator.new(round: false) }
|
21
22
|
|
22
23
|
context '#bbox' do
|
23
24
|
it '[0,0,0] converted to proper bbox' do
|
@@ -117,6 +118,10 @@ describe SphericalMercator do
|
|
117
118
|
it 'PX with float zoom value converts' do
|
118
119
|
expect(sm.px([-179, 85], 8.6574)).to eq([287.12734093961626, 169.30444219392666])
|
119
120
|
end
|
121
|
+
|
122
|
+
it 'PX with forced rounding' do
|
123
|
+
expect(sm_round.px([-179, 85], 9)).to eq([364.0888888888876, 214.68476683766494])
|
124
|
+
end
|
120
125
|
end
|
121
126
|
|
122
127
|
context 'high precision float' do
|
data/spherical_mercator.gemspec
CHANGED
@@ -5,7 +5,6 @@ require 'spherical_mercator/version'
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'spherical_mercator'
|
7
7
|
gem.version = SphericalMercator.gem_version
|
8
|
-
gem.date = '2017-10-03'
|
9
8
|
gem.summary = 'Spherical Mercator math in Ruby'
|
10
9
|
gem.description = 'Spherical Mercator provides projection math for converting between mercator' \
|
11
10
|
'meters, screen pixels (of 256x256 or configurable-size tiles), and latitude/longitude'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spherical_mercator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.7.9
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Spherical Mercator math in Ruby
|