@deck.gl-community/widgets 9.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/dist/_deprecate/long-press-button.d.ts +13 -0
- package/dist/_deprecate/long-press-button.d.ts.map +1 -0
- package/dist/_deprecate/long-press-button.js +32 -0
- package/dist/_deprecate/long-press-button.js.map +1 -0
- package/dist/_deprecate/view-control-widget.d.ts +78 -0
- package/dist/_deprecate/view-control-widget.d.ts.map +1 -0
- package/dist/_deprecate/view-control-widget.js +198 -0
- package/dist/_deprecate/view-control-widget.js.map +1 -0
- package/dist/index.cjs +708 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/widgets/html-cluster-widget.d.ts +25 -0
- package/dist/widgets/html-cluster-widget.d.ts.map +1 -0
- package/dist/widgets/html-cluster-widget.js +39 -0
- package/dist/widgets/html-cluster-widget.js.map +1 -0
- package/dist/widgets/html-overlay-item.d.ts +13 -0
- package/dist/widgets/html-overlay-item.d.ts.map +1 -0
- package/dist/widgets/html-overlay-item.js +10 -0
- package/dist/widgets/html-overlay-item.js.map +1 -0
- package/dist/widgets/html-overlay-widget.d.ts +45 -0
- package/dist/widgets/html-overlay-widget.d.ts.map +1 -0
- package/dist/widgets/html-overlay-widget.js +112 -0
- package/dist/widgets/html-overlay-widget.js.map +1 -0
- package/dist/widgets/html-tooltip-widget.d.ts +30 -0
- package/dist/widgets/html-tooltip-widget.d.ts.map +1 -0
- package/dist/widgets/html-tooltip-widget.js +67 -0
- package/dist/widgets/html-tooltip-widget.js.map +1 -0
- package/dist/widgets/long-press-button.d.ts +22 -0
- package/dist/widgets/long-press-button.d.ts.map +1 -0
- package/dist/widgets/long-press-button.js +84 -0
- package/dist/widgets/long-press-button.js.map +1 -0
- package/dist/widgets/long-press-controller.d.ts +27 -0
- package/dist/widgets/long-press-controller.d.ts.map +1 -0
- package/dist/widgets/long-press-controller.js +144 -0
- package/dist/widgets/long-press-controller.js.map +1 -0
- package/dist/widgets/pan-widget.d.ts +33 -0
- package/dist/widgets/pan-widget.d.ts.map +1 -0
- package/dist/widgets/pan-widget.js +141 -0
- package/dist/widgets/pan-widget.js.map +1 -0
- package/dist/widgets/view-manager-utils.d.ts +11 -0
- package/dist/widgets/view-manager-utils.d.ts.map +1 -0
- package/dist/widgets/view-manager-utils.js +13 -0
- package/dist/widgets/view-manager-utils.js.map +1 -0
- package/dist/widgets/zoom-range-widget.d.ts +43 -0
- package/dist/widgets/zoom-range-widget.d.ts.map +1 -0
- package/dist/widgets/zoom-range-widget.js +190 -0
- package/dist/widgets/zoom-range-widget.js.map +1 -0
- package/package.json +41 -0
- package/src/_deprecate/long-press-button.tsx +50 -0
- package/src/_deprecate/view-control-widget.tsx +339 -0
- package/src/index.ts +18 -0
- package/src/widgets/html-cluster-widget.ts +84 -0
- package/src/widgets/html-overlay-item.tsx +32 -0
- package/src/widgets/html-overlay-widget.tsx +147 -0
- package/src/widgets/html-tooltip-widget.tsx +93 -0
- package/src/widgets/long-press-button.tsx +125 -0
- package/src/widgets/long-press-controller.ts +159 -0
- package/src/widgets/pan-widget.tsx +182 -0
- package/src/widgets/view-manager-utils.ts +24 -0
- package/src/widgets/zoom-range-widget.tsx +284 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
// deck.gl-community
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
// Copyright (c) vis.gl contributors
|
|
5
|
+
import { render } from 'preact';
|
|
6
|
+
import { LongPressButton } from "./long-press-button.js";
|
|
7
|
+
import { cloneViewState, hasViewManager } from "./view-manager-utils.js";
|
|
8
|
+
import { Widget } from '@deck.gl/core';
|
|
9
|
+
const WRAPPER_STYLE = {
|
|
10
|
+
position: 'absolute',
|
|
11
|
+
display: 'flex',
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
background: '#f7f7f7',
|
|
15
|
+
border: '0.5px solid #eaeaea',
|
|
16
|
+
marginTop: '6px',
|
|
17
|
+
padding: '2px 0',
|
|
18
|
+
width: '18px',
|
|
19
|
+
userSelect: 'none',
|
|
20
|
+
pointerEvents: 'auto'
|
|
21
|
+
};
|
|
22
|
+
const ZOOM_BUTTON_STYLE = {
|
|
23
|
+
cursor: 'pointer',
|
|
24
|
+
fontSize: '14px',
|
|
25
|
+
fontWeight: '500',
|
|
26
|
+
margin: '-4px'
|
|
27
|
+
};
|
|
28
|
+
const SLIDER_CONTAINER_STYLE = {
|
|
29
|
+
display: 'inline-block',
|
|
30
|
+
height: '100px',
|
|
31
|
+
padding: '0',
|
|
32
|
+
width: '10px'
|
|
33
|
+
};
|
|
34
|
+
const VERTICAL_SLIDER_STYLE = {
|
|
35
|
+
writingMode: 'vertical-lr',
|
|
36
|
+
height: '100px',
|
|
37
|
+
padding: '0',
|
|
38
|
+
margin: '0',
|
|
39
|
+
width: '10px'
|
|
40
|
+
};
|
|
41
|
+
export class ZoomRangeWidget extends Widget {
|
|
42
|
+
static defaultProps = {
|
|
43
|
+
id: 'zoom-range',
|
|
44
|
+
viewId: null,
|
|
45
|
+
placement: 'top-left',
|
|
46
|
+
minZoom: undefined,
|
|
47
|
+
maxZoom: undefined,
|
|
48
|
+
step: 0.1,
|
|
49
|
+
style: {},
|
|
50
|
+
className: ''
|
|
51
|
+
};
|
|
52
|
+
placement = 'top-left';
|
|
53
|
+
className = 'deck-widget-zoom-range';
|
|
54
|
+
deck = null;
|
|
55
|
+
step;
|
|
56
|
+
currentZoom = 0;
|
|
57
|
+
inferredMinZoom = null;
|
|
58
|
+
inferredMaxZoom = null;
|
|
59
|
+
constructor(props = {}) {
|
|
60
|
+
super({ ...ZoomRangeWidget.defaultProps, ...props });
|
|
61
|
+
this.viewId = props.viewId ?? null;
|
|
62
|
+
this.placement = props.placement ?? 'top-left';
|
|
63
|
+
this.step = props.step ?? ZoomRangeWidget.defaultProps.step;
|
|
64
|
+
}
|
|
65
|
+
setProps(props) {
|
|
66
|
+
if (props.viewId !== undefined) {
|
|
67
|
+
this.viewId = props.viewId;
|
|
68
|
+
}
|
|
69
|
+
if (props.placement !== undefined) {
|
|
70
|
+
this.placement = props.placement;
|
|
71
|
+
}
|
|
72
|
+
if (props.step !== undefined) {
|
|
73
|
+
this.step = props.step;
|
|
74
|
+
}
|
|
75
|
+
super.setProps(props);
|
|
76
|
+
}
|
|
77
|
+
onAdd({ deck, viewId }) {
|
|
78
|
+
this.deck = deck;
|
|
79
|
+
if (this.viewId === undefined) {
|
|
80
|
+
this.viewId = viewId;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
onRemove() {
|
|
84
|
+
this.deck = null;
|
|
85
|
+
}
|
|
86
|
+
onRenderHTML(rootElement) {
|
|
87
|
+
const style = { ...WRAPPER_STYLE, ...this.props.style };
|
|
88
|
+
Object.assign(rootElement.style, style);
|
|
89
|
+
const { minZoom, maxZoom } = this.getZoomBounds();
|
|
90
|
+
const clampedZoom = Math.max(minZoom, Math.min(maxZoom, this.currentZoom));
|
|
91
|
+
const stopEventPropagation = (event) => {
|
|
92
|
+
event.stopPropagation();
|
|
93
|
+
if (typeof event.stopImmediatePropagation === 'function') {
|
|
94
|
+
event.stopImmediatePropagation();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const ui = (_jsxs(_Fragment, { children: [_jsx("div", { style: ZOOM_BUTTON_STYLE, children: _jsx(LongPressButton, { onClick: () => this.handleZoomDelta(this.step), children: '+' }) }), _jsx("div", { style: SLIDER_CONTAINER_STYLE, onPointerDown: stopEventPropagation, onPointerMove: stopEventPropagation, onPointerUp: stopEventPropagation, onMouseDown: stopEventPropagation, onMouseMove: stopEventPropagation, onMouseUp: stopEventPropagation, onClick: stopEventPropagation, onWheel: stopEventPropagation, onTouchStart: stopEventPropagation, onTouchMove: stopEventPropagation, onTouchEnd: stopEventPropagation, children: _jsx("input", { type: "range", value: clampedZoom, min: minZoom, max: maxZoom, step: this.step, onInput: (event) => this.handleZoomTo(Number(event.target.value)), onChange: (event) => this.handleZoomTo(Number(event.target.value)), onPointerDown: stopEventPropagation, onPointerMove: stopEventPropagation, onPointerUp: stopEventPropagation, onMouseDown: stopEventPropagation, onMouseMove: stopEventPropagation, onMouseUp: stopEventPropagation, onClick: stopEventPropagation, onWheel: stopEventPropagation, onTouchStart: stopEventPropagation, onTouchMove: stopEventPropagation, onTouchEnd: stopEventPropagation,
|
|
98
|
+
/* @ts-expect-error - non-standard attribute for vertical sliders */
|
|
99
|
+
orient: "vertical", style: VERTICAL_SLIDER_STYLE }) }), _jsx("div", { style: ZOOM_BUTTON_STYLE, children: _jsx(LongPressButton, { onClick: () => this.handleZoomDelta(-this.step), children: '-' }) })] }));
|
|
100
|
+
render(ui, rootElement);
|
|
101
|
+
}
|
|
102
|
+
onViewportChange(viewport) {
|
|
103
|
+
const viewState = this.getViewState(viewport);
|
|
104
|
+
const zoom = Number(viewState?.zoom);
|
|
105
|
+
if (Number.isFinite(zoom)) {
|
|
106
|
+
this.currentZoom = zoom;
|
|
107
|
+
}
|
|
108
|
+
if (this.props.minZoom === undefined) {
|
|
109
|
+
const minZoom = Number(viewState?.minZoom);
|
|
110
|
+
if (Number.isFinite(minZoom)) {
|
|
111
|
+
this.inferredMinZoom = minZoom;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (this.props.maxZoom === undefined) {
|
|
115
|
+
const maxZoom = Number(viewState?.maxZoom);
|
|
116
|
+
if (Number.isFinite(maxZoom)) {
|
|
117
|
+
this.inferredMaxZoom = maxZoom;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.updateHTML();
|
|
121
|
+
}
|
|
122
|
+
getZoomBounds() {
|
|
123
|
+
const minZoom = this.props.minZoom ?? this.inferredMinZoom ?? Number.NEGATIVE_INFINITY;
|
|
124
|
+
const maxZoom = this.props.maxZoom ?? this.inferredMaxZoom ?? Number.POSITIVE_INFINITY;
|
|
125
|
+
if (minZoom > maxZoom) {
|
|
126
|
+
return { minZoom: maxZoom, maxZoom: minZoom };
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
minZoom: Number.isFinite(minZoom) ? minZoom : -20,
|
|
130
|
+
maxZoom: Number.isFinite(maxZoom) ? maxZoom : 20
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
getTargetViewports() {
|
|
134
|
+
const deck = this.deck;
|
|
135
|
+
if (!deck) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
if (this.viewId) {
|
|
139
|
+
if (hasViewManager(deck)) {
|
|
140
|
+
const viewport = deck.viewManager?.getViewport(this.viewId);
|
|
141
|
+
return viewport ? [viewport] : [];
|
|
142
|
+
}
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
return deck.getViewports();
|
|
146
|
+
}
|
|
147
|
+
getViewState(viewport) {
|
|
148
|
+
const deck = this.deck;
|
|
149
|
+
const viewManager = hasViewManager(deck) ? deck.viewManager : null;
|
|
150
|
+
const viewId = this.viewId || viewport.id;
|
|
151
|
+
if (viewManager) {
|
|
152
|
+
try {
|
|
153
|
+
return { ...viewManager.getViewState(viewId) };
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
return cloneViewState(viewManager.viewState);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return cloneViewState(viewport);
|
|
160
|
+
}
|
|
161
|
+
handleZoomDelta(delta) {
|
|
162
|
+
const { minZoom, maxZoom } = this.getZoomBounds();
|
|
163
|
+
for (const viewport of this.getTargetViewports()) {
|
|
164
|
+
const viewState = this.getViewState(viewport);
|
|
165
|
+
const baseZoom = Number(viewState.zoom);
|
|
166
|
+
const current = Number.isFinite(baseZoom) ? baseZoom : this.currentZoom;
|
|
167
|
+
const nextZoom = Math.max(minZoom, Math.min(maxZoom, current + delta));
|
|
168
|
+
this.updateViewState(viewport, { ...viewState, zoom: nextZoom });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
handleZoomTo(zoom) {
|
|
172
|
+
const { minZoom, maxZoom } = this.getZoomBounds();
|
|
173
|
+
const nextZoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
|
174
|
+
for (const viewport of this.getTargetViewports()) {
|
|
175
|
+
const viewState = this.getViewState(viewport);
|
|
176
|
+
this.updateViewState(viewport, { ...viewState, zoom: nextZoom });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
updateViewState(viewport, viewState) {
|
|
180
|
+
if (!this.deck) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const viewId = this.viewId || viewport.id || 'default-view';
|
|
184
|
+
this.currentZoom = Number(viewState.zoom) || this.currentZoom;
|
|
185
|
+
this.updateHTML();
|
|
186
|
+
// @ts-ignore Using private method until a public alternative is available
|
|
187
|
+
this.deck._onViewStateChange({ viewId, viewState, interactionState: {} });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=zoom-range-widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zoom-range-widget.js","sourceRoot":"","sources":["../../src/widgets/zoom-range-widget.tsx"],"names":[],"mappings":";AAAA,oBAAoB;AACpB,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,gCAA6B;AACpE,OAAO,EACL,MAAM,EAKP,MAAM,eAAe,CAAC;AAUvB,MAAM,aAAa,GAAiC;IAClD,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,MAAM;IACf,aAAa,EAAE,QAAQ;IACvB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,SAAS;IACrB,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gets for deck.gl",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"widgets",
|
|
11
|
+
"visualization",
|
|
12
|
+
"deck.gl"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test-watch": "vitest"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@deck.gl/core": "~9.2.1",
|
|
36
|
+
"@turf/helpers": "^6.5.0",
|
|
37
|
+
"preact": "^10.17.0",
|
|
38
|
+
"supercluster": "^8.0.1"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "7c3c27d9df35a4d089d183696a06c643ea77fcd1"
|
|
41
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Component} from 'preact';
|
|
6
|
+
|
|
7
|
+
export type LongPressButtonProps = {
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
children: any;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class LongPressButton extends Component<LongPressButtonProps> {
|
|
13
|
+
buttonPressTimer: ReturnType<typeof setTimeout> | null = null;
|
|
14
|
+
|
|
15
|
+
_repeat = () => {
|
|
16
|
+
if (this.buttonPressTimer) {
|
|
17
|
+
this.props.onClick();
|
|
18
|
+
this.buttonPressTimer = setTimeout(this._repeat, 100);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
_handleButtonPress = () => {
|
|
23
|
+
this.buttonPressTimer = setTimeout(this._repeat, 100);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
_handleButtonRelease = () => {
|
|
27
|
+
if (this.buttonPressTimer) {
|
|
28
|
+
clearTimeout(this.buttonPressTimer);
|
|
29
|
+
}
|
|
30
|
+
this.buttonPressTimer = null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
render() {
|
|
34
|
+
return (
|
|
35
|
+
<div className="deck-widget-button">
|
|
36
|
+
<div
|
|
37
|
+
style={{
|
|
38
|
+
pointerEvents: 'auto'
|
|
39
|
+
}}
|
|
40
|
+
onMouseDown={(event) => {
|
|
41
|
+
this._handleButtonPress();
|
|
42
|
+
document.addEventListener('mouseup', this._handleButtonRelease, {once: true});
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
{this.props.children}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Component, render} from 'preact';
|
|
6
|
+
|
|
7
|
+
// import {FlyToInterpolator} from '@deck.gl/core';
|
|
8
|
+
import {Widget, type Deck, type Viewport, type WidgetPlacement} from '@deck.gl/core';
|
|
9
|
+
import {LongPressButton} from './long-press-button';
|
|
10
|
+
|
|
11
|
+
export const ViewControlWrapper = ({children}) => (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
display: 'flex',
|
|
16
|
+
flexDirection: 'column',
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
zIndex: 99,
|
|
19
|
+
userSelect: 'none'
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
{' '}
|
|
23
|
+
{children}{' '}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const NavigationButtonContainer = ({children}) => (
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
background: '#f7f7f7',
|
|
31
|
+
borderRadius: '23px',
|
|
32
|
+
border: '0.5px solid #eaeaea',
|
|
33
|
+
boxShadow: 'inset 11px 11px 5px -7px rgba(230, 230, 230, 0.49)',
|
|
34
|
+
height: '46px',
|
|
35
|
+
width: '46px'
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
{' '}
|
|
39
|
+
{children}{' '}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export type NavigationButtonProps = {
|
|
44
|
+
left: any;
|
|
45
|
+
top: any;
|
|
46
|
+
rotate?: number;
|
|
47
|
+
children?: any;
|
|
48
|
+
onClick?: () => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const NavigationButton = (props: NavigationButtonProps) => (
|
|
52
|
+
<div
|
|
53
|
+
onClick={props.onClick}
|
|
54
|
+
style={{
|
|
55
|
+
color: '#848484',
|
|
56
|
+
cursor: 'pointer',
|
|
57
|
+
position: 'absolute',
|
|
58
|
+
left: props.left,
|
|
59
|
+
top: props.top,
|
|
60
|
+
transform: `rotate(${props.rotate || 0}deg)`
|
|
61
|
+
// &:hover,
|
|
62
|
+
// &:active {
|
|
63
|
+
// color: #00ade6;
|
|
64
|
+
// }
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{' '}
|
|
68
|
+
{props.children}{' '}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export const ZoomControlWrapper = ({children}) => (
|
|
73
|
+
<div
|
|
74
|
+
style={{
|
|
75
|
+
alignItems: 'center',
|
|
76
|
+
background: '#f7f7f7',
|
|
77
|
+
border: '0.5px solid #eaeaea',
|
|
78
|
+
display: 'flex',
|
|
79
|
+
flexDirection: 'column',
|
|
80
|
+
marginTop: '6px',
|
|
81
|
+
padding: '2px 0',
|
|
82
|
+
width: '18px'
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{' '}
|
|
86
|
+
{children}{' '}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export const VerticalSlider = ({children}) => (
|
|
91
|
+
<div
|
|
92
|
+
style={{
|
|
93
|
+
display: 'inline-block',
|
|
94
|
+
height: '100px',
|
|
95
|
+
padding: '0',
|
|
96
|
+
width: '10px'
|
|
97
|
+
|
|
98
|
+
// > input[type='range'][orient='vertical'] {
|
|
99
|
+
// -webkit-appearance: slider-vertical;
|
|
100
|
+
// height: 100px;
|
|
101
|
+
// padding: 0;
|
|
102
|
+
// margin: 0;
|
|
103
|
+
// width: 10px;
|
|
104
|
+
// }
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
{' '}
|
|
108
|
+
{children}{' '}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
export const ZoomControlButton = ({children}) => (
|
|
113
|
+
<div
|
|
114
|
+
style={{
|
|
115
|
+
cursor: 'pointer',
|
|
116
|
+
fontSize: '14px',
|
|
117
|
+
fontWeight: 500,
|
|
118
|
+
margin: '-4px'
|
|
119
|
+
|
|
120
|
+
// &:hover,
|
|
121
|
+
// &:active {
|
|
122
|
+
// color: #00ade6;
|
|
123
|
+
// }
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
{' '}
|
|
127
|
+
{children}{' '}
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
export type ViewControlProps = {
|
|
132
|
+
id?: string;
|
|
133
|
+
viewId?: string;
|
|
134
|
+
placement?: WidgetPlacement;
|
|
135
|
+
fitBounds: () => void;
|
|
136
|
+
panBy?: (dx: number, dy: number) => void;
|
|
137
|
+
zoomBy?: (delta: number) => void;
|
|
138
|
+
zoomLevel: number;
|
|
139
|
+
minZoom: number;
|
|
140
|
+
maxZoom: number;
|
|
141
|
+
deltaPan: number;
|
|
142
|
+
deltaZoom: number;
|
|
143
|
+
/** CSS inline style overrides. */
|
|
144
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
145
|
+
/** Additional CSS class. */
|
|
146
|
+
className?: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export class ViewControl extends Component<ViewControlProps> {
|
|
150
|
+
static displayName = 'ViewControl';
|
|
151
|
+
|
|
152
|
+
static defaultProps: Required<ViewControlProps> = {
|
|
153
|
+
id: undefined,
|
|
154
|
+
viewId: undefined,
|
|
155
|
+
placement: 'top-left',
|
|
156
|
+
fitBounds: () => {},
|
|
157
|
+
panBy: () => {},
|
|
158
|
+
zoomBy: () => {},
|
|
159
|
+
zoomLevel: 1,
|
|
160
|
+
deltaPan: 10,
|
|
161
|
+
deltaZoom: 0.1,
|
|
162
|
+
minZoom: 0.1,
|
|
163
|
+
maxZoom: 1,
|
|
164
|
+
style: {},
|
|
165
|
+
className: ''
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// pan actions
|
|
169
|
+
panUp = () => this.props.panBy(0, this.props.deltaPan);
|
|
170
|
+
panDown = () => this.props.panBy(0, -1 * this.props.deltaPan);
|
|
171
|
+
panLeft = () => this.props.panBy(this.props.deltaPan, 0);
|
|
172
|
+
panRight = () => this.props.panBy(-1 * this.props.deltaPan, 0);
|
|
173
|
+
|
|
174
|
+
// zoom actions
|
|
175
|
+
zoomIn = () => this.props.zoomBy(this.props.deltaZoom);
|
|
176
|
+
zoomOut = () => this.props.zoomBy(-1 * this.props.deltaZoom);
|
|
177
|
+
onChangeZoomLevel = (evt) => {
|
|
178
|
+
const delta = evt.target.value - this.props.zoomLevel;
|
|
179
|
+
this.props.zoomBy(delta);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
render() {
|
|
183
|
+
const buttons = [
|
|
184
|
+
{top: -2, left: 14, rotate: 0, onClick: this.panUp, content: '▲', key: 'up'},
|
|
185
|
+
{top: 12, left: 0, rotate: -90, onClick: this.panLeft, content: '◀', key: 'left'},
|
|
186
|
+
{top: 12, left: 28, rotate: 90, onClick: this.panRight, content: '▶', key: 'right'},
|
|
187
|
+
{top: 25, left: 14, rotate: 180, onClick: this.panDown, content: '▼', key: 'down'}
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<ViewControlWrapper>
|
|
192
|
+
<NavigationButtonContainer>
|
|
193
|
+
{buttons.map((b: any) => (
|
|
194
|
+
<NavigationButton key={b.key} top={`${b.top}px`} left={`${b.left}px`} rotate={b.rotate}>
|
|
195
|
+
<LongPressButton onClick={b.onClick}>{b.content}</LongPressButton>
|
|
196
|
+
</NavigationButton>
|
|
197
|
+
))}
|
|
198
|
+
<NavigationButton
|
|
199
|
+
top={'12px'}
|
|
200
|
+
left={'16px'}
|
|
201
|
+
onClick={() => {
|
|
202
|
+
// console.log('on click fit bounds') || this.props.fitBounds;
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
{'¤'}
|
|
206
|
+
</NavigationButton>
|
|
207
|
+
</NavigationButtonContainer>
|
|
208
|
+
<ZoomControlWrapper>
|
|
209
|
+
<ZoomControlButton>
|
|
210
|
+
<LongPressButton onClick={this.zoomIn}>{'+'}</LongPressButton>
|
|
211
|
+
</ZoomControlButton>
|
|
212
|
+
<VerticalSlider>
|
|
213
|
+
<input
|
|
214
|
+
type="range"
|
|
215
|
+
value={this.props.zoomLevel}
|
|
216
|
+
min={this.props.minZoom}
|
|
217
|
+
max={this.props.maxZoom}
|
|
218
|
+
step={this.props.deltaZoom}
|
|
219
|
+
onChange={this.onChangeZoomLevel}
|
|
220
|
+
/* @ts-expect-error TODO */
|
|
221
|
+
orient="vertical"
|
|
222
|
+
/>
|
|
223
|
+
</VerticalSlider>
|
|
224
|
+
<ZoomControlButton>
|
|
225
|
+
<LongPressButton onClick={this.zoomOut}>{'-'}</LongPressButton>
|
|
226
|
+
</ZoomControlButton>
|
|
227
|
+
</ZoomControlWrapper>
|
|
228
|
+
</ViewControlWrapper>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export class ViewControlWidget extends Widget<ViewControlProps> {
|
|
234
|
+
id = 'zoom';
|
|
235
|
+
placement: WidgetPlacement = 'top-left';
|
|
236
|
+
orientation: 'vertical' | 'horizontal' = 'vertical';
|
|
237
|
+
viewId?: string | null = null;
|
|
238
|
+
viewports: {[id: string]: Viewport} = {};
|
|
239
|
+
element?: HTMLDivElement;
|
|
240
|
+
className = 'deck-widget-view-control';
|
|
241
|
+
|
|
242
|
+
constructor(props: ViewControlProps) {
|
|
243
|
+
super(props);
|
|
244
|
+
this.props = {...ViewControl.defaultProps, ...props};
|
|
245
|
+
this.id = props.id || 'zoom';
|
|
246
|
+
this.viewId = props.viewId || null;
|
|
247
|
+
this.placement = props.placement || 'top-left';
|
|
248
|
+
// this.orientation = props.orientation || 'vertical';
|
|
249
|
+
// props.transitionDuration = props.transitionDuration || 200;
|
|
250
|
+
// props.zoomInLabel = props.zoomInLabel || 'Zoom In';
|
|
251
|
+
// props.zoomOutLabel = props.zoomOutLabel || 'Zoom Out';
|
|
252
|
+
props.style = props.style || {};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
onAdd({deck}: {deck: Deck<any>}): HTMLDivElement {
|
|
256
|
+
this.deck = deck;
|
|
257
|
+
this.element = document.createElement('div');
|
|
258
|
+
|
|
259
|
+
const {style, className} = this.props;
|
|
260
|
+
this.element.classList.add('deck-widget', 'deck-widget-zoom');
|
|
261
|
+
if (className) {
|
|
262
|
+
this.element.classList.add(className);
|
|
263
|
+
}
|
|
264
|
+
if (style) {
|
|
265
|
+
Object.entries(style).map(([key, value]) =>
|
|
266
|
+
this.element.style.setProperty(key, value as string)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return this.element;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
onRemove() {
|
|
274
|
+
this.deck = undefined;
|
|
275
|
+
this.element = undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
onRenderHTML(rootElement: HTMLElement): void {
|
|
279
|
+
const ui = (
|
|
280
|
+
<ViewControl
|
|
281
|
+
{...this.props}
|
|
282
|
+
zoomBy={this.handleDeltaZoom.bind(this)}
|
|
283
|
+
panBy={this.handlePanBy.bind(this)}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
render(ui, rootElement);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
setProps(props: Partial<ViewControlProps>) {
|
|
290
|
+
Object.assign(this.props, props);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
onViewportChange(viewport: Viewport) {
|
|
294
|
+
this.viewports[viewport.id] = viewport;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
handleDeltaZoom(deltaZoom: number) {
|
|
298
|
+
// console.log('Handle delta zoom');
|
|
299
|
+
for (const view of this.deck.getViewports()) {
|
|
300
|
+
this.handleZoomView(view, view.zoom + deltaZoom);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
handlePanBy(deltaX: number, deltaY: number) {
|
|
305
|
+
// console.log('Handle panby', deltaX, deltaY);
|
|
306
|
+
for (const viewport of this.deck.getViewports()) {
|
|
307
|
+
this.handlePanViewport(viewport, deltaX, deltaY);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
handleZoomView(viewport: Viewport, nextZoom: number) {
|
|
312
|
+
const viewId = this.viewId || viewport?.id || 'default-view';
|
|
313
|
+
// @ts-expect-error TODO we lack a proper API for getting viewStates
|
|
314
|
+
const viewState = this.deck.viewManager.viewState || viewport;
|
|
315
|
+
const nextViewState = {
|
|
316
|
+
...viewState,
|
|
317
|
+
zoom: nextZoom
|
|
318
|
+
// transitionDuration: this.props.transitionDuration,
|
|
319
|
+
// transitionInterpolator: new FlyToInterpolator()
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// @ts-ignore Using private method temporary until there's a public one
|
|
323
|
+
this.deck._onViewStateChange({viewId, viewState: nextViewState, interactionState: {}});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
handlePanViewport(viewport: Viewport, deltaX: number, deltaY: number) {
|
|
327
|
+
const viewId = this.viewId || viewport?.id || 'default-view';
|
|
328
|
+
// @ts-expect-error TODO we lack a proper API for getting viewStates
|
|
329
|
+
const viewState = this.deck.viewManager.viewState || viewport;
|
|
330
|
+
// console.log('Handle pan viewport', deltaX, deltaY, viewState);
|
|
331
|
+
const nextViewState = {
|
|
332
|
+
...viewState,
|
|
333
|
+
position: [viewport.position[0] + deltaX, viewport.position[1] + deltaY]
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// @ts-ignore Using private method temporary until there's a public one
|
|
337
|
+
this.deck._onViewStateChange({viewId, viewState: nextViewState, interactionState: {}});
|
|
338
|
+
}
|
|
339
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export {PanWidget} from './widgets/pan-widget';
|
|
6
|
+
export type {PanWidgetProps} from './widgets/pan-widget';
|
|
7
|
+
|
|
8
|
+
export {ZoomRangeWidget} from './widgets/zoom-range-widget';
|
|
9
|
+
export type {ZoomRangeWidgetProps} from './widgets/zoom-range-widget';
|
|
10
|
+
|
|
11
|
+
export {HtmlOverlayWidget} from './widgets/html-overlay-widget';
|
|
12
|
+
export type {HtmlOverlayWidgetProps} from './widgets/html-overlay-widget';
|
|
13
|
+
export {HtmlOverlayItem} from './widgets/html-overlay-item';
|
|
14
|
+
export type {HtmlOverlayItemProps} from './widgets/html-overlay-item';
|
|
15
|
+
export {HtmlClusterWidget} from './widgets/html-cluster-widget';
|
|
16
|
+
export type {HtmlClusterWidgetProps} from './widgets/html-cluster-widget';
|
|
17
|
+
export {HtmlTooltipWidget} from './widgets/html-tooltip-widget';
|
|
18
|
+
export type {HtmlTooltipWidgetProps} from './widgets/html-tooltip-widget';
|