ソースを参照

2.0.0

gh-pages
Gregor MacLennan 9年前
コミット
b7279c0b4a
3個のファイルの変更50行の追加15行の削除
  1. 48
    13
      leaflet-side-by-side.js
  2. 1
    1
      leaflet-side-by-side.min.js
  3. 1
    1
      package.json

+ 48
- 13
leaflet-side-by-side.js ファイルの表示

@@ -5,6 +5,7 @@ require('./layout.css')
5 5
 require('./range.css')
6 6
 
7 7
 var mapWasDragEnabled
8
+var mapWasTapEnabled
8 9
 
9 10
 // Leaflet v0.7 backwards compatibility
10 11
 function on (el, types, fn, context) {
@@ -26,13 +27,24 @@ function getRangeEvent (rangeInput) {
26 27
 
27 28
 function cancelMapDrag () {
28 29
   mapWasDragEnabled = this._map.dragging.enabled()
30
+  mapWasTapEnabled = this._map.tap && this._map.tap.enabled()
29 31
   this._map.dragging.disable()
32
+  this._map.tap && this._map.tap.disable()
30 33
 }
31 34
 
32 35
 function uncancelMapDrag (e) {
33
-  if (!mapWasDragEnabled) return
34 36
   this._refocusOnMap(e)
35
-  this._map.dragging.enable()
37
+  if (mapWasDragEnabled) {
38
+    this._map.dragging.enable()
39
+  }
40
+  if (mapWasTapEnabled) {
41
+    this._map.tap.enable()
42
+  }
43
+}
44
+
45
+// convert arg to an array - returns empty array if arg is undefined
46
+function asArray (arg) {
47
+  return (arg === 'undefined') ? [] : Array.isArray(arg) ? arg : [arg]
36 48
 }
37 49
 
38 50
 function noop () {
@@ -40,12 +52,22 @@ function noop () {
40 52
 }
41 53
 
42 54
 L.Control.SideBySide = L.Control.extend({
43
-  initialize: function (leftLayers, rightLayers) {
44
-    this._leftLayers = Array.isArray(leftLayers) ? leftLayers : [leftLayers]
45
-    this._rightLayers = Array.isArray(rightLayers) ? rightLayers : [rightLayers]
55
+  options: {
56
+    thumbSize: 42,
57
+    padding: 0
46 58
   },
47 59
 
48
-  getPosition: noop,
60
+  initialize: function (leftLayers, rightLayers, options) {
61
+    this.setLeftLayers(leftLayers)
62
+    this.setRightLayers(rightLayers)
63
+    L.setOptions(this, options)
64
+  },
65
+
66
+  getPosition: function () {
67
+    var rangeValue = this._range.value
68
+    var offset = (0.5 - rangeValue) * (2 * this.options.padding + this.options.thumbSize)
69
+    return this._map.getSize().x * rangeValue + offset
70
+  },
49 71
 
50 72
   setPosition: noop,
51 73
 
@@ -64,9 +86,9 @@ L.Control.SideBySide = L.Control.extend({
64 86
     range.max = 1
65 87
     range.step = 'any'
66 88
     range.value = 0.5
89
+    range.style.paddingLeft = range.style.paddingRight = this.options.padding + 'px'
67 90
     this._addEvents()
68 91
     this._updateLayers()
69
-    this._updateClip()
70 92
     return this
71 93
   },
72 94
 
@@ -82,14 +104,24 @@ L.Control.SideBySide = L.Control.extend({
82 104
     return this
83 105
   },
84 106
 
107
+  setLeftLayers: function (leftLayers) {
108
+    this._leftLayers = asArray(leftLayers)
109
+    this._updateLayers()
110
+    return this
111
+  },
112
+
113
+  setRightLayers: function (rightLayers) {
114
+    this._rightLayers = asArray(rightLayers)
115
+    this._updateLayers()
116
+    return this
117
+  },
118
+
85 119
   _updateClip: function () {
86 120
     var map = this._map
87
-    var rangeValue = this._range.value
88 121
     var nw = map.containerPointToLayerPoint([0, 0])
89 122
     var se = map.containerPointToLayerPoint(map.getSize())
90
-    var offset = (0.5 - rangeValue) * 44
91
-    var clipX = nw.x + (se.x - nw.x) * rangeValue + offset
92
-    var dividerX = map.getSize().x * rangeValue + offset
123
+    var clipX = nw.x + this.getPosition()
124
+    var dividerX = this.getPosition()
93 125
 
94 126
     this._divider.style.left = dividerX + 'px'
95 127
     this.fire('dividermove', {x: dividerX})
@@ -104,6 +136,9 @@ L.Control.SideBySide = L.Control.extend({
104 136
   },
105 137
 
106 138
   _updateLayers: function () {
139
+    if (!this._map) {
140
+      return this
141
+    }
107 142
     var prevLeft = this._leftLayer
108 143
     var prevRight = this._rightLayer
109 144
     this._leftLayer = this._rightLayer = null
@@ -154,11 +189,11 @@ L.Control.SideBySide = L.Control.extend({
154 189
   }
155 190
 })
156 191
 
157
-L.Control.sideBySide = function (leftLayers, rightLayers, options) {
192
+L.control.sideBySide = function (leftLayers, rightLayers, options) {
158 193
   return new L.Control.SideBySide(leftLayers, rightLayers, options)
159 194
 }
160 195
 
161
-module.export = L.Control.sideBySide
196
+module.exports = L.Control.SideBySide
162 197
 
163 198
 }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
164 199
 },{"./layout.css":2,"./range.css":4}],2:[function(require,module,exports){

+ 1
- 1
leaflet-side-by-side.min.js
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 1
- 1
package.json ファイルの表示

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "leaflet-side-by-side",
3
-  "version": "1.1.1",
3
+  "version": "2.0.0",
4 4
   "description": "Compare two Leaflet layers side by side",
5 5
   "main": "index.js",
6 6
   "browserify": {

読み込み中…
キャンセル
保存