UNPKG

4.04 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 }
8 return function (d, b) {
9 extendStatics(d, b);
10 function __() { this.constructor = d; }
11 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12 };
13})();
14var __assign = (this && this.__assign) || function () {
15 __assign = Object.assign || function(t) {
16 for (var s, i = 1, n = arguments.length; i < n; i++) {
17 s = arguments[i];
18 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19 t[p] = s[p];
20 }
21 return t;
22 };
23 return __assign.apply(this, arguments);
24};
25import * as React from 'react';
26import { overlayState, overlayTransform } from './util/overlays';
27import { withMap } from './context';
28var defaultStyle = {
29 zIndex: 3
30};
31var ProjectedLayer = (function (_super) {
32 __extends(ProjectedLayer, _super);
33 function ProjectedLayer() {
34 var _this = _super !== null && _super.apply(this, arguments) || this;
35 _this.container = undefined;
36 _this.prevent = false;
37 _this.state = {};
38 _this.setContainer = function (el) {
39 if (el) {
40 _this.container = el;
41 }
42 };
43 _this.handleMapMove = function () {
44 if (!_this.prevent) {
45 _this.setState(overlayState(_this.props, _this.props.map, _this.container));
46 }
47 };
48 return _this;
49 }
50 ProjectedLayer.prototype.componentDidMount = function () {
51 var map = this.props.map;
52 map.on('move', this.handleMapMove);
53 this.handleMapMove();
54 };
55 ProjectedLayer.prototype.havePropsChanged = function (props, prevProps) {
56 return (props.coordinates[0] !== prevProps.coordinates[0] ||
57 props.coordinates[1] !== prevProps.coordinates[1] ||
58 props.offset !== prevProps.offset ||
59 props.anchor !== prevProps.anchor);
60 };
61 ProjectedLayer.prototype.componentDidUpdate = function (prevProps) {
62 if (this.havePropsChanged(this.props, prevProps)) {
63 this.setState(overlayState(this.props, this.props.map, this.container));
64 }
65 };
66 ProjectedLayer.prototype.componentWillUnmount = function () {
67 var map = this.props.map;
68 this.prevent = true;
69 map.off('move', this.handleMapMove);
70 };
71 ProjectedLayer.prototype.render = function () {
72 var _a = this.props, style = _a.style, children = _a.children, className = _a.className, onClick = _a.onClick, onDoubleClick = _a.onDoubleClick, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, onScroll = _a.onScroll, onWheel = _a.onWheel, type = _a.type, tabIndex = _a.tabIndex;
73 var anchor = this.state.anchor;
74 var finalStyle = __assign({}, defaultStyle, style, { transform: overlayTransform(this.state).join(' ') });
75 var anchorClassname = anchor && type === 'popup' ? "mapboxgl-popup-anchor-" + anchor : '';
76 return (React.createElement("div", { className: className + " " + anchorClassname, onClick: onClick, onDoubleClick: onDoubleClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onScroll: onScroll, onWheel: onWheel, style: finalStyle, ref: this.setContainer, tabIndex: tabIndex }, children));
77 };
78 ProjectedLayer.defaultProps = {
79 offset: 0,
80 onClick: function () {
81 var args = [];
82 for (var _i = 0; _i < arguments.length; _i++) {
83 args[_i] = arguments[_i];
84 }
85 return args;
86 }
87 };
88 return ProjectedLayer;
89}(React.Component));
90export { ProjectedLayer };
91export default withMap(ProjectedLayer);
92//# sourceMappingURL=projected-layer.js.map
\No newline at end of file