UNPKG

rc-leaflet

Version:
65 lines (64 loc) 2.84 kB
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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { 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); }; import PropTypes from 'prop-types'; import L from 'leaflet'; import { Bounds } from '../../util/PropTypes'; import InteractiveLayer from '../InteractiveLayer'; // this hack is used to open an unsticky tooltip when mouseover ImageOverlay L.ImageOverlay.include({ getCenter: function () { return this.getBounds().getCenter(); } }); var ImageOverlayClass = /** @class */ (function (_super) { __extends(ImageOverlayClass, _super); function ImageOverlayClass(props, context) { var _this = _super.call(this, props, context) || this; _this.onLoad = function (e) { return _this.props.onLoad && _this.props.onLoad(e); }; _this.onError = function (e) { return _this.props.onError && _this.props.onError(e); }; var overlay = _this.instance; overlay.on({ load: _this.onLoad, error: _this.onError }); overlay.setZIndex(props.zIndex); return _this; } ImageOverlayClass.prototype.componentDidUpdate = function (prevProps) { var prevBounds = prevProps.bounds, prevOpacity = prevProps.opacity, prevZIndex = prevProps.zIndex; var _a = this.props, bounds = _a.bounds, opacity = _a.opacity, zIndex = _a.zIndex; var overlay = this.instance; if (bounds !== prevBounds) { overlay.setBounds(bounds instanceof L.LatLngBounds ? bounds : new L.LatLngBounds(bounds)); } if (opacity !== prevOpacity) { overlay.setOpacity(opacity); } if (zIndex !== prevZIndex) { overlay.setZIndex(zIndex); } _super.prototype.componentDidUpdate.call(this, prevProps); }; ImageOverlayClass.propTypes = __assign({}, InteractiveLayer.propTypes, { bounds: Bounds.isRequired, onLoad: PropTypes.func, onError: PropTypes.func }); return ImageOverlayClass; }(InteractiveLayer)); export default ImageOverlayClass;