@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
57 lines (56 loc) • 1.61 kB
JavaScript
import { getOlayerByName } from '../utils/olutils';
import SimpleMaskLayer from './simplemasklayer';
const MASK_LAYER_NAME = 'SimpleMask';
/**
* Manager to display a simple mask layer with a cut-out box in the middle.
*/
class SimpleMaskManager {
constructor(map) {
Object.defineProperty(this, "maskLayer", {
enumerable: true,
configurable: true,
writable: true,
value: new SimpleMaskLayer({ name: MASK_LAYER_NAME })
});
Object.defineProperty(this, "map", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "visible", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
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;