leaflet-rails 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 514333090001baba0d126fda802c52ab96c75699
4
- data.tar.gz: b2bb1cf5169b9bab76c75936335db73d72d8ea0a
3
+ metadata.gz: 39fdde9beb6ebc940c68b0ff8b4798e6cd531e15
4
+ data.tar.gz: 8e8739dbee2d813cfe9c4da4d5302f6bb222d892
5
5
  SHA512:
6
- metadata.gz: 42c7f28900cf74311aaf405c932d643310ef2697f109c8298c51ddfe7390d3c12638ed621e744b712ed03233fc7d46590157a862e9528518136f60857f10cefc
7
- data.tar.gz: 704bfdcf6813e3f2812ab038a842654d91f36b14f3ea069c33a5e0d6b62036a232714397b1b36e66b5c6d3c59e98b070d987ff39d90ec7792c8d729fa925d376
6
+ metadata.gz: 353dfa942ec238a6d1c9c4028b088aed522f58d43f2222e6f51826f404c1e7825afc0f1a83d8b1e6525665c66e4d6f355fc0542e13b8984d88764840193c14a9
7
+ data.tar.gz: 82600a54859803f3ad7f5d85dc69dbeb31a6e4564e07856e5789e33bc87a4a55f2c67fc769f565b6704e605311a660e823a5a754a061ffe1d4507c51af259715
data/.gitignore CHANGED
@@ -5,4 +5,7 @@ pkg/*
5
5
 
6
6
  /.rspec
7
7
  /coverage/
8
- /log/
8
+ /log/
9
+ .idea/*
10
+ .ruby-gemset
11
+ .ruby-version
data/README.md CHANGED
@@ -35,6 +35,17 @@ If you are using Rails 4.1+ you will need to open your application-wide CSS file
35
35
  //= depend_on_asset "layers-2x.png"
36
36
  ```
37
37
 
38
+
39
+ Version Parity
40
+ ==============
41
+
42
+ leaflet-rails tries to keep version parity with leaflet.js. However, this isn't possible in all cases. Discrepancies have been noted below.
43
+
44
+ | leaflet-rails | leaflet.js | Reason |
45
+ | ------------- | ------------- | ------|
46
+ | 0.7.4 | 0.7.3 | Requested in #33 because of large gap between master and rubygems.org.|
47
+
48
+
38
49
  Helpers
39
50
  =======
40
51
 
@@ -47,6 +58,13 @@ Leaflet.attribution = "Your attribution statement"
47
58
  Leaflet.max_zoom = 18
48
59
  ```
49
60
 
61
+ If you are using a tile layer which requires non-default subdomains such as [MapQuest-OSM Tiles](http://developer.mapquest.com/web/products/open/map), you can set the subdomains like this:
62
+
63
+ ```ruby
64
+ Leaflet.tile_layer = "http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png"
65
+ Leaflet.subdomains = ['otile1', 'otile2', 'otile3', 'otile4']
66
+ ```
67
+
50
68
  You will then be able to call the ```#map``` helper method in a view, and make sure that the helper method is inside an erb tag like so:
51
69
  ```ruby
52
70
  <div id="map">
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_development_dependency "rspec"
22
+ s.add_development_dependency "rspec", '<= 2.9.0'
23
23
  s.add_development_dependency "simplecov-rcov"
24
24
  s.add_development_dependency "actionpack", '>= 3.2.0'
25
25
  s.add_development_dependency "activesupport", '>= 3.2.0'
@@ -5,7 +5,8 @@ module Leaflet
5
5
  mattr_accessor :tile_layer
6
6
  mattr_accessor :attribution
7
7
  mattr_accessor :max_zoom
8
-
8
+ mattr_accessor :subdomains
9
+
9
10
  module Rails
10
11
  class Engine < ::Rails::Engine
11
12
  initializer 'leaflet-rails.precompile' do |app|
@@ -1,5 +1,5 @@
1
1
  module Leaflet
2
2
  module Rails
3
- VERSION = "0.7.3"
3
+ VERSION = "0.7.4"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/inflector'
1
2
  module Leaflet
2
3
  module ViewHelpers
3
4
 
@@ -5,26 +6,47 @@ module Leaflet
5
6
  options[:tile_layer] ||= Leaflet.tile_layer
6
7
  options[:attribution] ||= Leaflet.attribution
7
8
  options[:max_zoom] ||= Leaflet.max_zoom
9
+ options[:subdomains] ||= Leaflet.subdomains
8
10
  options[:container_id] ||= 'map'
9
11
 
12
+ tile_layer = options.delete(:tile_layer) || Leaflet.tile_layer
13
+ attribution = options.delete(:attribution) || Leaflet.attribution
14
+ max_zoom = options.delete(:max_zoom) || Leaflet.max_zoom
15
+ container_id = options.delete(:container_id) || 'map'
16
+ no_container = options.delete(:no_container)
17
+ center = options.delete(:center)
18
+ markers = options.delete(:markers)
19
+ circles = options.delete(:circles)
20
+ polylines = options.delete(:polylines)
21
+ fitbounds = options.delete(:fitbounds)
22
+
23
+
10
24
  output = []
11
- output << "<div id='#{options[:container_id]}'></div>" unless options[:no_container]
25
+ output << "<div id='#{container_id}'></div>" unless no_container
12
26
  output << "<script>"
13
- output << "var map = L.map('#{options[:container_id]}')"
14
- if options[:center]
15
- output << "map.setView([#{options[:center][:latlng][0]}, #{options[:center][:latlng][1]}], #{options[:center][:zoom]})"
27
+ output << "var map = L.map('#{container_id}')"
28
+
29
+ if center
30
+ output << "map.setView([#{center[:latlng][0]}, #{center[:latlng][1]}], #{center[:zoom]})"
16
31
  end
17
- if options[:markers]
18
- options[:markers].each do |marker|
19
- output << "marker = L.marker([#{marker[:latlng][0]}, #{marker[:latlng][1]}]).addTo(map)"
32
+
33
+ if markers
34
+ markers.each_with_index do |marker, index|
35
+ if marker[:icon]
36
+ icon_settings = prep_icon_settings(marker[:icon])
37
+ output << "var #{icon_settings[:name]}#{index} = L.icon({iconUrl: '#{icon_settings[:icon_url]}', shadowUrl: '#{icon_settings[:shadow_url]}', iconSize: #{icon_settings[:icon_size]}, shadowSize: #{icon_settings[:shadow_size]}, iconAnchor: #{icon_settings[:icon_anchor]}, shadowAnchor: #{icon_settings[:shadow_anchor]}, popupAnchor: #{icon_settings[:popup_anchor]}})"
38
+ output << "marker = L.marker([#{marker[:latlng][0]}, #{marker[:latlng][1]}], {icon: #{icon_settings[:name]}#{index}}).addTo(map)"
39
+ else
40
+ output << "marker = L.marker([#{marker[:latlng][0]}, #{marker[:latlng][1]}]).addTo(map)"
41
+ end
20
42
  if marker[:popup]
21
43
  output << "marker.bindPopup('#{marker[:popup]}')"
22
44
  end
23
45
  end
24
46
  end
25
47
 
26
- if options[:circles]
27
- options[:circles].each do |circle|
48
+ if circles
49
+ circles.each do |circle|
28
50
  output << "L.circle(['#{circle[:latlng][0]}', '#{circle[:latlng][1]}'], #{circle[:radius]}, {
29
51
  color: '#{circle[:color]}',
30
52
  fillColor: '#{circle[:fillColor]}',
@@ -33,8 +55,8 @@ module Leaflet
33
55
  end
34
56
  end
35
57
 
36
- if options[:polylines]
37
- options[:polylines].each do |polyline|
58
+ if polylines
59
+ polylines.each do |polyline|
38
60
  _output = "L.polyline(#{polyline[:latlngs]}"
39
61
  _output << "," + polyline[:options].to_json if polyline[:options]
40
62
  _output << ").addTo(map);"
@@ -42,18 +64,40 @@ module Leaflet
42
64
  end
43
65
  end
44
66
 
45
- if options[:fitbounds]
46
- output << "map.fitBounds(L.latLngBounds(#{options[:fitbounds]}));"
67
+ if fitbounds
68
+ output << "map.fitBounds(L.latLngBounds(#{fitbounds}));"
69
+ end
70
+
71
+ output << "L.tileLayer('#{tile_layer}', {
72
+ attribution: '#{attribution}',
73
+ maxZoom: #{max_zoom},"
74
+
75
+ if options[:subdomains]
76
+ output << " subdomains: #{options[:subdomains]},"
77
+ options.delete( :subdomains )
78
+ end
79
+
80
+ options.each do |key, value|
81
+ output << "#{key.to_s.camelize(:lower)}: '#{value}',"
47
82
  end
83
+ output << "}).addTo(map)"
48
84
 
49
- output << "L.tileLayer('#{options[:tile_layer]}', {
50
- attribution: '#{options[:attribution]}',
51
- maxZoom: #{options[:max_zoom]}
52
- }).addTo(map)"
53
85
  output << "</script>"
54
86
  output.join("\n").html_safe
55
87
  end
56
88
 
89
+ private
90
+
91
+ def prep_icon_settings(settings)
92
+ settings[:name] = 'icon' if settings[:name].nil? or settings[:name].blank?
93
+ settings[:shadow_url] = '' if settings[:shadow_url].nil?
94
+ settings[:icon_size] = [] if settings[:icon_size].nil?
95
+ settings[:shadow_size] = [] if settings[:shadow_size].nil?
96
+ settings[:icon_anchor] = [0, 0] if settings[:icon_anchor].nil?
97
+ settings[:shadow_anchor] = [0, 0] if settings[:shadow_anchor].nil?
98
+ settings[:popup_anchor] = [0, 0] if settings[:popup_anchor].nil?
99
+ return settings
100
+ end
57
101
  end
58
102
 
59
103
  end
@@ -63,6 +63,86 @@ describe Leaflet::ViewHelpers do
63
63
  result.should match(/marker = L\.marker\(\[51.52238797921441, -0.08366235665359283\]\).addTo\(map\)/)
64
64
  result.should match(/marker\.bindPopup\('Hello!'\)/)
65
65
  end
66
+
67
+ it 'should generate a marker with a popup and a custom icon' do
68
+ icon_options = { :name => 'house',
69
+ :icon_url => 'images/house.png',
70
+ :shadow_url => 'images/house_shadow.png',
71
+ :icon_size => [38, 95],
72
+ :shadow_size => [50, 64],
73
+ :icon_anchor => [22, 94],
74
+ :shadow_anchor => [4, 62],
75
+ :popup_anchor => [-3, -76]}
76
+ result = @view.map(:center => {
77
+ :latlng => [51.52238797921441, -0.08366235665359283],
78
+ :zoom => 18
79
+ },
80
+ :markers => [
81
+ {
82
+ :latlng => [51.52238797921441, -0.08366235665359283],
83
+ :popup => "Hello!",
84
+ :icon => icon_options
85
+ }
86
+ ])
87
+ expected_icon_def = "var #{icon_options[:name]}0 = L.icon({iconUrl: '#{icon_options[:icon_url]}', shadowUrl: '#{icon_options[:shadow_url]}', iconSize: #{icon_options[:icon_size]}, shadowSize: #{icon_options[:shadow_size]}, iconAnchor: #{icon_options[:icon_anchor]}, shadowAnchor: #{icon_options[:shadow_anchor]}, popupAnchor: #{icon_options[:popup_anchor]}})"
88
+ result.should include(expected_icon_def)
89
+ result.should match(/marker = L\.marker\(\[51.52238797921441, -0.08366235665359283\], \{icon: house\d+\}\).addTo\(map\)/)
90
+ result.should match(/marker\.bindPopup\('Hello!'\)/)
91
+ end
92
+
93
+ it 'should generate many markers with popups and custom icons' do
94
+ icon_options = { :name => 'house',
95
+ :icon_url => 'images/house.png',
96
+ :shadow_url => 'images/house_shadow.png',
97
+ :icon_size => [38, 95],
98
+ :shadow_size => [50, 64],
99
+ :icon_anchor => [22, 94],
100
+ :shadow_anchor => [4, 62],
101
+ :popup_anchor => [-3, -76]}
102
+ result = @view.map(:center => {
103
+ :latlng => [51.52238797921441, -0.08366235665359283],
104
+ :zoom => 18
105
+ },
106
+ :markers => [
107
+ {
108
+ :latlng => [51.52238797921441, -0.08366235665359283],
109
+ :popup => "Hello!",
110
+ :icon => icon_options
111
+ },
112
+ {
113
+ :latlng => [51.54238797921441, -0.08566235665359283],
114
+ :popup => "Farewell!",
115
+ :icon => icon_options
116
+ }
117
+ ])
118
+ expected_icon_def_1 = "var #{icon_options[:name]}0 = L.icon({iconUrl: '#{icon_options[:icon_url]}', shadowUrl: '#{icon_options[:shadow_url]}', iconSize: #{icon_options[:icon_size]}, shadowSize: #{icon_options[:shadow_size]}, iconAnchor: #{icon_options[:icon_anchor]}, shadowAnchor: #{icon_options[:shadow_anchor]}, popupAnchor: #{icon_options[:popup_anchor]}})"
119
+ expected_icon_def_2 = "var #{icon_options[:name]}1 = L.icon({iconUrl: '#{icon_options[:icon_url]}', shadowUrl: '#{icon_options[:shadow_url]}', iconSize: #{icon_options[:icon_size]}, shadowSize: #{icon_options[:shadow_size]}, iconAnchor: #{icon_options[:icon_anchor]}, shadowAnchor: #{icon_options[:shadow_anchor]}, popupAnchor: #{icon_options[:popup_anchor]}})"
120
+ result.should include(expected_icon_def_1)
121
+ result.should include(expected_icon_def_2)
122
+ result.should match(/marker = L\.marker\(\[51.52238797921441, -0.08366235665359283\], \{icon: house\d+\}\).addTo\(map\)/)
123
+ result.should match(/marker = L\.marker\(\[51.54238797921441, -0.08566235665359283\], \{icon: house\d+\}\).addTo\(map\)/)
124
+ result.should match(/marker\.bindPopup\('Hello!'\)/)
125
+ result.should match(/marker\.bindPopup\('Farewell!'\)/)
126
+ end
127
+
128
+ it 'should have defaults for icon options' do
129
+ icon_options = { :icon_url => 'images/house.png'}
130
+ result = @view.map(:center => {
131
+ :latlng => [51.52238797921441, -0.08366235665359283],
132
+ :zoom => 18
133
+ },
134
+ :markers => [
135
+ {
136
+ :latlng => [51.52238797921441, -0.08366235665359283],
137
+ :popup => "Hello!",
138
+ :icon => icon_options
139
+ }
140
+ ])
141
+ expected_icon_def = "var icon0 = L.icon({iconUrl: '#{icon_options[:icon_url]}', shadowUrl: '', iconSize: [], shadowSize: [], iconAnchor: [0, 0], shadowAnchor: [0, 0], popupAnchor: [0, 0]})"
142
+ result.should include(expected_icon_def)
143
+ result.should match(/marker = L\.marker\(\[51.52238797921441, -0.08366235665359283\], \{icon: icon\d+\}\).addTo\(map\)/)
144
+ result.should match(/marker\.bindPopup\('Hello!'\)/)
145
+ end
66
146
 
67
147
  it 'should override the method configuration options if set' do
68
148
  result = @view.map(:center => {
@@ -79,6 +159,26 @@ describe Leaflet::ViewHelpers do
79
159
  result.should match(/maxZoom: 4/)
80
160
  end
81
161
 
162
+ it 'should pass any configuration options to L.tileLayer if set' do
163
+ result = @view.map(:center => {
164
+ :latlng => [51.52238797921441, -0.08366235665359283],
165
+ :zoom => 18
166
+ },
167
+ :tile_layer => "http://{s}.someotherdomain.com/blabla/{z}/{x}/{y}.png",
168
+ :attribution => "Some other attribution text",
169
+ :max_zoom => 4,
170
+ :some_key => 'some value',
171
+ :key2 => 42
172
+ )
173
+
174
+ result.should match(/L.tileLayer\('http:\/\/{s}.someotherdomain\.com\/blabla\/{z}\/{x}\/{y}\.png'/)
175
+ result.should match(/attribution: 'Some other attribution text'/)
176
+ result.should match(/maxZoom: 4/)
177
+ result.should match(/someKey: 'some value'/)
178
+ result.should match(/key2: '42'/)
179
+
180
+ end
181
+
82
182
  it 'should have multiple map on single page' do
83
183
  result = @view.map(:container_id => "first_map", :center => {
84
184
  :latlng => [51.52238797921441, -0.08366235665359283],
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaflet-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akshay Joshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.9.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov-rcov
29
29
  requirement: !ruby/object:Gem::Requirement