Skip to content

Commit

Permalink
[ADD] event on layer visible/opacity change
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Mar 12, 2021
1 parent a48e013 commit 4ce46d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions dist/ol-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2667,12 +2667,13 @@ ol.control.SearchGeoportail.prototype.searchCommune = function (f, cback) {
released under the CeCILL-B license (French BSD license)
(http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt).
*/
/**
* @classdesc OpenLayers 3 Layer Switcher Control.
/** Layer Switcher Control.
* @fires drawlist
* @fires toggle
* @fires reorder-start
* @fires reorder-end
* @fires layer:visible
* @fires layer:opacity
*
* @constructor
* @extends {ol.control.Control}
Expand All @@ -2691,7 +2692,7 @@ ol.control.SearchGeoportail.prototype.searchCommune = function (f, cback) {
*
* Layers attributes that control the switcher
* - allwaysOnTop {boolean} true to force layer stay on top of the others while reordering, default false
* - displayInLayerSwitcher {boolean} display in switcher, default true
* - displayInLayerSwitcher {boolean} display the layer in switcher, default true
* - noSwitcherDelete {boolean} to prevent layer deletion (w. trash option = true), default false
*/
ol.control.LayerSwitcher = function(options) {
Expand Down Expand Up @@ -2947,6 +2948,7 @@ ol.control.LayerSwitcher.prototype._setLayerForLI = function(li, layer) {
ol.control.LayerSwitcher.prototype.setLayerOpacity = function(layer, li) {
var i = li.querySelector('.layerswitcher-opacity-cursor')
if (i) i.style.left = (layer.getOpacity()*100)+"%"
this.dispatchEvent({ type: 'layer:opacity', layer: layer });
};
/** Set visibility for a layer
* @param {ol.layer.Layer} layer
Expand All @@ -2958,6 +2960,7 @@ ol.control.LayerSwitcher.prototype.setLayerVisibility = function(layer, li) {
if (i) i.checked = layer.getVisible();
if (layer.getVisible()) li.classList.add('ol-visible');
else li.classList.remove('ol-visible');
this.dispatchEvent({ type: 'layer:visible', layer: layer });
};
/** Clear layers associated with li
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/ol-ext.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/control/LayerSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import {intersects as ol_extent_intersects} from 'ol/extent'

import ol_ext_element from '../util/element'

/**
* @classdesc OpenLayers 3 Layer Switcher Control.
/** Layer Switcher Control.
* @fires drawlist
* @fires toggle
* @fires reorder-start
* @fires reorder-end
* @fires layer:visible
* @fires layer:opacity
*
* @constructor
* @extends {ol_control_Control}
Expand All @@ -38,7 +39,7 @@ import ol_ext_element from '../util/element'
*
* Layers attributes that control the switcher
* - allwaysOnTop {boolean} true to force layer stay on top of the others while reordering, default false
* - displayInLayerSwitcher {boolean} display in switcher, default true
* - displayInLayerSwitcher {boolean} display the layer in switcher, default true
* - noSwitcherDelete {boolean} to prevent layer deletion (w. trash option = true), default false
*/
var ol_control_LayerSwitcher = function(options) {
Expand Down Expand Up @@ -318,6 +319,7 @@ ol_control_LayerSwitcher.prototype._setLayerForLI = function(li, layer) {
ol_control_LayerSwitcher.prototype.setLayerOpacity = function(layer, li) {
var i = li.querySelector('.layerswitcher-opacity-cursor')
if (i) i.style.left = (layer.getOpacity()*100)+"%"
this.dispatchEvent({ type: 'layer:opacity', layer: layer });
};

/** Set visibility for a layer
Expand All @@ -330,6 +332,7 @@ ol_control_LayerSwitcher.prototype.setLayerVisibility = function(layer, li) {
if (i) i.checked = layer.getVisible();
if (layer.getVisible()) li.classList.add('ol-visible');
else li.classList.remove('ol-visible');
this.dispatchEvent({ type: 'layer:visible', layer: layer });
};

/** Clear layers associated with li
Expand Down

0 comments on commit 4ce46d2

Please sign in to comment.