129 lines
3.7 KiB
JavaScript
129 lines
3.7 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
exports.__esModule = true;
|
|
exports.default = void 0;
|
|
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
|
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
|
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
|
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
|
|
var _leaflet = require("leaflet");
|
|
|
|
var _context = require("./context");
|
|
|
|
var _DivOverlay2 = _interopRequireDefault(require("./DivOverlay"));
|
|
|
|
var Popup = /*#__PURE__*/function (_DivOverlay) {
|
|
(0, _inheritsLoose2.default)(Popup, _DivOverlay);
|
|
|
|
function Popup() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _DivOverlay.call.apply(_DivOverlay, [this].concat(args)) || this;
|
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPopupOpen", function (_ref) {
|
|
var popup = _ref.popup;
|
|
|
|
if (popup === _this.leafletElement) {
|
|
_this.onOpen();
|
|
}
|
|
});
|
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPopupClose", function (_ref2) {
|
|
var popup = _ref2.popup;
|
|
|
|
if (popup === _this.leafletElement) {
|
|
_this.onClose();
|
|
}
|
|
});
|
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onRender", function () {
|
|
if (_this.props.autoPan !== false && _this.leafletElement.isOpen()) {
|
|
if (_this.leafletElement._map && _this.leafletElement._map._panAnim) {
|
|
_this.leafletElement._map._panAnim = undefined;
|
|
}
|
|
|
|
_this.leafletElement._adjustPan();
|
|
}
|
|
});
|
|
return _this;
|
|
}
|
|
|
|
var _proto = Popup.prototype;
|
|
|
|
_proto.getOptions = function getOptions(props) {
|
|
return (0, _extends2.default)({}, _DivOverlay.prototype.getOptions.call(this, props), {
|
|
autoPan: false
|
|
});
|
|
};
|
|
|
|
_proto.createLeafletElement = function createLeafletElement(props) {
|
|
var options = this.getOptions(props);
|
|
options.autoPan = props.autoPan !== false;
|
|
return new _leaflet.Popup(options, props.leaflet.popupContainer);
|
|
};
|
|
|
|
_proto.updateLeafletElement = function updateLeafletElement(fromProps, toProps) {
|
|
if (toProps.position !== fromProps.position) {
|
|
this.leafletElement.setLatLng(toProps.position);
|
|
}
|
|
};
|
|
|
|
_proto.componentDidMount = function componentDidMount() {
|
|
var position = this.props.position;
|
|
var _this$props$leaflet = this.props.leaflet,
|
|
map = _this$props$leaflet.map,
|
|
popupContainer = _this$props$leaflet.popupContainer;
|
|
var el = this.leafletElement;
|
|
|
|
if (map != null) {
|
|
map.on({
|
|
popupopen: this.onPopupOpen,
|
|
popupclose: this.onPopupClose
|
|
});
|
|
}
|
|
|
|
if (popupContainer) {
|
|
// Attach to container component
|
|
popupContainer.bindPopup(el);
|
|
} else {
|
|
// Attach to a Map
|
|
if (position) {
|
|
el.setLatLng(position);
|
|
}
|
|
|
|
el.openOn(map);
|
|
}
|
|
};
|
|
|
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
var map = this.props.leaflet.map;
|
|
|
|
if (map != null) {
|
|
map.off({
|
|
popupopen: this.onPopupOpen,
|
|
popupclose: this.onPopupClose
|
|
});
|
|
map.removeLayer(this.leafletElement);
|
|
}
|
|
|
|
_DivOverlay.prototype.componentWillUnmount.call(this);
|
|
};
|
|
|
|
return Popup;
|
|
}(_DivOverlay2.default);
|
|
|
|
(0, _defineProperty2.default)(Popup, "defaultProps", {
|
|
pane: 'popupPane'
|
|
});
|
|
|
|
var _default = (0, _context.withLeaflet)(Popup);
|
|
|
|
exports.default = _default; |