@deck.gl/widgets 9.3.0-alpha.6 → 9.3.0-beta.2
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/dist/compass-widget.d.ts +12 -0
- package/dist/compass-widget.d.ts.map +1 -1
- package/dist/compass-widget.js +9 -3
- package/dist/compass-widget.js.map +1 -1
- package/dist/dist.dev.js +285 -93
- package/dist/fullscreen-widget.d.ts +5 -0
- package/dist/fullscreen-widget.d.ts.map +1 -1
- package/dist/fullscreen-widget.js +18 -8
- package/dist/fullscreen-widget.js.map +1 -1
- package/dist/geocoder-widget.d.ts +13 -0
- package/dist/geocoder-widget.d.ts.map +1 -1
- package/dist/geocoder-widget.js +13 -1
- package/dist/geocoder-widget.js.map +1 -1
- package/dist/gimbal-widget.d.ts +12 -0
- package/dist/gimbal-widget.d.ts.map +1 -1
- package/dist/gimbal-widget.js +4 -1
- package/dist/gimbal-widget.js.map +1 -1
- package/dist/index.cjs +278 -90
- package/dist/index.cjs.map +3 -3
- package/dist/loading-widget.d.ts +5 -0
- package/dist/loading-widget.d.ts.map +1 -1
- package/dist/loading-widget.js +4 -1
- package/dist/loading-widget.js.map +1 -1
- package/dist/reset-view-widget.d.ts +9 -0
- package/dist/reset-view-widget.d.ts.map +1 -1
- package/dist/reset-view-widget.js +4 -1
- package/dist/reset-view-widget.js.map +1 -1
- package/dist/stats-widget.d.ts +18 -3
- package/dist/stats-widget.d.ts.map +1 -1
- package/dist/stats-widget.js +29 -12
- package/dist/stats-widget.js.map +1 -1
- package/dist/theme-widget.d.ts +20 -2
- package/dist/theme-widget.d.ts.map +1 -1
- package/dist/theme-widget.js +38 -14
- package/dist/theme-widget.js.map +1 -1
- package/dist/timeline-widget.d.ts +34 -3
- package/dist/timeline-widget.d.ts.map +1 -1
- package/dist/timeline-widget.js +98 -24
- package/dist/timeline-widget.js.map +1 -1
- package/dist/zoom-widget.d.ts +22 -1
- package/dist/zoom-widget.d.ts.map +1 -1
- package/dist/zoom-widget.js +62 -15
- package/dist/zoom-widget.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +3 -3
- package/src/compass-widget.tsx +23 -3
- package/src/fullscreen-widget.tsx +24 -9
- package/src/geocoder-widget.tsx +23 -1
- package/src/gimbal-widget.tsx +17 -1
- package/src/loading-widget.tsx +11 -1
- package/src/reset-view-widget.tsx +15 -1
- package/src/stats-widget.tsx +43 -14
- package/src/theme-widget.tsx +56 -17
- package/src/timeline-widget.tsx +123 -24
- package/src/zoom-widget.tsx +108 -17
package/src/zoom-widget.tsx
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Widget, FlyToInterpolator, LinearInterpolator} from '@deck.gl/core';
|
|
6
|
-
import type {WidgetProps, WidgetPlacement} from '@deck.gl/core';
|
|
5
|
+
import {Widget, FlyToInterpolator, LinearInterpolator, OrthographicView} from '@deck.gl/core';
|
|
6
|
+
import type {WidgetProps, WidgetPlacement, OrthographicViewState} from '@deck.gl/core';
|
|
7
7
|
import {render} from 'preact';
|
|
8
8
|
import {ButtonGroup} from './lib/components/button-group';
|
|
9
9
|
import {IconButton} from './lib/components/icon-button';
|
|
@@ -21,6 +21,26 @@ export type ZoomWidgetProps = WidgetProps & {
|
|
|
21
21
|
zoomOutLabel?: string;
|
|
22
22
|
/** Zoom transition duration in ms. 0 disables the transition */
|
|
23
23
|
transitionDuration?: number;
|
|
24
|
+
/** Which axes to apply zoom to. One of 'X', 'Y' or 'all'.
|
|
25
|
+
* Only effective if the current view is OrthographicView.
|
|
26
|
+
*/
|
|
27
|
+
zoomAxis?: 'X' | 'Y' | 'all';
|
|
28
|
+
/**
|
|
29
|
+
* Callback when zoom buttons are clicked.
|
|
30
|
+
* Called for each viewport that will be zoomed.
|
|
31
|
+
*/
|
|
32
|
+
onZoom?: (params: {
|
|
33
|
+
/** The view being zoomed */
|
|
34
|
+
viewId: string;
|
|
35
|
+
/** Zoom direction: +1 for zoom in, -1 for zoom out */
|
|
36
|
+
delta: number;
|
|
37
|
+
/** The new zoom level */
|
|
38
|
+
zoom: number;
|
|
39
|
+
/** The new zoom level of the X axis, if using OrthographicView */
|
|
40
|
+
zoomX?: number;
|
|
41
|
+
/** The new zoom level of the Y axis, if using OrthographicView */
|
|
42
|
+
zoomY?: number;
|
|
43
|
+
}) => void;
|
|
24
44
|
};
|
|
25
45
|
|
|
26
46
|
export class ZoomWidget extends Widget<ZoomWidgetProps> {
|
|
@@ -32,7 +52,9 @@ export class ZoomWidget extends Widget<ZoomWidgetProps> {
|
|
|
32
52
|
transitionDuration: 200,
|
|
33
53
|
zoomInLabel: 'Zoom In',
|
|
34
54
|
zoomOutLabel: 'Zoom Out',
|
|
35
|
-
|
|
55
|
+
zoomAxis: 'all',
|
|
56
|
+
viewId: null,
|
|
57
|
+
onZoom: () => {}
|
|
36
58
|
};
|
|
37
59
|
|
|
38
60
|
className = 'deck-widget-zoom';
|
|
@@ -67,22 +89,66 @@ export class ZoomWidget extends Widget<ZoomWidgetProps> {
|
|
|
67
89
|
render(ui, rootElement);
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
|
|
92
|
+
isOrthographicView(viewId: string): boolean {
|
|
93
|
+
const deck = this.deck;
|
|
94
|
+
const view = deck?.isInitialized && deck.getView(viewId);
|
|
95
|
+
return view instanceof OrthographicView;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
handleZoom(viewId: string, delta: number) {
|
|
71
99
|
// Respect minZoom/maxZoom constraints from the view state
|
|
72
100
|
const viewState = this.getViewState(viewId);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
const newViewState: Record<string, unknown> = {};
|
|
102
|
+
|
|
103
|
+
if (this.isOrthographicView(viewId)) {
|
|
104
|
+
const {zoomAxis} = this.props;
|
|
105
|
+
const {zoomX, minZoomX, maxZoomX, zoomY, minZoomY, maxZoomY} = normalizeOrthographicViewState(
|
|
106
|
+
viewState as any
|
|
107
|
+
);
|
|
108
|
+
let nextZoom: number;
|
|
109
|
+
let nextZoomY: number;
|
|
110
|
+
if (zoomAxis === 'X') {
|
|
111
|
+
nextZoom = clamp(zoomX + delta, minZoomX, maxZoomX);
|
|
112
|
+
nextZoomY = zoomY;
|
|
113
|
+
} else if (zoomAxis === 'Y') {
|
|
114
|
+
nextZoom = zoomX;
|
|
115
|
+
nextZoomY = clamp(zoomY + delta, minZoomY, maxZoomY);
|
|
116
|
+
} else {
|
|
117
|
+
const clampedDelta = clamp(
|
|
118
|
+
delta,
|
|
119
|
+
Math.max(minZoomX - zoomX, minZoomY - zoomY),
|
|
120
|
+
Math.min(maxZoomX - zoomX, maxZoomY - zoomY)
|
|
121
|
+
);
|
|
122
|
+
nextZoom = zoomX + clampedDelta;
|
|
123
|
+
nextZoomY = zoomY + clampedDelta;
|
|
80
124
|
}
|
|
125
|
+
newViewState.zoom = [nextZoom, nextZoomY];
|
|
126
|
+
newViewState.zoomX = nextZoom;
|
|
127
|
+
newViewState.zoomY = nextZoomY;
|
|
128
|
+
// Call callback
|
|
129
|
+
this.props.onZoom?.({
|
|
130
|
+
viewId,
|
|
131
|
+
delta,
|
|
132
|
+
// `zoom` will not match the new state if using 2D zoom. Deprecated behavior for backward compatibility.
|
|
133
|
+
zoom: zoomAxis === 'Y' ? nextZoomY : nextZoom,
|
|
134
|
+
zoomX: nextZoom,
|
|
135
|
+
zoomY: nextZoomY
|
|
136
|
+
});
|
|
137
|
+
} else {
|
|
138
|
+
const {zoom = 0, minZoom, maxZoom} = viewState as any;
|
|
139
|
+
const nextZoom = clamp(zoom + delta, minZoom, maxZoom);
|
|
140
|
+
newViewState.zoom = nextZoom;
|
|
141
|
+
// Call callback
|
|
142
|
+
this.props.onZoom?.({
|
|
143
|
+
viewId,
|
|
144
|
+
delta,
|
|
145
|
+
zoom: nextZoom
|
|
146
|
+
});
|
|
81
147
|
}
|
|
82
148
|
|
|
83
149
|
const nextViewState: Record<string, unknown> = {
|
|
84
150
|
...viewState,
|
|
85
|
-
|
|
151
|
+
...newViewState
|
|
86
152
|
};
|
|
87
153
|
if (this.props.transitionDuration > 0) {
|
|
88
154
|
nextViewState.transitionDuration = this.props.transitionDuration;
|
|
@@ -90,7 +156,7 @@ export class ZoomWidget extends Widget<ZoomWidgetProps> {
|
|
|
90
156
|
'latitude' in nextViewState
|
|
91
157
|
? new FlyToInterpolator()
|
|
92
158
|
: new LinearInterpolator({
|
|
93
|
-
transitionProps: ['zoom']
|
|
159
|
+
transitionProps: 'zoomX' in newViewState ? ['zoomX', 'zoomY'] : ['zoom']
|
|
94
160
|
});
|
|
95
161
|
}
|
|
96
162
|
this.setViewState(viewId, nextViewState);
|
|
@@ -99,16 +165,41 @@ export class ZoomWidget extends Widget<ZoomWidgetProps> {
|
|
|
99
165
|
handleZoomIn() {
|
|
100
166
|
const viewIds = this.viewId ? [this.viewId] : (this.deck?.getViews().map(v => v.id) ?? []);
|
|
101
167
|
for (const viewId of viewIds) {
|
|
102
|
-
|
|
103
|
-
this.handleZoom(viewId, (viewState.zoom as number) + 1);
|
|
168
|
+
this.handleZoom(viewId, 1);
|
|
104
169
|
}
|
|
105
170
|
}
|
|
106
171
|
|
|
107
172
|
handleZoomOut() {
|
|
108
173
|
const viewIds = this.viewId ? [this.viewId] : (this.deck?.getViews().map(v => v.id) ?? []);
|
|
109
174
|
for (const viewId of viewIds) {
|
|
110
|
-
|
|
111
|
-
this.handleZoom(viewId, (viewState.zoom as number) - 1);
|
|
175
|
+
this.handleZoom(viewId, -1);
|
|
112
176
|
}
|
|
113
177
|
}
|
|
114
178
|
}
|
|
179
|
+
|
|
180
|
+
function clamp(zoom: number, minZoom: number, maxZoom: number): number {
|
|
181
|
+
return zoom < minZoom ? minZoom : zoom > maxZoom ? maxZoom : zoom;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function normalizeOrthographicViewState({
|
|
185
|
+
zoom = 0,
|
|
186
|
+
zoomX,
|
|
187
|
+
zoomY,
|
|
188
|
+
minZoom = -Infinity,
|
|
189
|
+
maxZoom = Infinity,
|
|
190
|
+
minZoomX = minZoom,
|
|
191
|
+
maxZoomX = maxZoom,
|
|
192
|
+
minZoomY = minZoom,
|
|
193
|
+
maxZoomY = maxZoom
|
|
194
|
+
}: OrthographicViewState): {
|
|
195
|
+
zoomX: number;
|
|
196
|
+
zoomY: number;
|
|
197
|
+
minZoomX: number;
|
|
198
|
+
maxZoomX: number;
|
|
199
|
+
minZoomY: number;
|
|
200
|
+
maxZoomY: number;
|
|
201
|
+
} {
|
|
202
|
+
zoomX = zoomX ?? (Array.isArray(zoom) ? zoom[0] : zoom);
|
|
203
|
+
zoomY = zoomY ?? (Array.isArray(zoom) ? zoom[1] : zoom);
|
|
204
|
+
return {zoomX, zoomY, minZoomX, minZoomY, maxZoomX, maxZoomY};
|
|
205
|
+
}
|