leaflet-rails 0.7.2 → 0.7.3
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 +7 -0
- data/README.md +16 -6
- data/lib/leaflet-rails/version.rb +1 -1
- data/lib/leaflet-rails/view_helpers.rb +17 -2
- data/spec/view_helpers_spec.rb +29 -0
- data/vendor/assets/javascripts/leaflet.js.erb +37 -21
- metadata +21 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 514333090001baba0d126fda802c52ab96c75699
|
4
|
+
data.tar.gz: b2bb1cf5169b9bab76c75936335db73d72d8ea0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42c7f28900cf74311aaf405c932d643310ef2697f109c8298c51ddfe7390d3c12638ed621e744b712ed03233fc7d46590157a862e9528518136f60857f10cefc
|
7
|
+
data.tar.gz: 704bfdcf6813e3f2812ab038a842654d91f36b14f3ea069c33a5e0d6b62036a232714397b1b36e66b5c6d3c59e98b070d987ff39d90ec7792c8d729fa925d376
|
data/README.md
CHANGED
@@ -26,6 +26,15 @@ After that, open your application-wide Javascript file (typically `app/assets/ja
|
|
26
26
|
|
27
27
|
At this point, you may skip the first two steps of the [Leaflet Quick Start guide](http://leafletjs.com/examples/quick-start.html) and start at the third step (adding the map `div` to a view).
|
28
28
|
|
29
|
+
*Rails 4.1+*
|
30
|
+
|
31
|
+
If you are using Rails 4.1+ you will need to open your application-wide CSS file (`app/assets/stylesheets/application.css`) and add the following lines at the top:
|
32
|
+
|
33
|
+
```
|
34
|
+
//= depend_on_asset "layers.png"
|
35
|
+
//= depend_on_asset "layers-2x.png"
|
36
|
+
```
|
37
|
+
|
29
38
|
Helpers
|
30
39
|
=======
|
31
40
|
|
@@ -38,12 +47,14 @@ Leaflet.attribution = "Your attribution statement"
|
|
38
47
|
Leaflet.max_zoom = 18
|
39
48
|
```
|
40
49
|
|
41
|
-
You will then be able to call the helper in a view like so:
|
50
|
+
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:
|
42
51
|
```ruby
|
43
|
-
map
|
52
|
+
<div id="map">
|
53
|
+
<%= map(:center => {
|
44
54
|
:latlng => [51.52238797921441, -0.08366235665359283],
|
45
55
|
:zoom => 18
|
46
|
-
})
|
56
|
+
}) %>
|
57
|
+
</div>
|
47
58
|
```
|
48
59
|
|
49
60
|
You can also add any number of markers like so:
|
@@ -76,7 +87,7 @@ map(:center => {
|
|
76
87
|
)
|
77
88
|
```
|
78
89
|
|
79
|
-
If you want to override the map settings you have set in the initializer, you can also add them to the helper:
|
90
|
+
If you want to override the map settings you have set in the initializer, you can also add them to the helper method:
|
80
91
|
|
81
92
|
```ruby
|
82
93
|
map(:center => {
|
@@ -89,7 +100,7 @@ map(:center => {
|
|
89
100
|
)
|
90
101
|
```
|
91
102
|
|
92
|
-
If you want to have multiple maps on same page , you should add unique container_id in helper for each map:
|
103
|
+
If you want to have multiple maps on same page , you should add unique container_id in helper method for each map:
|
93
104
|
|
94
105
|
```ruby
|
95
106
|
map(:container_id => "first_map", :center => {
|
@@ -105,4 +116,3 @@ map(:container_id => "second_map", :center => {
|
|
105
116
|
|
106
117
|
|
107
118
|
[](https://bitdeli.com/free "Bitdeli Badge")
|
108
|
-
|
@@ -8,10 +8,12 @@ module Leaflet
|
|
8
8
|
options[:container_id] ||= 'map'
|
9
9
|
|
10
10
|
output = []
|
11
|
-
output << "<div id='#{options[:container_id]}'></div>"
|
11
|
+
output << "<div id='#{options[:container_id]}'></div>" unless options[:no_container]
|
12
12
|
output << "<script>"
|
13
13
|
output << "var map = L.map('#{options[:container_id]}')"
|
14
|
-
|
14
|
+
if options[:center]
|
15
|
+
output << "map.setView([#{options[:center][:latlng][0]}, #{options[:center][:latlng][1]}], #{options[:center][:zoom]})"
|
16
|
+
end
|
15
17
|
if options[:markers]
|
16
18
|
options[:markers].each do |marker|
|
17
19
|
output << "marker = L.marker([#{marker[:latlng][0]}, #{marker[:latlng][1]}]).addTo(map)"
|
@@ -31,6 +33,19 @@ module Leaflet
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
if options[:polylines]
|
37
|
+
options[:polylines].each do |polyline|
|
38
|
+
_output = "L.polyline(#{polyline[:latlngs]}"
|
39
|
+
_output << "," + polyline[:options].to_json if polyline[:options]
|
40
|
+
_output << ").addTo(map);"
|
41
|
+
output << _output.gsub(/\n/,'')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if options[:fitbounds]
|
46
|
+
output << "map.fitBounds(L.latLngBounds(#{options[:fitbounds]}));"
|
47
|
+
end
|
48
|
+
|
34
49
|
output << "L.tileLayer('#{options[:tile_layer]}', {
|
35
50
|
attribution: '#{options[:attribution]}',
|
36
51
|
maxZoom: #{options[:max_zoom]}
|
data/spec/view_helpers_spec.rb
CHANGED
@@ -118,4 +118,33 @@ describe Leaflet::ViewHelpers do
|
|
118
118
|
\}\).addTo\(map\)/)
|
119
119
|
end
|
120
120
|
|
121
|
+
it 'should not create the container tag if no_container is set' do
|
122
|
+
result = @view.map(:center => {
|
123
|
+
:latlng => [51.52238797921441, -0.08366235665359283],
|
124
|
+
:zoom => 18
|
125
|
+
},
|
126
|
+
:no_container => true
|
127
|
+
)
|
128
|
+
|
129
|
+
result.should_not match(/<div id='map'>/)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should generate a map and add a polyline' do
|
133
|
+
result = @view.map(
|
134
|
+
:polylines => [{:latlngs => [[51.5, -0.08], [-51.5, 0.08]], :options => {:color => "green"}}]
|
135
|
+
)
|
136
|
+
result.should match(Regexp.quote('L.polyline([[51.5, -0.08], [-51.5, 0.08]],{"color":"green"}).addTo(map);'))
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should generate a map and add fitbounds' do
|
140
|
+
result = @view.map(
|
141
|
+
:fitbounds => [[51.5, -0.08],[-51.5, 0.08]]
|
142
|
+
)
|
143
|
+
result.should match(Regexp.quote("map.fitBounds(L.latLngBounds([[51.5, -0.08], [-51.5, 0.08]]));"))
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should not require a center option to generate a map' do
|
147
|
+
result = @view.map({})
|
148
|
+
result.should_not match(Regexp.quote("map.setView"))
|
149
|
+
end
|
121
150
|
end
|
@@ -3,11 +3,16 @@
|
|
3
3
|
(c) 2010-2013, Vladimir Agafonkin
|
4
4
|
(c) 2010-2011, CloudMade
|
5
5
|
*/
|
6
|
+
|
7
|
+
//= depend_on_asset "marker-icon-2x.png"
|
8
|
+
//= depend_on_asset "marker-shadow.png"
|
9
|
+
//= depend_on_asset "marker-icon.png"
|
10
|
+
|
6
11
|
(function (window, document, undefined) {
|
7
12
|
var oldL = window.L,
|
8
13
|
L = {};
|
9
14
|
|
10
|
-
L.version = '0.7.
|
15
|
+
L.version = '0.7.3';
|
11
16
|
|
12
17
|
// define Leaflet for Node module pattern loaders, including Browserify
|
13
18
|
if (typeof module === 'object' && typeof module.exports === 'object') {
|
@@ -2104,13 +2109,13 @@ L.Map = L.Class.extend({
|
|
2104
2109
|
var loading = !this._loaded;
|
2105
2110
|
this._loaded = true;
|
2106
2111
|
|
2112
|
+
this.fire('viewreset', {hard: !preserveMapOffset});
|
2113
|
+
|
2107
2114
|
if (loading) {
|
2108
2115
|
this.fire('load');
|
2109
2116
|
this.eachLayer(this._layerAdd, this);
|
2110
2117
|
}
|
2111
2118
|
|
2112
|
-
this.fire('viewreset', {hard: !preserveMapOffset});
|
2113
|
-
|
2114
2119
|
this.fire('move');
|
2115
2120
|
|
2116
2121
|
if (zoomChanged || afterZoomAnim) {
|
@@ -5082,6 +5087,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
|
|
5082
5087
|
|
5083
5088
|
this._requestUpdate();
|
5084
5089
|
|
5090
|
+
this.fire('remove');
|
5085
5091
|
this._map = null;
|
5086
5092
|
},
|
5087
5093
|
|
@@ -6603,12 +6609,12 @@ L.DomEvent = {
|
|
6603
6609
|
var timeStamp = (e.timeStamp || e.originalEvent.timeStamp),
|
6604
6610
|
elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick);
|
6605
6611
|
|
6606
|
-
// are they closer together than
|
6612
|
+
// are they closer together than 500ms yet more than 100ms?
|
6607
6613
|
// Android typically triggers them ~300ms apart while multiple listeners
|
6608
6614
|
// on the same event should be triggered far faster;
|
6609
6615
|
// or check if click is simulated on the element, and if it is, reject any non-simulated events
|
6610
6616
|
|
6611
|
-
if ((elapsed && elapsed > 100 && elapsed <
|
6617
|
+
if ((elapsed && elapsed > 100 && elapsed < 500) || (e.target._simulatedClick && !e._simulated)) {
|
6612
6618
|
L.DomEvent.stop(e);
|
6613
6619
|
return;
|
6614
6620
|
}
|
@@ -6706,6 +6712,7 @@ L.Draggable = L.Class.extend({
|
|
6706
6712
|
offset = newPoint.subtract(this._startPoint);
|
6707
6713
|
|
6708
6714
|
if (!offset.x && !offset.y) { return; }
|
6715
|
+
if (L.Browser.touch && Math.abs(offset.x) + Math.abs(offset.y) < 3) { return; }
|
6709
6716
|
|
6710
6717
|
L.DomEvent.preventDefault(e);
|
6711
6718
|
|
@@ -6716,7 +6723,8 @@ L.Draggable = L.Class.extend({
|
|
6716
6723
|
this._startPos = L.DomUtil.getPosition(this._element).subtract(offset);
|
6717
6724
|
|
6718
6725
|
L.DomUtil.addClass(document.body, 'leaflet-dragging');
|
6719
|
-
|
6726
|
+
this._lastTarget = e.target || e.srcElement;
|
6727
|
+
L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target');
|
6720
6728
|
}
|
6721
6729
|
|
6722
6730
|
this._newPos = this._startPos.add(offset);
|
@@ -6732,9 +6740,13 @@ L.Draggable = L.Class.extend({
|
|
6732
6740
|
this.fire('drag');
|
6733
6741
|
},
|
6734
6742
|
|
6735
|
-
_onUp: function (
|
6743
|
+
_onUp: function () {
|
6736
6744
|
L.DomUtil.removeClass(document.body, 'leaflet-dragging');
|
6737
|
-
|
6745
|
+
|
6746
|
+
if (this._lastTarget) {
|
6747
|
+
L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target');
|
6748
|
+
this._lastTarget = null;
|
6749
|
+
}
|
6738
6750
|
|
6739
6751
|
for (var i in L.Draggable.MOVE) {
|
6740
6752
|
L.DomEvent
|
@@ -7389,7 +7401,7 @@ L.Map.TouchZoom = L.Handler.extend({
|
|
7389
7401
|
center = map.layerPointToLatLng(origin),
|
7390
7402
|
zoom = map.getScaleZoom(this._scale);
|
7391
7403
|
|
7392
|
-
map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta);
|
7404
|
+
map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta, false, true);
|
7393
7405
|
},
|
7394
7406
|
|
7395
7407
|
_onTouchEnd: function () {
|
@@ -8374,8 +8386,8 @@ L.Control.Layers = L.Control.extend({
|
|
8374
8386
|
|
8375
8387
|
onRemove: function (map) {
|
8376
8388
|
map
|
8377
|
-
.off('layeradd', this._onLayerChange)
|
8378
|
-
.off('layerremove', this._onLayerChange);
|
8389
|
+
.off('layeradd', this._onLayerChange, this)
|
8390
|
+
.off('layerremove', this._onLayerChange, this);
|
8379
8391
|
},
|
8380
8392
|
|
8381
8393
|
addBaseLayer: function (layer, name) {
|
@@ -8916,9 +8928,11 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
|
8916
8928
|
return true;
|
8917
8929
|
},
|
8918
8930
|
|
8919
|
-
_animateZoom: function (center, zoom, origin, scale, delta, backwards) {
|
8931
|
+
_animateZoom: function (center, zoom, origin, scale, delta, backwards, forTouchZoom) {
|
8920
8932
|
|
8921
|
-
|
8933
|
+
if (!forTouchZoom) {
|
8934
|
+
this._animatingZoom = true;
|
8935
|
+
}
|
8922
8936
|
|
8923
8937
|
// put transform transition on all layers with leaflet-zoom-animated class
|
8924
8938
|
L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
|
@@ -8932,14 +8946,16 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
|
8932
8946
|
L.Draggable._disabled = true;
|
8933
8947
|
}
|
8934
8948
|
|
8935
|
-
|
8936
|
-
|
8937
|
-
|
8938
|
-
|
8939
|
-
|
8940
|
-
|
8941
|
-
|
8942
|
-
|
8949
|
+
L.Util.requestAnimFrame(function () {
|
8950
|
+
this.fire('zoomanim', {
|
8951
|
+
center: center,
|
8952
|
+
zoom: zoom,
|
8953
|
+
origin: origin,
|
8954
|
+
scale: scale,
|
8955
|
+
delta: delta,
|
8956
|
+
backwards: backwards
|
8957
|
+
});
|
8958
|
+
}, this);
|
8943
8959
|
},
|
8944
8960
|
|
8945
8961
|
_onZoomTransitionEnd: function () {
|
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaflet-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Akshay Joshi
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: simplecov-rcov
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: actionpack
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 3.2.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 3.2.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: activesupport
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 3.2.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 3.2.0
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: activemodel
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 3.2.0
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 3.2.0
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: railties
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: 3.2.0
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: 3.2.0
|
110
97
|
description: This gem provides the leaflet.js map display library for your Rails 3/4
|
@@ -115,8 +102,8 @@ executables: []
|
|
115
102
|
extensions: []
|
116
103
|
extra_rdoc_files: []
|
117
104
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .travis.yml
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
120
107
|
- CHANGELOG.md
|
121
108
|
- Gemfile
|
122
109
|
- LICENSE
|
@@ -138,29 +125,27 @@ files:
|
|
138
125
|
homepage: ''
|
139
126
|
licenses:
|
140
127
|
- BSD
|
128
|
+
metadata: {}
|
141
129
|
post_install_message:
|
142
130
|
rdoc_options: []
|
143
131
|
require_paths:
|
144
132
|
- lib
|
145
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
134
|
requirements:
|
148
|
-
- -
|
135
|
+
- - ">="
|
149
136
|
- !ruby/object:Gem::Version
|
150
137
|
version: '0'
|
151
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
-
none: false
|
153
139
|
requirements:
|
154
|
-
- -
|
140
|
+
- - ">="
|
155
141
|
- !ruby/object:Gem::Version
|
156
142
|
version: '0'
|
157
143
|
requirements: []
|
158
144
|
rubyforge_project: leaflet-rails
|
159
|
-
rubygems_version:
|
145
|
+
rubygems_version: 2.2.2
|
160
146
|
signing_key:
|
161
|
-
specification_version:
|
147
|
+
specification_version: 4
|
162
148
|
summary: Use leaflet.js with Rails 3/4.
|
163
149
|
test_files:
|
164
150
|
- spec/spec_helper.rb
|
165
151
|
- spec/view_helpers_spec.rb
|
166
|
-
has_rdoc:
|