rc-leaflet
Version:
React Map Components of Leaflet
103 lines (102 loc) • 4.55 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var prop_types_1 = __importDefault(require("prop-types"));
var leaflet_1 = __importDefault(require("leaflet"));
var InteractiveLayer_1 = __importDefault(require("../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_1.default.propTypes, { stroke: prop_types_1.default.bool, color: prop_types_1.default.string, weight: prop_types_1.default.number, opacity: prop_types_1.default.number, lineCap: prop_types_1.default.oneOf(['butt', 'round', 'square', 'inherit']), lineJoin: prop_types_1.default.oneOf(['miter', 'round', 'bevel', 'inherit']), dashArray: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.arrayOf(prop_types_1.default.number)]), dashOffset: prop_types_1.default.string, fill: prop_types_1.default.bool, fillColor: prop_types_1.default.string, fillOpacity: prop_types_1.default.number, fillRule: prop_types_1.default.oneOf(['nonzero', 'evenodd', 'inherit']), renderer: prop_types_1.default.instanceOf(leaflet_1.default.Renderer), className: prop_types_1.default.string });
return Path;
}(InteractiveLayer_1.default));
exports.default = Path;