leaflet-zoomslider-rails 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in leaflet-zoomslider-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Klaas Endrikat
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Leaflet::Zoomslider::Rails
2
+
3
+ Integrates the [leaflet-zoomslider] plugin with the asset pipeline
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'leaflet-zoomslider-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install leaflet-zoomslider-rails
18
+
19
+ ## Usage
20
+
21
+ Add the following to your `app/assets/javascripts/application.js`:
22
+
23
+ //= require leaflet.zoomslider
24
+
25
+ Add the following to your `app/assets/stylesheets/application.css`:
26
+
27
+ *= require leaflet.zoomslider
28
+ *= require leaflet.zoomslider.ie
29
+
30
+ Examples can be found at [kartena]
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
39
+
40
+ ## License
41
+ MIT License, full text of license see [here][License]
42
+
43
+ *Free Software, Fuck Yeah!*
44
+
45
+ [License]: https://github.com/kendrikat/leaflet-zoomslider-rails/blob/master/LICENSE.txt "LICENSE"
46
+ [leaflet-zoomslider]: https://github.com/kartena/Leaflet.zoomslider
47
+ [kartena]: https://github.com/kartena/Leaflet.zoomslider/tree/master/examples
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'leaflet-zoomslider-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "leaflet-zoomslider-rails"
8
+ gem.version = Leaflet::Zoomslider::Rails::VERSION
9
+ gem.authors = ["Klaas Endrikat"]
10
+ gem.email = ["klaas.endrikat@googlemail.com"]
11
+ gem.description = %q{Integrates the Leaflet ZoomSlider plugin with Rails asset pipeline}
12
+ gem.summary = %q{Leaflet ZoomSlider plugin for Rails}
13
+ gem.license = 'MIT'
14
+ gem.homepage = "https://github.com/kendrikat/leaflet-zoomslider-rails"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,7 @@
1
+ module Leaflet
2
+ module Zoomslider
3
+ module Rails
4
+ VERSION = "0.6.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "leaflet-zoomslider-rails/version"
2
+
3
+ module Leaflet
4
+ module Zoomslider
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,206 @@
1
+ L.Control.Zoomslider = (function () {
2
+
3
+ var Knob = L.Draggable.extend({
4
+ initialize: function (element, stepHeight, knobHeight) {
5
+ L.Draggable.prototype.initialize.call(this, element, element);
6
+ this._element = element;
7
+
8
+ this._stepHeight = stepHeight;
9
+ this._knobHeight = knobHeight;
10
+
11
+ this.on('predrag', function () {
12
+ this._newPos.x = 0;
13
+ this._newPos.y = this._adjust(this._newPos.y);
14
+ }, this);
15
+ },
16
+
17
+ _adjust: function (y) {
18
+ var value = Math.round(this._toValue(y));
19
+ value = Math.max(0, Math.min(this._maxValue, value));
20
+ return this._toY(value);
21
+ },
22
+
23
+ // y = k*v + m
24
+ _toY: function (value) {
25
+ return this._k * value + this._m;
26
+ },
27
+ // v = (y - m) / k
28
+ _toValue: function (y) {
29
+ return (y - this._m) / this._k;
30
+ },
31
+
32
+ setSteps: function (steps) {
33
+ var sliderHeight = steps * this._stepHeight;
34
+ this._maxValue = steps - 1;
35
+
36
+ // conversion parameters
37
+ // the conversion is just a common linear function.
38
+ this._k = -this._stepHeight;
39
+ this._m = sliderHeight - (this._stepHeight + this._knobHeight) / 2;
40
+ },
41
+
42
+ setPosition: function (y) {
43
+ L.DomUtil.setPosition(this._element,
44
+ L.point(0, this._adjust(y)));
45
+ },
46
+
47
+ setValue: function (v) {
48
+ this.setPosition(this._toY(v));
49
+ },
50
+
51
+ getValue: function () {
52
+ return this._toValue(L.DomUtil.getPosition(this._element).y);
53
+ }
54
+ });
55
+
56
+ var Zoomslider = L.Control.extend({
57
+ options: {
58
+ position: 'topleft',
59
+ // Height of zoom-slider.png in px
60
+ stepHeight: 8,
61
+ // Height of the knob div in px (including border)
62
+ knobHeight: 6,
63
+ styleNS: 'leaflet-control-zoomslider'
64
+ },
65
+
66
+ onAdd: function (map) {
67
+ this._map = map;
68
+ this._ui = this._createUI();
69
+ this._knob = new Knob(this._ui.knob,
70
+ this.options.stepHeight,
71
+ this.options.knobHeight);
72
+
73
+ map .whenReady(this._initKnob, this)
74
+ .whenReady(this._initEvents, this)
75
+ .whenReady(this._updateSize, this)
76
+ .whenReady(this._updateKnobValue, this)
77
+ .whenReady(this._updateDisabled, this);
78
+ return this._ui.bar;
79
+ },
80
+
81
+ onRemove: function (map) {
82
+ map .off('zoomlevelschange', this._updateSize, this)
83
+ .off('zoomend zoomlevelschange', this._updateKnobValue, this)
84
+ .off('zoomend zoomlevelschange', this._updateDisabled, this);
85
+ },
86
+
87
+ _createUI: function () {
88
+ var ui = {},
89
+ ns = this.options.styleNS;
90
+
91
+ ui.bar = L.DomUtil.create('div', ns + ' leaflet-bar'),
92
+ ui.zoomIn = this._createZoomBtn('in', 'top', ui.bar),
93
+ ui.wrap = L.DomUtil.create('div', ns + '-wrap leaflet-bar-part', ui.bar),
94
+ ui.zoomOut = this._createZoomBtn('out', 'bottom', ui.bar),
95
+ ui.body = L.DomUtil.create('div', ns + '-body', ui.wrap),
96
+ ui.knob = L.DomUtil.create('div', ns + '-knob');
97
+
98
+ L.DomEvent.disableClickPropagation(ui.bar);
99
+ L.DomEvent.disableClickPropagation(ui.knob);
100
+
101
+ return ui;
102
+ },
103
+ _createZoomBtn: function (zoomDir, end, container) {
104
+ var classDef = this.options.styleNS + '-' + zoomDir
105
+ + ' leaflet-bar-part'
106
+ + ' leaflet-bar-part-' + end,
107
+ link = L.DomUtil.create('a', classDef, container);
108
+
109
+ link.href = '#';
110
+ link.title = 'Zoom ' + zoomDir;
111
+
112
+ L.DomEvent.on(link, 'click', L.DomEvent.preventDefault);
113
+
114
+ return link;
115
+ },
116
+
117
+ _initKnob: function () {
118
+ this._knob.enable();
119
+ this._ui.body.appendChild(this._ui.knob);
120
+ },
121
+ _initEvents: function (map) {
122
+ this._map
123
+ .on('zoomlevelschange', this._updateSize, this)
124
+ .on('zoomend zoomlevelschange', this._updateKnobValue, this)
125
+ .on('zoomend zoomlevelschange', this._updateDisabled, this);
126
+
127
+ L.DomEvent.on(this._ui.body, 'click', this._onSliderClick, this);
128
+ L.DomEvent.on(this._ui.zoomIn, 'click', this._zoomIn, this);
129
+ L.DomEvent.on(this._ui.zoomOut, 'click', this._zoomOut, this);
130
+
131
+ this._knob.on('dragend', this._updateMapZoom, this);
132
+ },
133
+
134
+ _onSliderClick: function (e) {
135
+ var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
136
+ y = L.DomEvent.getMousePosition(first).y
137
+ - L.DomUtil.getViewportOffset(this._ui.body).y; // Cache this?
138
+
139
+ this._knob.setPosition(y);
140
+ this._updateMapZoom();
141
+ },
142
+
143
+ _zoomIn: function (e) {
144
+ this._map.zoomIn(e.shiftKey ? 3 : 1);
145
+ },
146
+ _zoomOut: function (e) {
147
+ this._map.zoomOut(e.shiftKey ? 3 : 1);
148
+ },
149
+
150
+ _zoomLevels: function () {
151
+ var zoomLevels = this._map.getMaxZoom() - this._map.getMinZoom() + 1;
152
+ return zoomLevels < Infinity ? zoomLevels : 0;
153
+ },
154
+ _toZoomLevel: function (value) {
155
+ return value + this._map.getMinZoom();
156
+ },
157
+ _toValue: function (zoomLevel) {
158
+ return zoomLevel - this._map.getMinZoom();
159
+ },
160
+
161
+ _updateSize: function () {
162
+ var steps = this._zoomLevels();
163
+
164
+ this._ui.body.style.height = this.options.stepHeight * steps + 'px';
165
+ this._knob.setSteps(steps);
166
+ },
167
+ _updateMapZoom: function () {
168
+ this._map.setZoom(this._toZoomLevel(this._knob.getValue()));
169
+ },
170
+ _updateKnobValue: function () {
171
+ this._knob.setValue(this._toValue(this._map.getZoom()));
172
+ },
173
+ _updateDisabled: function () {
174
+ var zoomLevel = this._map.getZoom(),
175
+ className = this.options.styleNS + '-disabled';
176
+
177
+ L.DomUtil.removeClass(this._ui.zoomIn, className);
178
+ L.DomUtil.removeClass(this._ui.zoomOut, className);
179
+
180
+ if (zoomLevel === this._map.getMinZoom()) {
181
+ L.DomUtil.addClass(this._ui.zoomOut, className);
182
+ }
183
+ if (zoomLevel === this._map.getMaxZoom()) {
184
+ L.DomUtil.addClass(this._ui.zoomIn, className);
185
+ }
186
+ }
187
+ });
188
+
189
+ return Zoomslider;
190
+ })();
191
+
192
+ L.Map.mergeOptions({
193
+ zoomControl: false,
194
+ zoomsliderControl: true
195
+ });
196
+
197
+ L.Map.addInitHook(function () {
198
+ if (this.options.zoomsliderControl) {
199
+ this.zoomsliderControl = new L.Control.Zoomslider();
200
+ this.addControl(this.zoomsliderControl);
201
+ }
202
+ });
203
+
204
+ L.control.zoomslider = function (options) {
205
+ return new L.Control.Zoomslider(options);
206
+ };
@@ -0,0 +1,103 @@
1
+ /** Slider **/
2
+ .leaflet-control-zoomslider-wrap {
3
+ padding-top: 5px;
4
+ padding-bottom: 5px;
5
+ background-color: #fff;
6
+ border-bottom: 1px solid #ccc;
7
+ }
8
+ .leaflet-control-zoomslider-body {
9
+ width: 2px;
10
+ border: solid #fff;
11
+ border-width: 0px 9px 0px 9px;
12
+ background-color: black;
13
+ margin: 0 auto;
14
+ }
15
+ .leaflet-control-zoomslider-knob {
16
+ position: relative;
17
+ width: 12px;
18
+ height: 4px;
19
+ background-color: #efefef;
20
+ -webkit-border-radius: 2px;
21
+ border-radius: 2px;
22
+ border: 1px solid #000;
23
+ margin-left: -6px;
24
+ }
25
+ .leaflet-control-zoomslider-body:hover {
26
+ cursor: pointer;
27
+ }
28
+ .leaflet-control-zoomslider-knob:hover {
29
+ cursor: default;
30
+ cursor: -webkit-grab;
31
+ cursor: -moz-grab;
32
+ }
33
+
34
+ .leaflet-dragging .leaflet-control-zoomslider,
35
+ .leaflet-dragging .leaflet-control-zoomslider-wrap,
36
+ .leaflet-dragging .leaflet-control-zoomslider-body,
37
+ .leaflet-dragging .leaflet-control-zoomslider a,
38
+ .leaflet-dragging .leaflet-control-zoomslider a.leaflet-control-zoomslider-disabled,
39
+ .leaflet-dragging .leaflet-control-zoomslider-knob:hover {
40
+ cursor: move;
41
+ cursor: -webkit-grabbing;
42
+ cursor: -moz-grabbing;
43
+ }
44
+
45
+ /** Leaflet Zoom Styles **/
46
+ .leaflet-container .leaflet-control-zoomslider {
47
+ margin-left: 10px;
48
+ margin-top: 10px;
49
+ }
50
+ .leaflet-control-zoomslider a {
51
+ width: 26px;
52
+ height: 26px;
53
+ text-align: center;
54
+ text-decoration: none;
55
+ color: black;
56
+ display: block;
57
+ }
58
+ .leaflet-control-zoomslider a:hover {
59
+ background-color: #f4f4f4;
60
+ }
61
+ .leaflet-control-zoomslider-in {
62
+ font: bold 18px 'Lucida Console', Monaco, monospace;
63
+ }
64
+ .leaflet-control-zoomslider-in:after{
65
+ content:"+"
66
+ }
67
+ .leaflet-control-zoomslider-out {
68
+ font: bold 22px 'Lucida Console', Monaco, monospace;
69
+ }
70
+ .leaflet-control-zoomslider-out:after{
71
+ content:"-"
72
+ }
73
+ .leaflet-control-zoomslider a.leaflet-control-zoomslider-disabled {
74
+ cursor: default;
75
+ color: #bbb;
76
+ }
77
+
78
+ /* Touch */
79
+ .leaflet-touch .leaflet-control-zoomslider-body {
80
+ background-position: 10px 0px;
81
+ }
82
+ .leaflet-touch .leaflet-control-zoomslider-knob {
83
+ width:16px;
84
+ margin-left: -1px;
85
+ }
86
+ .leaflet-touch .leaflet-control-zoomslider a {
87
+ width: 30px;
88
+ height: 30px;
89
+ }
90
+ .leaflet-touch .leaflet-control-zoomslider-in {
91
+ font-size: 24px;
92
+ line-height: 29px;
93
+ }
94
+ .leaflet-touch .leaflet-control-zoomslider-out {
95
+ font-size: 28px;
96
+ line-height: 30px;
97
+ }
98
+ .leaflet-touch .leaflet-control-zoomslider {
99
+ box-shadow: none;
100
+ }
101
+ .leaflet-touch .leaflet-control-zoomslider {
102
+ border: 4px solid rgba(0,0,0,0.3);
103
+ }
@@ -0,0 +1,16 @@
1
+ /* IE6-7 specific hacks */
2
+ .leaflet-control-zoomslider-wrap {
3
+ *width: 26px;
4
+ }
5
+ /* Fix IE6-divs having a too large min height */
6
+ .leaflet-control-zoomslider-knob {
7
+ *overflow: hidden;
8
+ }
9
+
10
+ /* Support for element:after { content: 'text' } */
11
+ .leaflet-control-zoomslider-in {
12
+ *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '+');
13
+ }
14
+ .leaflet-control-zoomslider-out {
15
+ *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '-');
16
+ }
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leaflet-zoomslider-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Klaas Endrikat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Integrates the Leaflet ZoomSlider plugin with Rails asset pipeline
15
+ email:
16
+ - klaas.endrikat@googlemail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - leaflet-zoomslider-rails.gemspec
27
+ - lib/leaflet-zoomslider-rails.rb
28
+ - lib/leaflet-zoomslider-rails/version.rb
29
+ - vendor/assets/javascripts/leaflet.zoomslider.js
30
+ - vendor/assets/stylesheets/leaflet.zoomslider.css
31
+ - vendor/assets/stylesheets/leaflet.zoomslider.ie.css
32
+ homepage: https://github.com/kendrikat/leaflet-zoomslider-rails
33
+ licenses:
34
+ - MIT
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Leaflet ZoomSlider plugin for Rails
57
+ test_files: []