120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
"use strict";
|
|
|
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
import { Popup as LeafletPopup } from 'leaflet';
|
|
import { withLeaflet } from './context';
|
|
import DivOverlay from './DivOverlay';
|
|
|
|
var Popup = /*#__PURE__*/function (_DivOverlay) {
|
|
_inheritsLoose(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;
|
|
|
|
_defineProperty(_assertThisInitialized(_this), "onPopupOpen", function (_ref) {
|
|
var popup = _ref.popup;
|
|
|
|
if (popup === _this.leafletElement) {
|
|
_this.onOpen();
|
|
}
|
|
});
|
|
|
|
_defineProperty(_assertThisInitialized(_this), "onPopupClose", function (_ref2) {
|
|
var popup = _ref2.popup;
|
|
|
|
if (popup === _this.leafletElement) {
|
|
_this.onClose();
|
|
}
|
|
});
|
|
|
|
_defineProperty(_assertThisInitialized(_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 _extends({}, _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 LeafletPopup(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;
|
|
}(DivOverlay);
|
|
|
|
_defineProperty(Popup, "defaultProps", {
|
|
pane: 'popupPane'
|
|
});
|
|
|
|
export default withLeaflet(Popup); |