rlayers
Version:
React Components for OpenLayers
92 lines • 3.89 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 (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 __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 REvent_1 = require("../REvent");
var debug_1 = __importDefault(require("../debug"));
/**
* A basic Base interaction component
*
* It is meant to be be extended by more specific interactions
*/
var RBaseInteraction = /** @class */ (function (_super) {
__extends(RBaseInteraction, _super);
function RBaseInteraction(props) {
var _this = _super.call(this, props) || this;
_this.ol = null;
return _this;
}
RBaseInteraction.prototype.createOL = function (props) {
throw new Error('RBaseInteraction should not be directly instantiated');
};
RBaseInteraction.prototype.refresh = function (prevProps) {
var e_1, _a;
try {
for (var _b = __values(this.classProps), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (prevProps && prevProps[p] !== this.props[p]) {
(0, debug_1.default)('Replacing interaction', this, prevProps);
this.componentWillUnmount();
this.ol = this.createOL(this.props);
this.componentDidMount();
break;
}
}
}
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; }
}
_super.prototype.refresh.call(this, prevProps);
};
RBaseInteraction.prototype.componentDidMount = function () {
_super.prototype.componentDidMount.call(this);
this.context.map.addInteraction(this.ol);
};
RBaseInteraction.prototype.componentWillUnmount = function () {
_super.prototype.componentWillUnmount.call(this);
this.context.map.removeInteraction(this.ol);
};
RBaseInteraction.prototype.render = function () {
var _a, _b;
if (!((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.addInteraction))
throw new Error('An interaction must be part of a map');
if (this.ol === null)
this.ol = this.createOL(this.props);
return _super.prototype.render.call(this);
};
RBaseInteraction.classProps = [];
return RBaseInteraction;
}(REvent_1.RlayersBase));
exports.default = RBaseInteraction;
//# sourceMappingURL=RBaseInteraction.js.map
;