rlayers
Version:
React Components for OpenLayers
120 lines • 4.71 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 __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ROverlay_1 = require("./ROverlay");
/**
* Popup component
*
* `Popup` extends `Overlay` and implements an automatic popup
*
* Requires a location context
*
* (ie it must be descendant of a `RFeature`)
*/
var RPopup = /** @class */ (function (_super) {
__extends(RPopup, _super);
function RPopup(props, context) {
var _this = _super.call(this, props, context) || this;
/**
* Toggle the state
*/
_this.toggle = function () {
_this.visible = !_this.visible;
_this.setPosition();
};
/**
* Show the popup
*/
_this.show = function () {
var _a, _b;
if (_this.showing)
return;
if (_this.hiding)
window.clearTimeout(_this.hiding);
_this.showing = window.setTimeout(function () {
_this.visible = true;
_this.setPosition();
_this.hiding = _this.showing = undefined;
}, (_b = (_a = _this.props.delay) === null || _a === void 0 ? void 0 : _a.show) !== null && _b !== void 0 ? _b : 250);
};
/**
* Hide the popup
*/
_this.hide = function () {
var _a, _b;
if (_this.hiding)
return;
if (_this.showing)
window.clearTimeout(_this.showing);
_this.hiding = window.setTimeout(function () {
_this.visible = false;
_this.setPosition();
_this.hiding = _this.showing = undefined;
}, (_b = (_a = _this.props.delay) === null || _a === void 0 ? void 0 : _a.hide) !== null && _b !== void 0 ? _b : 50);
};
_this.visible = false;
return _this;
}
RPopup.prototype.componentWillUnmount = function () {
_super.prototype.componentWillUnmount.call(this);
this.unregister();
};
RPopup.prototype.setPosition = function () {
this.ol.setPosition(this.visible ? this.context.location : undefined);
};
RPopup.prototype.unregister = function (prevProps) {
if (!prevProps)
return;
switch (prevProps.trigger) {
default:
case 'click':
this.context.rFeature.un('click', this.toggle);
break;
case 'hover':
this.context.rFeature.un('pointerenter', this.show);
this.context.rFeature.un('pointerhide', this.hide);
break;
}
};
RPopup.prototype.refresh = function (prevProps) {
this.ol.setElement(this.containerRef.current);
if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.trigger) !== this.props.trigger) {
this.unregister(prevProps);
switch (this.props.trigger) {
default:
case 'click':
if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.trigger) === 'hover') {
this.context.rFeature.un('pointerenter', this.show);
this.context.rFeature.un('pointerhide', this.hide);
}
this.context.rFeature.on('click', this.toggle);
break;
case 'hover':
if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.trigger) === 'click') {
this.context.rFeature.un('click', this.toggle);
}
this.context.rFeature.on('pointerenter', this.show);
this.context.rFeature.on('pointerleave', this.hide);
break;
}
}
this.setPosition();
};
return RPopup;
}(ROverlay_1.ROverlayBase));
exports.default = RPopup;
//# sourceMappingURL=RPopup.js.map
;