@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
42 lines (41 loc) • 1.14 kB
JavaScript
import { getOlayerByName } from '../utils/olutils.js';
import SimpleMaskLayer from './simplemasklayer.js';
const MASK_LAYER_NAME = 'SimpleMask';
/**
* Manager to display a simple mask layer with a cut-out box in the middle.
*/
class SimpleMaskManager {
maskLayer = new SimpleMaskLayer({ name: MASK_LAYER_NAME });
map;
visible = false;
constructor(map) {
this.map = map;
}
/**
* Display the mask or hide it.
*/
setMaskVisibility(visible) {
const isLayerInMap = getOlayerByName(this.map, MASK_LAYER_NAME);
this.visible = visible;
if (this.visible && !isLayerInMap) {
this.map.addLayer(this.maskLayer);
return;
}
if (!this.visible && isLayerInMap) {
this.map.removeLayer(this.maskLayer);
}
}
/**
* Update the size (width, height), in pixels of the mask.
*/
setMaskSize(size) {
this.maskLayer.updateSize(size);
this.renderMask();
}
renderMask() {
if (this.visible) {
this.maskLayer.changed();
}
}
}
export default SimpleMaskManager;