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