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: 10, right: 10, bottom: 'auto', left: 'auto' },
|
46 | 'top-left': { top: 10, left: 10, bottom: 'auto', right: 'auto' },
|
47 | 'bottom-right': { bottom: 10, right: 10, top: 'auto', left: 'auto' },
|
48 | 'bottom-left': { bottom: 10, 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 | backgroundImage: "url('https://api.mapbox.com/mapbox.js/v2.4.0/images/icons-000000@2x.png')",
|
59 | backgroundPosition: '0px 0px',
|
60 | backgroundSize: '26px 260px',
|
61 | outline: 0
|
62 | };
|
63 | var buttonStyleHovered = {
|
64 | backgroundColor: '#fff',
|
65 | opacity: 1
|
66 | };
|
67 | var buttonStylePlus = {
|
68 | borderBottom: '1px solid rgba(0, 0, 0, 0.1)',
|
69 | borderTopLeftRadius: 2,
|
70 | borderTopRightRadius: 2
|
71 | };
|
72 | var buttonStyleMinus = {
|
73 | backgroundPosition: '0px -26px',
|
74 | borderBottomLeftRadius: 2,
|
75 | borderBottomRightRadius: 2
|
76 | };
|
77 | var _a = [0, 1], PLUS = _a[0], MINUS = _a[1];
|
78 | var POSITIONS = Object.keys(positions);
|
79 | var ZoomControl = (function (_super) {
|
80 | __extends(ZoomControl, _super);
|
81 | function ZoomControl() {
|
82 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
83 | _this.state = {
|
84 | hover: undefined
|
85 | };
|
86 | _this.onMouseOut = function () {
|
87 | _this.setState({ hover: undefined });
|
88 | };
|
89 | _this.plusOver = function () {
|
90 | if (PLUS !== _this.state.hover) {
|
91 | _this.setState({ hover: PLUS });
|
92 | }
|
93 | };
|
94 | _this.minusOver = function () {
|
95 | if (MINUS !== _this.state.hover) {
|
96 | _this.setState({ hover: MINUS });
|
97 | }
|
98 | };
|
99 | _this.onClickPlus = function () {
|
100 | _this.props.onControlClick(_this.props.map, _this.props.zoomDiff);
|
101 | };
|
102 | _this.onClickMinus = function () {
|
103 | _this.props.onControlClick(_this.props.map, -_this.props.zoomDiff);
|
104 | };
|
105 | return _this;
|
106 | }
|
107 | ZoomControl.prototype.render = function () {
|
108 | var _a = this.props, position = _a.position, style = _a.style, className = _a.className, tabIndex = _a.tabIndex;
|
109 | var hover = this.state.hover;
|
110 | var plusStyle = __assign({}, buttonStyle, buttonStylePlus, (hover === PLUS ? buttonStyleHovered : {}));
|
111 | var minusStyle = __assign({}, buttonStyle, buttonStyleMinus, (hover === MINUS ? buttonStyleHovered : {}));
|
112 | return (React.createElement("div", { className: className, tabIndex: tabIndex, style: __assign({}, containerStyle, positions[position], style) },
|
113 | React.createElement("button", { id: "zoomIn", type: "button", style: plusStyle, "aria-label": "Zoom in", onMouseOver: this.plusOver, onMouseOut: this.onMouseOut, onClick: this.onClickPlus }),
|
114 | React.createElement("button", { id: "zoomOut", type: "button", style: minusStyle, "aria-label": "Zoom out", onMouseOver: this.minusOver, onMouseOut: this.onMouseOut, onClick: this.onClickMinus })));
|
115 | };
|
116 | ZoomControl.defaultProps = {
|
117 | position: POSITIONS[0],
|
118 | zoomDiff: 0.5,
|
119 | onControlClick: function (map, zoomDiff) {
|
120 | map.zoomTo(map.getZoom() + zoomDiff);
|
121 | }
|
122 | };
|
123 | return ZoomControl;
|
124 | }(React.Component));
|
125 | exports.ZoomControl = ZoomControl;
|
126 | exports.default = context_1.withMap(ZoomControl);
|
127 |
|
\ | No newline at end of file |