Bläddra i källkod

Add setLeftLayers() and setRightLayers()

gh-pages
Gregor MacLennan 9 år sedan
förälder
incheckning
8f428aa6e7
3 ändrade filer med 38 tillägg och 7 borttagningar
  1. 10
    2
      CHANGELOG.md
  2. 9
    2
      README.md
  3. 19
    3
      index.js

+ 10
- 2
CHANGELOG.md Visa fil

@@ -3,11 +3,15 @@
3 3
 All notable changes to this project will be documented in this file.
4 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 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 16
 - ADDED: Events
13 17
 - FIXED: Fix initial divider position in Firefox, should start in middle of map
@@ -15,3 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
15 19
 ## v1.0.2 - 2015-12-02
16 20
 
17 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 Visa fil

@@ -12,8 +12,8 @@ Creates a new Leaflet Control for comparing two layers or collections of layers.
12 12
 
13 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 18
 ### Events
19 19
 
@@ -27,6 +27,13 @@ Subscribe to events using [these methods](http://leafletjs.com/reference.html#ev
27 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 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 37
 ### Usage
31 38
 
32 39
 Add the script to the top of your page (css is included in the javascript):

+ 19
- 3
index.js Visa fil

@@ -33,14 +33,19 @@ function uncancelMapDrag (e) {
33 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 41
 function noop () {
37 42
   return
38 43
 }
39 44
 
40 45
 L.Control.SideBySide = L.Control.extend({
41 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 51
   getPosition: noop,
@@ -64,7 +69,6 @@ L.Control.SideBySide = L.Control.extend({
64 69
     range.value = 0.5
65 70
     this._addEvents()
66 71
     this._updateLayers()
67
-    this._updateClip()
68 72
     return this
69 73
   },
70 74
 
@@ -80,6 +84,18 @@ L.Control.SideBySide = L.Control.extend({
80 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 99
   _updateClip: function () {
84 100
     var map = this._map
85 101
     var rangeValue = this._range.value

Laddar…
Avbryt
Spara