Browse Source

Add setLeftLayers() and setRightLayers()

gh-pages
Gregor MacLennan 9 years ago
parent
commit
8f428aa6e7
3 changed files with 38 additions and 7 deletions
  1. 10
    2
      CHANGELOG.md
  2. 9
    2
      README.md
  3. 19
    3
      index.js

+ 10
- 2
CHANGELOG.md View File

3
 All notable changes to this project will be documented in this file.
3
 All notable changes to this project will be documented in this file.
4
 This project adheres to [Semantic Versioning](http://semver.org/).
4
 This project adheres to [Semantic Versioning](http://semver.org/).
5
 
5
 
6
-## v1.1.1
6
+## Unreleased
7
+
8
+- ADDED: Add `setLeftLayers()` and `setRightLayers()` methods
9
+
10
+## [v1.1.1] - 2015-12-03
7
 
11
 
8
 - FIXED: fix package.json settings for npm distribution
12
 - FIXED: fix package.json settings for npm distribution
9
 
13
 
10
-## v1.1.0 - 2015-12-03
14
+## [v1.1.0] - 2015-12-03
11
 
15
 
12
 - ADDED: Events
16
 - ADDED: Events
13
 - FIXED: Fix initial divider position in Firefox, should start in middle of map
17
 - FIXED: Fix initial divider position in Firefox, should start in middle of map
15
 ## v1.0.2 - 2015-12-02
19
 ## v1.0.2 - 2015-12-02
16
 
20
 
17
 Initial release
21
 Initial release
22
+
23
+[Unreleased]: https://github.com/digidem/leaflet-side-by-side/compare/v1.1.1...HEAD
24
+[v1.1.1]: https://github.com/digidem/leaflet-side-by-side/compare/v1.1.0...v1.1.1
25
+[v1.1.0]: https://github.com/digidem/leaflet-side-by-side/compare/v1.0.2...v1.1.0

+ 9
- 2
README.md View File

12
 
12
 
13
 | parameter     | type           | description   |
13
 | parameter     | type           | description   |
14
 | ----------    | -------------- | ------------- |
14
 | ----------    | -------------- | ------------- |
15
-| `leftLayers`  | L.Layer\|array | A Leaflet Layer or array of layers to show on the left side of the map. Any layers in this array that are added to the map will be shown on the left |
16
-| `rightLayers` | L.Layer\|array | A Leaflet Layer or array of layers to show on the right side of the map. Any layers in this array that are added to the map will be shown on the right. These *should not be the same as any layers in `leftLayers`* |
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
+| `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
 
17
 
18
 ### Events
18
 ### Events
19
 
19
 
27
 | `rightlayerremove` | [LayerEvent](http://leafletjs.com/reference.html#layer-event) | You guessed it... fired when a layer is removed from the right-hand-side pane |
27
 | `rightlayerremove` | [LayerEvent](http://leafletjs.com/reference.html#layer-event) | You guessed it... fired when a layer is removed from the right-hand-side pane |
28
 | `dividermove` | {x: Number} | Fired when the divider is moved. Returns an event object with the property `x` = the pixels of the divider from the left side of the map container. |
28
 | `dividermove` | {x: Number} | Fired when the divider is moved. Returns an event object with the property `x` = the pixels of the divider from the left side of the map container. |
29
 
29
 
30
+### Methods
31
+
32
+| Method           | Returns        | Description   |
33
+| ----------       | -------------- | ------------- |
34
+| `setLeftLayers`  | `this`         | Set the layer(s) for the left side  |
35
+| `setRightLayers` | `this`         | Set the layer(s) for the right side |
36
+
30
 ### Usage
37
 ### Usage
31
 
38
 
32
 Add the script to the top of your page (css is included in the javascript):
39
 Add the script to the top of your page (css is included in the javascript):

+ 19
- 3
index.js View File

33
   this._map.dragging.enable()
33
   this._map.dragging.enable()
34
 }
34
 }
35
 
35
 
36
+// convert arg to an array - returns empty array if arg is undefined
37
+function asArray(arg) {
38
+  return (arg === 'undefined') ? [] : Array.isArray(arg) ? arg : [arg]
39
+}
40
+
36
 function noop () {
41
 function noop () {
37
   return
42
   return
38
 }
43
 }
39
 
44
 
40
 L.Control.SideBySide = L.Control.extend({
45
 L.Control.SideBySide = L.Control.extend({
41
   initialize: function (leftLayers, rightLayers) {
46
   initialize: function (leftLayers, rightLayers) {
42
-    this._leftLayers = Array.isArray(leftLayers) ? leftLayers : [leftLayers]
43
-    this._rightLayers = Array.isArray(rightLayers) ? rightLayers : [rightLayers]
47
+    this.setLeftLayers(leftLayers)
48
+    this.setRightLayers(rightLayers)
44
   },
49
   },
45
 
50
 
46
   getPosition: noop,
51
   getPosition: noop,
64
     range.value = 0.5
69
     range.value = 0.5
65
     this._addEvents()
70
     this._addEvents()
66
     this._updateLayers()
71
     this._updateLayers()
67
-    this._updateClip()
68
     return this
72
     return this
69
   },
73
   },
70
 
74
 
80
     return this
84
     return this
81
   },
85
   },
82
 
86
 
87
+  setLeftLayers: function (leftLayers) {
88
+    this._leftLayers = asArray(leftLayers)
89
+    this._updateLayers()
90
+    return this
91
+  },
92
+
93
+  setRightLayers: function (rightLayers) {
94
+    this._rightLayers = asArray(rightLayers)
95
+    this._updateLayers()
96
+    return this
97
+  },
98
+
83
   _updateClip: function () {
99
   _updateClip: function () {
84
     var map = this._map
100
     var map = this._map
85
     var rangeValue = this._range.value
101
     var rangeValue = this._range.value

Loading…
Cancel
Save