Skip to content

Commit

Permalink
Reinstate LayerSwitcher#renderPanel instance method
Browse files Browse the repository at this point in the history
Avoid breaking the public API.
  • Loading branch information
walkermatt committed Sep 6, 2018
1 parent 8b20ad9 commit de7a6df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 18 additions & 4 deletions dist/ol-layerswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}

Expand All @@ -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);

Expand All @@ -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
*/

Expand All @@ -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.
*/

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
11 changes: 9 additions & 2 deletions src/ol-layerswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/spec/ol-layerswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -271,21 +271,21 @@ 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);
});
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);
Expand Down

0 comments on commit de7a6df

Please sign in to comment.