UNPKG

rlayers

Version:

React Components for OpenLayers

58 lines 2.57 kB
import React from 'react'; import { createRoot } from 'react-dom/client'; 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) { super(props); this.style = (f, r) => { if (this.props.render) { const element = this.props.render(f, r); // eslint-disable-next-line @typescript-eslint/no-explicit-any React.Children.map(element.props.children, (child) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type if (React.isValidElement(child) && child.type !== RStyle) throw new TypeError('An RStyleArray should contain only RStyle elements'); }); const styleArray = []; const reactElement = (React.createElement(RContext.Provider, { value: Object.assign(Object.assign({}, this.context), { styleArray }) }, element.props.children)); createRoot(document.createElement('div')).render(reactElement); 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/no-unsafe-function-type 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