Przeglądaj źródła

Add get position

gh-pages
Gregor MacLennan 9 lat temu
rodzic
commit
074522a69a
2 zmienionych plików z 8 dodań i 5 usunięć
  1. 1
    0
      CHANGELOG.md
  2. 7
    5
      index.js

+ 1
- 0
CHANGELOG.md Wyświetl plik

@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7 7
 
8 8
 - ADDED: Add `setLeftLayers()` and `setRightLayers()` methods
9 9
 - ADDED: `options.padding`
10
+- ADDED: `getPosition()` returns the x coordinate (relative to the map container) of the divider
10 11
 - FIXED: **[BREAKING]** Export factory function on `L.control` not `L.Control`
11 12
 - FIXED: Slider drag was not working on touch devices
12 13
 

+ 7
- 5
index.js Wyświetl plik

@@ -61,7 +61,11 @@ L.Control.SideBySide = L.Control.extend({
61 61
     L.setOptions(this, options)
62 62
   },
63 63
 
64
-  getPosition: noop,
64
+  getPosition: function () {
65
+    var rangeValue = this._range.value
66
+    var offset = (0.5 - rangeValue) * (2 * this.options.padding + this.options.thumbSize)
67
+    return this._map.getSize().x * rangeValue + offset
68
+  },
65 69
 
66 70
   setPosition: noop,
67 71
 
@@ -112,12 +116,10 @@ L.Control.SideBySide = L.Control.extend({
112 116
 
113 117
   _updateClip: function () {
114 118
     var map = this._map
115
-    var rangeValue = this._range.value
116 119
     var nw = map.containerPointToLayerPoint([0, 0])
117 120
     var se = map.containerPointToLayerPoint(map.getSize())
118
-    var offset = (0.5 - rangeValue) * (2 * this.options.padding + this.options.thumbSize)
119
-    var clipX = nw.x + (se.x - nw.x) * rangeValue + offset
120
-    var dividerX = map.getSize().x * rangeValue + offset
121
+    var clipX = nw.x + this.getPosition()
122
+    var dividerX = this.getPosition()
121 123
 
122 124
     this._divider.style.left = dividerX + 'px'
123 125
     this.fire('dividermove', {x: dividerX})

Ładowanie…
Anuluj
Zapisz