rlayers
Version:
React Components for OpenLayers
53 lines • 2.09 kB
JavaScript
import React from 'react';
import { RContext } from '../context';
import { RlayersBase } from '../REvent';
import debug from '../debug';
/**
* Abstract base class for all layers, not meant to be used directly
*/
export default class RLayer extends RlayersBase {
constructor(props) {
super(props);
}
refresh(prevProps) {
var _a;
super.refresh(prevProps);
for (const p of [
'visible',
'opacity',
'zIndex',
'minResolution',
'maxResolution',
'minZoom',
'maxZoom'
]) {
const m = p.charAt(0).toUpperCase() + p.substring(1);
if (((_a = this.props) === null || _a === void 0 ? void 0 : _a[p]) !== (prevProps === null || prevProps === void 0 ? void 0 : prevProps[p])) {
debug('Setting', this, m, this.props[p]);
this.ol['set' + m](this.props[p]);
}
}
if (this.source && this.props.attributions !== (prevProps === null || prevProps === void 0 ? void 0 : prevProps.attributions)) {
debug('Setting attributions', this);
this.source.setAttributions(this.props.attributions);
}
if (this.props.properties)
this.ol.setProperties(this.props.properties);
}
componentDidMount() {
super.componentDidMount();
this.context.map.addLayer(this.ol);
}
componentWillUnmount() {
super.componentWillUnmount();
this.context.map.removeLayer(this.ol);
}
render() {
var _a, _b;
if (!((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.addLayer))
throw new Error('A layer must be part of a map');
return (React.createElement("div", { className: '_rlayers_RLayer' },
React.createElement(RContext.Provider, { value: Object.assign(Object.assign({}, this.context), { layer: this.ol, source: this.source, rLayer: this }) }, this.props.children)));
}
}
//# sourceMappingURL=RLayer.js.map