소스 검색

Add padding option

gh-pages
Gregor MacLennan 9 년 전
부모
커밋
cf35a6616a
3개의 변경된 파일12개의 추가작업 그리고 2개의 파일을 삭제
  1. 1
    0
      CHANGELOG.md
  2. 2
    0
      README.md
  3. 9
    2
      index.js

+ 1
- 0
CHANGELOG.md 파일 보기

@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6 6
 ## Unreleased
7 7
 
8 8
 - ADDED: Add `setLeftLayers()` and `setRightLayers()` methods
9
+- ADDED: `options.padding`
9 10
 - FIXED: **[BREAKING]** Export factory function on `L.control` not `L.Control`
10 11
 
11 12
 ## [v1.1.1] - 2015-12-03

+ 2
- 0
README.md 파일 보기

@@ -14,6 +14,8 @@ Creates a new Leaflet Control for comparing two layers or collections of layers.
14 14
 | ----------    | -------------- | ------------- |
15 15
 | `leftLayers`  | L.Layer\|array | A Leaflet Layer or array of layers to show on the left side of the map. Any layer added to the map that is in this array will be shown on the left |
16 16
 | `rightLayers` | L.Layer\|array | A Leaflet Layer or array of layers to show on the right side of the map. Any layer added to the map that is in this array will be shown on the right. These *should not be* the same as any layers in `leftLayers` |
17
+| `options`     | Object         | Options |
18
+| `options.padding` | Number     | Padding between slider min/max and the edge of the screen in pixels. Defaults to `44` - the width of the slider thumb |
17 19
 
18 20
 ### Events
19 21
 

+ 9
- 2
index.js 파일 보기

@@ -43,9 +43,15 @@ function noop () {
43 43
 }
44 44
 
45 45
 L.Control.SideBySide = L.Control.extend({
46
-  initialize: function (leftLayers, rightLayers) {
46
+  options: {
47
+    thumbSize: 42,
48
+    padding: 0
49
+  },
50
+
51
+  initialize: function (leftLayers, rightLayers, options) {
47 52
     this.setLeftLayers(leftLayers)
48 53
     this.setRightLayers(rightLayers)
54
+    L.setOptions(this, options)
49 55
   },
50 56
 
51 57
   getPosition: noop,
@@ -67,6 +73,7 @@ L.Control.SideBySide = L.Control.extend({
67 73
     range.max = 1
68 74
     range.step = 'any'
69 75
     range.value = 0.5
76
+    range.style.paddingLeft = range.style.paddingRight = this.options.padding + 'px'
70 77
     this._addEvents()
71 78
     this._updateLayers()
72 79
     return this
@@ -101,7 +108,7 @@ L.Control.SideBySide = L.Control.extend({
101 108
     var rangeValue = this._range.value
102 109
     var nw = map.containerPointToLayerPoint([0, 0])
103 110
     var se = map.containerPointToLayerPoint(map.getSize())
104
-    var offset = (0.5 - rangeValue) * 44
111
+    var offset = (0.5 - rangeValue) * (2 * this.options.padding + this.options.thumbSize)
105 112
     var clipX = nw.x + (se.x - nw.x) * rangeValue + offset
106 113
     var dividerX = map.getSize().x * rangeValue + offset
107 114
 

Loading…
취소
저장