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