1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | var __importStar = (this && this.__importStar) || function (mod) {
|
27 | if (mod && mod.__esModule) return mod;
|
28 | var result = {};
|
29 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
30 | result["default"] = mod;
|
31 | return result;
|
32 | };
|
33 | Object.defineProperty(exports, "__esModule", { value: true });
|
34 | var React = __importStar(require("react"));
|
35 | var context_1 = require("./context");
|
36 | var containerStyle = {
|
37 | position: 'absolute',
|
38 | zIndex: 10,
|
39 | display: 'flex',
|
40 | flexDirection: 'column',
|
41 | boxShadow: '0px 1px 4px rgba(0, 0, 0, .3)',
|
42 | border: '1px solid rgba(0, 0, 0, 0.1)'
|
43 | };
|
44 | var positions = {
|
45 | 'top-right': { top: 62, right: 10, bottom: 'auto', left: 'auto' },
|
46 | 'top-left': { top: 62, left: 10, bottom: 'auto', right: 'auto' },
|
47 | 'bottom-right': { bottom: 63, right: 10, top: 'auto', left: 'auto' },
|
48 | 'bottom-left': { bottom: 63, left: 10, top: 'auto', right: 'auto' }
|
49 | };
|
50 | var buttonStyle = {
|
51 | backgroundColor: '#f9f9f9',
|
52 | opacity: 0.95,
|
53 | transition: 'background-color 0.16s ease-out',
|
54 | cursor: 'pointer',
|
55 | border: 0,
|
56 | height: 26,
|
57 | width: 26,
|
58 | outline: 0,
|
59 | padding: 3
|
60 | };
|
61 | var buttonStyleHovered = {
|
62 | backgroundColor: '#fff',
|
63 | opacity: 1
|
64 | };
|
65 | var buttonStyleCompass = {
|
66 | borderBottom: '1px solid rgba(0, 0, 0, 0.1)',
|
67 | borderTopLeftRadius: 2,
|
68 | borderTopRightRadius: 2,
|
69 | borderBottomLeftRadius: 2,
|
70 | borderBottomRightRadius: 2
|
71 | };
|
72 | var Icon = function () { return (React.createElement("svg", { viewBox: "0 0 20 20" },
|
73 | React.createElement("polygon", { fill: "#333333", points: "6,9 10,1 14,9" }),
|
74 | React.createElement("polygon", { fill: "#CCCCCC", points: "6,11 10,19 14,11" }))); };
|
75 | var compassSpan = {
|
76 | width: 20,
|
77 | height: 20,
|
78 | display: 'inline-block'
|
79 | };
|
80 | var COMPASS = [0][0];
|
81 | var POSITIONS = Object.keys(positions);
|
82 | var RotationControl = (function (_super) {
|
83 | __extends(RotationControl, _super);
|
84 | function RotationControl() {
|
85 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
86 | _this.state = {
|
87 | hover: undefined
|
88 | };
|
89 | _this.compassIcon = null;
|
90 | _this.onMouseOut = function () {
|
91 | if (!_this.state.hover) {
|
92 | _this.setState({ hover: undefined });
|
93 | }
|
94 | };
|
95 | _this.onMouseIn = function () {
|
96 | if (COMPASS !== _this.state.hover) {
|
97 | _this.setState({ hover: COMPASS });
|
98 | }
|
99 | };
|
100 | _this.onClickCompass = function () {
|
101 | _this.props.map.resetNorth();
|
102 | };
|
103 | _this.onMapRotate = function () {
|
104 | var map = _this.props.map;
|
105 | var rotate = "rotate(" + map.transform.angle *
|
106 | (180 / Math.PI) + "deg)";
|
107 | if (_this.compassIcon) {
|
108 | _this.compassIcon.style.transform = rotate;
|
109 | }
|
110 | };
|
111 | _this.assignRef = function (icon) {
|
112 | _this.compassIcon = icon;
|
113 | };
|
114 | return _this;
|
115 | }
|
116 | RotationControl.prototype.componentDidMount = function () {
|
117 | this.props.map.on('rotate', this.onMapRotate);
|
118 | };
|
119 | RotationControl.prototype.componentWillUnmount = function () {
|
120 | this.props.map.off('rotate', this.onMapRotate);
|
121 | };
|
122 | RotationControl.prototype.render = function () {
|
123 | var _a = this.props, position = _a.position, style = _a.style, className = _a.className, tabIndex = _a.tabIndex;
|
124 | var hover = this.state.hover;
|
125 | var controlStyle = __assign({}, buttonStyle, buttonStyleCompass, (hover === COMPASS ? buttonStyleHovered : {}));
|
126 | return (React.createElement("div", { className: className, tabIndex: tabIndex, style: __assign({}, containerStyle, positions[position], style) },
|
127 | React.createElement("button", { style: controlStyle, onMouseOver: this.onMouseIn, onMouseOut: this.onMouseOut, onClick: this.onClickCompass },
|
128 | React.createElement("span", { ref: this.assignRef, style: compassSpan },
|
129 | React.createElement(Icon, null)))));
|
130 | };
|
131 | RotationControl.defaultProps = {
|
132 | position: POSITIONS[0]
|
133 | };
|
134 | return RotationControl;
|
135 | }(React.Component));
|
136 | exports.RotationControl = RotationControl;
|
137 | exports.default = context_1.withMap(RotationControl);
|
138 |
|
\ | No newline at end of file |