UNPKG

rlayers

Version:

React Components for OpenLayers

92 lines 4.29 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = __importDefault(require("react")); var react_dom_1 = __importDefault(require("react-dom")); var context_1 = require("../context"); var RStyle_1 = __importDefault(require("./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 */ var RStyleArray = /** @class */ (function (_super) { __extends(RStyleArray, _super); function RStyleArray(props, context) { var _this = _super.call(this, props, context) || this; _this.style = function (f, r) { if (_this.props.render) { var element = _this.props.render(f, r); react_1.default.Children.map(element.props.children, function (child) { // eslint-disable-next-line @typescript-eslint/ban-types if (react_1.default.isValidElement(child) && child.type !== RStyle_1.default) throw new TypeError('An RStyleArray should contain only RStyle elements'); }); var styleArray = []; var render = (react_1.default.createElement(context_1.RContext.Provider, { value: __assign(__assign({}, _this.context), { styleArray: styleArray }) }, element.props.children)); react_dom_1.default.render(render, document.createElement('div')); return styleArray; } return _this.ol; }; _this.childRefs = []; if (props.render) _this.ol = _this.style; else _this.ol = []; return _this; } RStyleArray.prototype.refresh = function (prevProps) { _super.prototype.refresh.call(this, prevProps); }; RStyleArray.prototype.render = function () { react_1.default.Children.map(this.props.children, function (child) { // eslint-disable-next-line @typescript-eslint/ban-types if (react_1.default.isValidElement(child) && child.type !== RStyle_1.default) throw new TypeError('An RStyleArray should contain only RStyle elements'); }); if (!this.props.render) return (react_1.default.createElement("div", { className: '_rlayers_RStyleArray' }, react_1.default.createElement(context_1.RContext.Provider, { value: __assign(__assign({}, this.context), { styleArray: this.ol }) }, this.props.children))); return react_1.default.createElement(react_1.default.Fragment, null); }; return RStyleArray; }(RStyle_1.default)); exports.default = RStyleArray; //# sourceMappingURL=RStyleArray.js.map