UNPKG

rlayers

Version:

React Components for OpenLayers

29 lines 1.08 kB
import React from 'react'; import { Control as Control } from 'ol/control'; import { default as RControlBase } from './RControlBase'; /** A custom control that can contain an HTMLElement * * All provided children will be rendered as an OpenLayers control * * Requires an `RMap` context * * [See this for an example](https://mmomtchev.github.io/rlayers/#/controls) */ export default class RCustom extends RControlBase { constructor(props, context) { super(props, context); this.targetRef = React.createRef(); } componentDidMount() { this.ol = new Control(this.toOLProps(this.props)); super.componentDidMount(); } toOLProps(props) { var _a; return Object.assign(Object.assign({}, super.toOLProps(props)), { element: (_a = this.targetRef) === null || _a === void 0 ? void 0 : _a.current }); } render() { return (React.createElement("div", { className: ['ol-control', this.props.className].join(' '), ref: this.targetRef }, this.props.children)); } } //# sourceMappingURL=RCustom.js.map