rlayers
Version:
React Components for OpenLayers
109 lines • 4.73 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 __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");
var debug_1 = __importDefault(require("../debug"));
/**
* Abstract base class for all layers, not meant to be used directly
*/
var RLayer = /** @class */ (function (_super) {
__extends(RLayer, _super);
function RLayer(props) {
return _super.call(this, props) || this;
}
RLayer.prototype.refresh = function (prevProps) {
var e_1, _a;
var _b;
_super.prototype.refresh.call(this, prevProps);
try {
for (var _c = __values([
'visible',
'opacity',
'zIndex',
'minResolution',
'maxResolution',
'minZoom',
'maxZoom'
]), _d = _c.next(); !_d.done; _d = _c.next()) {
var p = _d.value;
var m = p.charAt(0).toUpperCase() + p.substring(1);
if (((_b = this.props) === null || _b === void 0 ? void 0 : _b[p]) !== (prevProps === null || prevProps === void 0 ? void 0 : prevProps[p])) {
(0, debug_1.default)('Setting', this, m, this.props[p]);
this.ol['set' + m](this.props[p]);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
if (this.source && this.props.attributions !== (prevProps === null || prevProps === void 0 ? void 0 : prevProps.attributions)) {
(0, debug_1.default)('Setting attributions', this);
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 () {
var _a, _b;
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 (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
;