UNPKG

rlayers

Version:

React Components for OpenLayers

105 lines 4.38 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 __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; 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 context_1 = require("../context"); var REvent_1 = require("../REvent"); /** * Abstract base class for all layers, not meant to be used directly */ var RLayer = /** @class */ (function (_super) { __extends(RLayer, _super); function RLayer(props, context) { var _this = this; var _a, _b; _this = _super.call(this, props, context) || this; if (!((_b = (_a = _this.context) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.addLayer)) throw new Error('A layer must be part of a map'); return _this; } RLayer.prototype.refresh = function (prevProps) { var e_1, _a; _super.prototype.refresh.call(this, prevProps); try { for (var _b = __values([ 'visible', 'opacity', 'zIndex', 'minResolution', 'maxResolution', 'minZoom', 'maxZoom' ]), _c = _b.next(); !_c.done; _c = _b.next()) { var p = _c.value; var m = p.charAt(0).toUpperCase() + p.substring(1); if (this.props[p] !== (prevProps && prevProps[p])) this.ol['set' + m](this.props[p]); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } if (this.source && this.props.attributions) this.source.setAttributions(this.props.attributions); if (this.props.properties) this.ol.setProperties(this.props.properties); }; RLayer.prototype.componentDidMount = function () { _super.prototype.componentDidMount.call(this); this.context.map.addLayer(this.ol); }; RLayer.prototype.componentWillUnmount = function () { _super.prototype.componentWillUnmount.call(this); this.context.map.removeLayer(this.ol); }; RLayer.prototype.render = function () { return (react_1.default.createElement("div", { className: '_rlayers_RLayer' }, react_1.default.createElement(context_1.RContext.Provider, { value: __assign(__assign({}, this.context), { layer: this.ol, source: this.source, rLayer: this }) }, this.props.children))); }; return RLayer; }(REvent_1.RlayersBase)); exports.default = RLayer; //# sourceMappingURL=RLayer.js.map