diff --git a/README.md b/README.md index a23f967..d5e2ad9 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Then run the tests by opening [test/index.html](test/index.html) in a browser. - [showPanel](#showpanel) - [hidePanel](#hidepanel) - [renderPanel](#renderpanel) + - [renderPanel](#renderpanel-1) - [forEachRecursive](#foreachrecursive) - [uuid](#uuid) diff --git a/dist/ol-layerswitcher.js b/dist/ol-layerswitcher.js index 014b33f..aff0aed 100644 --- a/dist/ol-layerswitcher.js +++ b/dist/ol-layerswitcher.js @@ -182,7 +182,7 @@ var LayerSwitcher = function (_Control) { this.mapListeners.push(map.on('pointerdown', function () { this_.hidePanel(); })); - LayerSwitcher.renderPanel(this.panel, this.getMap()); + this.renderPanel(); } } @@ -195,7 +195,7 @@ var LayerSwitcher = function (_Control) { value: function showPanel() { if (!this.element.classList.contains(this.shownClassName)) { this.element.classList.add(this.shownClassName); - LayerSwitcher.renderPanel(this.panel, this.getMap()); + this.renderPanel(); } } @@ -211,15 +211,25 @@ var LayerSwitcher = function (_Control) { } } + /** + * Re-draw the layer panel to represent the current state of the layers. + */ + + }, { + key: 'renderPanel', + value: function renderPanel() { + LayerSwitcher.renderPanel(this.getMap(), this.panel); + } + /** * **Static** Re-draw the layer panel to represent the current state of the layers. - * @param {Element} panel The DOM Element into which the layer tree will be rendered * @param {ol.Map} map The OpenLayers Map instance to render layers for + * @param {Element} panel The DOM Element into which the layer tree will be rendered */ }], [{ key: 'renderPanel', - value: function renderPanel(panel, map) { + value: function renderPanel(map, panel) { LayerSwitcher.ensureTopVisibleBaseLayerShown_(map); @@ -235,6 +245,7 @@ var LayerSwitcher = function (_Control) { /** * **Static** Ensure only the top-most base layer is visible if more than one is visible. + * @param {ol.Map} map The map instance. * @private */ @@ -255,6 +266,7 @@ var LayerSwitcher = function (_Control) { * Takes care of hiding other layers in the same exclusive group if the layer * is toggle to visible. * @private + * @param {ol.Map} map The map instance. * @param {ol.layer.Base} The layer whos visibility will be toggled. */ @@ -275,6 +287,7 @@ var LayerSwitcher = function (_Control) { /** * **Static** Render all layers that are children of a group. * @private + * @param {ol.Map} map The map instance. * @param {ol.layer.Base} lyr Layer to be rendered (should have a title property). * @param {Number} idx Position in parent group list. */ @@ -333,6 +346,7 @@ var LayerSwitcher = function (_Control) { /** * **Static** Render all layers that are children of a group. * @private + * @param {ol.Map} map The map instance. * @param {ol.layer.Group} lyr Group layer whos children will be rendered. * @param {Element} elm DOM element that children will be appended to. */ diff --git a/src/ol-layerswitcher.js b/src/ol-layerswitcher.js index 84d7136..81801ad 100644 --- a/src/ol-layerswitcher.js +++ b/src/ol-layerswitcher.js @@ -79,7 +79,7 @@ export default class LayerSwitcher extends Control { this.mapListeners.push(map.on('pointerdown', function() { this_.hidePanel(); })); - LayerSwitcher.renderPanel(this.panel, this.getMap()); + this.renderPanel(); } } @@ -89,7 +89,7 @@ export default class LayerSwitcher extends Control { showPanel() { if (!this.element.classList.contains(this.shownClassName)) { this.element.classList.add(this.shownClassName); - LayerSwitcher.renderPanel(this.panel, this.getMap()); + this.renderPanel(); } } @@ -102,6 +102,13 @@ export default class LayerSwitcher extends Control { } } + /** + * Re-draw the layer panel to represent the current state of the layers. + */ + renderPanel() { + LayerSwitcher.renderPanel(this.getMap(), this.panel); + } + /** * **Static** Re-draw the layer panel to represent the current state of the layers. * @param {ol.Map} map The OpenLayers Map instance to render layers for diff --git a/test/spec/ol-layerswitcher.js b/test/spec/ol-layerswitcher.js index d44c5d5..0323178 100644 --- a/test/spec/ol-layerswitcher.js +++ b/test/spec/ol-layerswitcher.js @@ -256,7 +256,7 @@ describe('ol.control.LayerSwitcher', function() { l.setVisible(true); }); - ol.control.LayerSwitcher.renderPanel(switcher.getMap(), switcher.panel); + switcher.renderPanel(); var visibleBaseLayerCount = _.countBy(baseLayers, function (l){ return l.getVisible(); }); @@ -271,13 +271,13 @@ describe('ol.control.LayerSwitcher', function() { _.forEach(baseLayers, function (l) { l.setVisible(true); }); - ol.control.LayerSwitcher.renderPanel(switcher.getMap(), switcher.panel); + switcher.renderPanel(); expect(cbg.getVisible()).to.be(true); }); it('Clicking on unchecked base layer shows it', function() { var too = getLayerByTitle('Too'); too.setVisible(false); - ol.control.LayerSwitcher.renderPanel(switcher.getMap(), switcher.panel); + switcher.renderPanel(); jQuery('.layer-switcher label:contains("Too")').siblings('input').click(); expect(too.getVisible()).to.be(true); expect(jQuery('.layer-switcher label:contains("Too")').siblings('input').get(0).checked).to.be(true); @@ -285,7 +285,7 @@ describe('ol.control.LayerSwitcher', function() { it('Clicking on checked base layer does not change base layer', function() { var foo = getLayerByTitle('Foo'); foo.setVisible(true); - ol.control.LayerSwitcher.renderPanel(switcher.getMap(), switcher.panel); + switcher.renderPanel(); jQuery('.layer-switcher label:contains("Foo")').siblings('input').click(); expect(foo.getVisible()).to.be(true); expect(jQuery('.layer-switcher label:contains("Foo")').siblings('input').get(0).checked).to.be(true);