UNPKG

rlayers

Version:

React Components for OpenLayers

46 lines 1.54 kB
import { RlayersBase } from '../REvent'; import debug from '../debug'; /** * A basic Base interaction component * * It is meant to be be extended by more specific interactions */ class RBaseInteraction extends RlayersBase { constructor(props) { super(props); this.ol = null; } createOL(props) { throw new Error('RBaseInteraction should not be directly instantiated'); } refresh(prevProps) { for (const p of this.classProps) if (prevProps && prevProps[p] !== this.props[p]) { debug('Replacing interaction', this, prevProps); this.componentWillUnmount(); this.ol = this.createOL(this.props); this.componentDidMount(); break; } super.refresh(prevProps); } componentDidMount() { super.componentDidMount(); this.context.map.addInteraction(this.ol); } componentWillUnmount() { super.componentWillUnmount(); this.context.map.removeInteraction(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.addInteraction)) throw new Error('An interaction must be part of a map'); if (this.ol === null) this.ol = this.createOL(this.props); return super.render(); } } RBaseInteraction.classProps = []; export default RBaseInteraction; //# sourceMappingURL=RBaseInteraction.js.map