UNPKG

rlayers

Version:

React Components for OpenLayers

57 lines 2.45 kB
import React from 'react'; import ReactDOM from 'react-dom'; import { RContext } from '../context'; import { default as RStyle } from './RStyle'; /** An array of RStyle, can be an RStyle of its own * - this represents the OpenLayers concept of a style array * * It replaces the references on its children, so individual elements * in the array cannot be referenced * * It doesn't support caching yet * * Every style in the array must be a static style and not a function * * Arrays of style functions are not supported by OpenLayers and won't * be supported rlayers either */ export default class RStyleArray extends RStyle { constructor(props, context) { super(props, context); this.style = (f, r) => { if (this.props.render) { const element = this.props.render(f, r); React.Children.map(element.props.children, (child) => { // eslint-disable-next-line @typescript-eslint/ban-types if (React.isValidElement(child) && child.type !== RStyle) throw new TypeError('An RStyleArray should contain only RStyle elements'); }); const styleArray = []; const render = (React.createElement(RContext.Provider, { value: Object.assign(Object.assign({}, this.context), { styleArray }) }, element.props.children)); ReactDOM.render(render, document.createElement('div')); return styleArray; } return this.ol; }; this.childRefs = []; if (props.render) this.ol = this.style; else this.ol = []; } refresh(prevProps) { super.refresh(prevProps); } render() { React.Children.map(this.props.children, (child) => { // eslint-disable-next-line @typescript-eslint/ban-types if (React.isValidElement(child) && child.type !== RStyle) throw new TypeError('An RStyleArray should contain only RStyle elements'); }); if (!this.props.render) return (React.createElement("div", { className: '_rlayers_RStyleArray' }, React.createElement(RContext.Provider, { value: Object.assign(Object.assign({}, this.context), { styleArray: this.ol }) }, this.props.children))); return React.createElement(React.Fragment, null); } } //# sourceMappingURL=RStyleArray.js.map