UNPKG

rc-leaflet

Version:
98 lines (97 loc) 4.03 kB
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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { 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 m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import PropTypes from 'prop-types'; import L from 'leaflet'; import InteractiveLayer from '../InteractiveLayer'; var Path = /** @class */ (function (_super) { __extends(Path, _super); function Path() { return _super !== null && _super.apply(this, arguments) || this; } Path.prototype.componentDidUpdate = function (prevProps) { this.setStyle(); _super.prototype.componentDidUpdate.call(this, prevProps); }; Path.prototype.setStyle = function () { var e_1, _a; var theme = this.getTheme(); var path = this.instance; var shouldUpdate = false; try { for (var _b = __values(Object.entries(__assign({}, theme, this.props))), _c = _b.next(); !_c.done; _c = _b.next()) { var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; if (Path.propTypes[key] && value !== path.options[key]) { shouldUpdate = true; path.options[key] = value; } } } 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 (shouldUpdate) { path.setStyle(path.options); } }; Path.prototype.getTheme = function () { if (this.context && this.context.theme && this.context.theme.path) { return this.context.theme.path; } return {}; }; Path.propTypes = __assign({}, InteractiveLayer.propTypes, { stroke: PropTypes.bool, color: PropTypes.string, weight: PropTypes.number, opacity: PropTypes.number, lineCap: PropTypes.oneOf(['butt', 'round', 'square', 'inherit']), lineJoin: PropTypes.oneOf(['miter', 'round', 'bevel', 'inherit']), dashArray: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.number)]), dashOffset: PropTypes.string, fill: PropTypes.bool, fillColor: PropTypes.string, fillOpacity: PropTypes.number, fillRule: PropTypes.oneOf(['nonzero', 'evenodd', 'inherit']), renderer: PropTypes.instanceOf(L.Renderer), className: PropTypes.string }); return Path; }(InteractiveLayer)); export default Path;