rlayers
Version:
React Components for OpenLayers
32 lines • 1.02 kB
JavaScript
import { RlayersBase } from '../REvent';
/**
* An abstract class serving as base for all controls, not meant to be used directly
*/
export default class RControlBase extends RlayersBase {
constructor(props, context) {
var _a;
super(props, context);
if (!((_a = this.context) === null || _a === void 0 ? void 0 : _a.map))
throw new Error('A control must be part of a map');
}
toOLProps(props) {
var _a;
return {
className: props.className,
target: (_a = props.target) === null || _a === void 0 ? void 0 : _a.current
};
}
refresh(prevProps) {
super.refresh(prevProps);
this.ol.setProperties(this.toOLProps(this.props));
}
componentDidMount() {
super.componentDidMount();
this.context.map.addControl(this.ol);
}
componentWillUnmount() {
super.componentWillUnmount();
this.context.map.removeControl(this.ol);
}
}
//# sourceMappingURL=RControlBase.js.map