@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.
Files changed (65) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +43 -0
  3. package/dist/_deprecate/long-press-button.d.ts +13 -0
  4. package/dist/_deprecate/long-press-button.d.ts.map +1 -0
  5. package/dist/_deprecate/long-press-button.js +32 -0
  6. package/dist/_deprecate/long-press-button.js.map +1 -0
  7. package/dist/_deprecate/view-control-widget.d.ts +78 -0
  8. package/dist/_deprecate/view-control-widget.d.ts.map +1 -0
  9. package/dist/_deprecate/view-control-widget.js +198 -0
  10. package/dist/_deprecate/view-control-widget.js.map +1 -0
  11. package/dist/index.cjs +708 -0
  12. package/dist/index.cjs.map +7 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +10 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/widgets/html-cluster-widget.d.ts +25 -0
  18. package/dist/widgets/html-cluster-widget.d.ts.map +1 -0
  19. package/dist/widgets/html-cluster-widget.js +39 -0
  20. package/dist/widgets/html-cluster-widget.js.map +1 -0
  21. package/dist/widgets/html-overlay-item.d.ts +13 -0
  22. package/dist/widgets/html-overlay-item.d.ts.map +1 -0
  23. package/dist/widgets/html-overlay-item.js +10 -0
  24. package/dist/widgets/html-overlay-item.js.map +1 -0
  25. package/dist/widgets/html-overlay-widget.d.ts +45 -0
  26. package/dist/widgets/html-overlay-widget.d.ts.map +1 -0
  27. package/dist/widgets/html-overlay-widget.js +112 -0
  28. package/dist/widgets/html-overlay-widget.js.map +1 -0
  29. package/dist/widgets/html-tooltip-widget.d.ts +30 -0
  30. package/dist/widgets/html-tooltip-widget.d.ts.map +1 -0
  31. package/dist/widgets/html-tooltip-widget.js +67 -0
  32. package/dist/widgets/html-tooltip-widget.js.map +1 -0
  33. package/dist/widgets/long-press-button.d.ts +22 -0
  34. package/dist/widgets/long-press-button.d.ts.map +1 -0
  35. package/dist/widgets/long-press-button.js +84 -0
  36. package/dist/widgets/long-press-button.js.map +1 -0
  37. package/dist/widgets/long-press-controller.d.ts +27 -0
  38. package/dist/widgets/long-press-controller.d.ts.map +1 -0
  39. package/dist/widgets/long-press-controller.js +144 -0
  40. package/dist/widgets/long-press-controller.js.map +1 -0
  41. package/dist/widgets/pan-widget.d.ts +33 -0
  42. package/dist/widgets/pan-widget.d.ts.map +1 -0
  43. package/dist/widgets/pan-widget.js +141 -0
  44. package/dist/widgets/pan-widget.js.map +1 -0
  45. package/dist/widgets/view-manager-utils.d.ts +11 -0
  46. package/dist/widgets/view-manager-utils.d.ts.map +1 -0
  47. package/dist/widgets/view-manager-utils.js +13 -0
  48. package/dist/widgets/view-manager-utils.js.map +1 -0
  49. package/dist/widgets/zoom-range-widget.d.ts +43 -0
  50. package/dist/widgets/zoom-range-widget.d.ts.map +1 -0
  51. package/dist/widgets/zoom-range-widget.js +190 -0
  52. package/dist/widgets/zoom-range-widget.js.map +1 -0
  53. package/package.json +41 -0
  54. package/src/_deprecate/long-press-button.tsx +50 -0
  55. package/src/_deprecate/view-control-widget.tsx +339 -0
  56. package/src/index.ts +18 -0
  57. package/src/widgets/html-cluster-widget.ts +84 -0
  58. package/src/widgets/html-overlay-item.tsx +32 -0
  59. package/src/widgets/html-overlay-widget.tsx +147 -0
  60. package/src/widgets/html-tooltip-widget.tsx +93 -0
  61. package/src/widgets/long-press-button.tsx +125 -0
  62. package/src/widgets/long-press-controller.ts +159 -0
  63. package/src/widgets/pan-widget.tsx +182 -0
  64. package/src/widgets/view-manager-utils.ts +24 -0
  65. package/src/widgets/zoom-range-widget.tsx +284 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,708 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __publicField = (obj, key, value) => {
30
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+ return value;
32
+ };
33
+
34
+ // dist/index.js
35
+ var dist_exports = {};
36
+ __export(dist_exports, {
37
+ HtmlClusterWidget: () => HtmlClusterWidget,
38
+ HtmlOverlayItem: () => HtmlOverlayItem,
39
+ HtmlOverlayWidget: () => HtmlOverlayWidget,
40
+ HtmlTooltipWidget: () => HtmlTooltipWidget,
41
+ PanWidget: () => PanWidget,
42
+ ZoomRangeWidget: () => ZoomRangeWidget
43
+ });
44
+ module.exports = __toCommonJS(dist_exports);
45
+
46
+ // dist/widgets/pan-widget.js
47
+ var import_jsx_runtime2 = require("preact/jsx-runtime");
48
+ var import_preact2 = require("preact");
49
+
50
+ // dist/widgets/long-press-button.js
51
+ var import_jsx_runtime = require("preact/jsx-runtime");
52
+ var import_preact = require("preact");
53
+ var REPEAT_DELAY_MS = 300;
54
+ var REPEAT_INTERVAL_MS = 100;
55
+ var LongPressButton = class extends import_preact.Component {
56
+ buttonPressTimer = null;
57
+ usingPointerEvents = false;
58
+ stopEvent(event) {
59
+ event.stopPropagation();
60
+ if (typeof event.stopImmediatePropagation === "function") {
61
+ event.stopImmediatePropagation();
62
+ }
63
+ if (typeof event.preventDefault === "function") {
64
+ event.preventDefault();
65
+ }
66
+ }
67
+ repeat = () => {
68
+ if (this.buttonPressTimer) {
69
+ this.props.onClick();
70
+ this.buttonPressTimer = setTimeout(this.repeat, REPEAT_INTERVAL_MS);
71
+ }
72
+ };
73
+ startPress(event) {
74
+ this.stopEvent(event);
75
+ this.props.onClick();
76
+ this.buttonPressTimer = setTimeout(this.repeat, REPEAT_DELAY_MS);
77
+ }
78
+ endPress(event) {
79
+ if (event) {
80
+ this.stopEvent(event);
81
+ }
82
+ if (this.buttonPressTimer) {
83
+ clearTimeout(this.buttonPressTimer);
84
+ }
85
+ this.buttonPressTimer = null;
86
+ }
87
+ handlePointerDown = (event) => {
88
+ var _a, _b;
89
+ this.usingPointerEvents = true;
90
+ (_b = (_a = event.currentTarget) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
91
+ this.startPress(event);
92
+ };
93
+ handlePointerUp = (event) => {
94
+ var _a, _b;
95
+ (_b = (_a = event.currentTarget) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
96
+ this.endPress(event);
97
+ };
98
+ handlePointerCancel = (event) => {
99
+ var _a, _b;
100
+ (_b = (_a = event.currentTarget) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
101
+ this.endPress(event);
102
+ };
103
+ handleMouseDown = (event) => {
104
+ if (this.usingPointerEvents) {
105
+ return;
106
+ }
107
+ this.startPress(event);
108
+ document.addEventListener("mouseup", this.handleMouseUp, { once: true });
109
+ };
110
+ handleMouseUp = (event) => {
111
+ if (this.usingPointerEvents) {
112
+ return;
113
+ }
114
+ this.endPress(event);
115
+ };
116
+ handleTouchStart = (event) => {
117
+ if (this.usingPointerEvents) {
118
+ return;
119
+ }
120
+ this.startPress(event);
121
+ document.addEventListener("touchend", this.handleTouchEnd, { once: true });
122
+ document.addEventListener("touchcancel", this.handleTouchEnd, { once: true });
123
+ };
124
+ handleTouchEnd = (event) => {
125
+ if (this.usingPointerEvents) {
126
+ return;
127
+ }
128
+ this.endPress(event);
129
+ };
130
+ render() {
131
+ return (0, import_jsx_runtime.jsx)("div", { className: "deck-widget-button", children: (0, import_jsx_runtime.jsx)("div", { style: { pointerEvents: "auto" }, onPointerDown: this.handlePointerDown, onPointerUp: this.handlePointerUp, onPointerCancel: this.handlePointerCancel, onPointerMove: (event) => this.stopEvent(event), onPointerLeave: this.handlePointerCancel, onPointerOut: this.handlePointerCancel, onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onMouseMove: (event) => this.stopEvent(event), onTouchStart: this.handleTouchStart, onTouchEnd: this.handleTouchEnd, onTouchMove: (event) => this.stopEvent(event), onContextMenu: (event) => event.preventDefault(), onWheel: (event) => this.stopEvent(event), onClick: (event) => this.stopEvent(event), children: this.props.children }) });
132
+ }
133
+ };
134
+
135
+ // dist/widgets/view-manager-utils.js
136
+ function hasViewManager(deck) {
137
+ return Boolean(deck && typeof deck === "object" && "viewManager" in deck);
138
+ }
139
+ function cloneViewState(value) {
140
+ if (value && typeof value === "object") {
141
+ return { ...value };
142
+ }
143
+ return {};
144
+ }
145
+
146
+ // dist/widgets/pan-widget.js
147
+ var import_core = require("@deck.gl/core");
148
+ var WRAPPER_STYLE = {
149
+ position: "absolute",
150
+ display: "flex",
151
+ flexDirection: "column",
152
+ alignItems: "center",
153
+ zIndex: "99",
154
+ userSelect: "none"
155
+ };
156
+ var NAVIGATION_CONTAINER_STYLE = {
157
+ position: "relative",
158
+ background: "#f7f7f7",
159
+ borderRadius: "23px",
160
+ border: "0.5px solid #eaeaea",
161
+ boxShadow: "inset 11px 11px 5px -7px rgba(230, 230, 230, 0.49)",
162
+ height: "46px",
163
+ width: "46px"
164
+ };
165
+ var NAVIGATION_BUTTON_STYLE = {
166
+ color: "#848484",
167
+ cursor: "pointer",
168
+ position: "absolute",
169
+ pointerEvents: "auto"
170
+ };
171
+ var _PanWidget = class extends import_core.Widget {
172
+ placement = "top-left";
173
+ className = "deck-widget-pan";
174
+ deck = null;
175
+ step;
176
+ constructor(props = {}) {
177
+ super({ ..._PanWidget.defaultProps, ...props });
178
+ this.viewId = props.viewId ?? null;
179
+ this.placement = props.placement ?? "top-left";
180
+ this.step = props.step ?? _PanWidget.defaultProps.step;
181
+ }
182
+ setProps(props) {
183
+ if (props.viewId !== void 0) {
184
+ this.viewId = props.viewId;
185
+ }
186
+ if (props.placement !== void 0) {
187
+ this.placement = props.placement;
188
+ }
189
+ if (props.step !== void 0) {
190
+ this.step = props.step;
191
+ }
192
+ super.setProps(props);
193
+ }
194
+ onAdd({ deck, viewId }) {
195
+ this.deck = deck;
196
+ if (this.viewId === void 0) {
197
+ this.viewId = viewId;
198
+ }
199
+ }
200
+ onRemove() {
201
+ this.deck = null;
202
+ }
203
+ onRenderHTML(rootElement) {
204
+ const style = { ...WRAPPER_STYLE, ...this.props.style };
205
+ Object.assign(rootElement.style, style);
206
+ const buttons = [
207
+ { top: -2, left: 14, onClick: () => this.handlePan(0, this.step), label: "\u25B2", key: "up" },
208
+ { top: 12, left: 0, onClick: () => this.handlePan(this.step, 0), label: "\u25C0", key: "left" },
209
+ { top: 12, left: 28, onClick: () => this.handlePan(-this.step, 0), label: "\u25B6", key: "right" },
210
+ { top: 25, left: 14, onClick: () => this.handlePan(0, -this.step), label: "\u25BC", key: "down" }
211
+ ];
212
+ const ui = (0, import_jsx_runtime2.jsx)("div", { style: NAVIGATION_CONTAINER_STYLE, children: buttons.map((button) => {
213
+ const buttonStyle = {
214
+ ...NAVIGATION_BUTTON_STYLE,
215
+ top: `${button.top}px`,
216
+ left: `${button.left}px`
217
+ };
218
+ return (0, import_jsx_runtime2.jsx)("div", { style: buttonStyle, children: (0, import_jsx_runtime2.jsx)(LongPressButton, { onClick: button.onClick, children: button.label }) }, button.key);
219
+ }) });
220
+ (0, import_preact2.render)(ui, rootElement);
221
+ }
222
+ getTargetViewports() {
223
+ var _a;
224
+ const deck = this.deck;
225
+ if (!deck) {
226
+ return [];
227
+ }
228
+ if (this.viewId) {
229
+ if (hasViewManager(deck)) {
230
+ const viewport = (_a = deck.viewManager) == null ? void 0 : _a.getViewport(this.viewId);
231
+ return viewport ? [viewport] : [];
232
+ }
233
+ return [];
234
+ }
235
+ return deck.getViewports();
236
+ }
237
+ getViewState(viewport) {
238
+ const deck = this.deck;
239
+ const viewManager = hasViewManager(deck) ? deck.viewManager : null;
240
+ const viewId = this.viewId || viewport.id;
241
+ if (viewManager) {
242
+ try {
243
+ return { ...viewManager.getViewState(viewId) };
244
+ } catch (err) {
245
+ return cloneViewState(viewManager.viewState);
246
+ }
247
+ }
248
+ return cloneViewState(viewport);
249
+ }
250
+ handlePan(deltaX, deltaY) {
251
+ if (!this.deck) {
252
+ return;
253
+ }
254
+ const viewports = this.getTargetViewports();
255
+ for (const viewport of viewports) {
256
+ const center = viewport.unproject([viewport.width / 2, viewport.height / 2]);
257
+ if (center) {
258
+ const nextPixel = [
259
+ viewport.width / 2 + deltaX,
260
+ viewport.height / 2 + deltaY
261
+ ];
262
+ const viewState = this.getViewState(viewport);
263
+ const panUpdate = viewport.panByPosition(center, nextPixel);
264
+ const nextViewState = { ...viewState, ...panUpdate };
265
+ const viewId = this.viewId || viewport.id || "default-view";
266
+ this.deck._onViewStateChange({ viewId, viewState: nextViewState, interactionState: {} });
267
+ }
268
+ }
269
+ }
270
+ };
271
+ var PanWidget = _PanWidget;
272
+ __publicField(PanWidget, "defaultProps", {
273
+ id: "pan",
274
+ viewId: null,
275
+ placement: "top-left",
276
+ step: 48,
277
+ style: {},
278
+ className: ""
279
+ });
280
+
281
+ // dist/widgets/zoom-range-widget.js
282
+ var import_jsx_runtime3 = require("preact/jsx-runtime");
283
+ var import_preact3 = require("preact");
284
+ var import_core2 = require("@deck.gl/core");
285
+ var WRAPPER_STYLE2 = {
286
+ position: "absolute",
287
+ display: "flex",
288
+ flexDirection: "column",
289
+ alignItems: "center",
290
+ background: "#f7f7f7",
291
+ border: "0.5px solid #eaeaea",
292
+ marginTop: "6px",
293
+ padding: "2px 0",
294
+ width: "18px",
295
+ userSelect: "none",
296
+ pointerEvents: "auto"
297
+ };
298
+ var ZOOM_BUTTON_STYLE = {
299
+ cursor: "pointer",
300
+ fontSize: "14px",
301
+ fontWeight: "500",
302
+ margin: "-4px"
303
+ };
304
+ var SLIDER_CONTAINER_STYLE = {
305
+ display: "inline-block",
306
+ height: "100px",
307
+ padding: "0",
308
+ width: "10px"
309
+ };
310
+ var VERTICAL_SLIDER_STYLE = {
311
+ writingMode: "vertical-lr",
312
+ height: "100px",
313
+ padding: "0",
314
+ margin: "0",
315
+ width: "10px"
316
+ };
317
+ var _ZoomRangeWidget = class extends import_core2.Widget {
318
+ placement = "top-left";
319
+ className = "deck-widget-zoom-range";
320
+ deck = null;
321
+ step;
322
+ currentZoom = 0;
323
+ inferredMinZoom = null;
324
+ inferredMaxZoom = null;
325
+ constructor(props = {}) {
326
+ super({ ..._ZoomRangeWidget.defaultProps, ...props });
327
+ this.viewId = props.viewId ?? null;
328
+ this.placement = props.placement ?? "top-left";
329
+ this.step = props.step ?? _ZoomRangeWidget.defaultProps.step;
330
+ }
331
+ setProps(props) {
332
+ if (props.viewId !== void 0) {
333
+ this.viewId = props.viewId;
334
+ }
335
+ if (props.placement !== void 0) {
336
+ this.placement = props.placement;
337
+ }
338
+ if (props.step !== void 0) {
339
+ this.step = props.step;
340
+ }
341
+ super.setProps(props);
342
+ }
343
+ onAdd({ deck, viewId }) {
344
+ this.deck = deck;
345
+ if (this.viewId === void 0) {
346
+ this.viewId = viewId;
347
+ }
348
+ }
349
+ onRemove() {
350
+ this.deck = null;
351
+ }
352
+ onRenderHTML(rootElement) {
353
+ const style = { ...WRAPPER_STYLE2, ...this.props.style };
354
+ Object.assign(rootElement.style, style);
355
+ const { minZoom, maxZoom } = this.getZoomBounds();
356
+ const clampedZoom = Math.max(minZoom, Math.min(maxZoom, this.currentZoom));
357
+ const stopEventPropagation = (event) => {
358
+ event.stopPropagation();
359
+ if (typeof event.stopImmediatePropagation === "function") {
360
+ event.stopImmediatePropagation();
361
+ }
362
+ };
363
+ const ui = (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [(0, import_jsx_runtime3.jsx)("div", { style: ZOOM_BUTTON_STYLE, children: (0, import_jsx_runtime3.jsx)(LongPressButton, { onClick: () => this.handleZoomDelta(this.step), children: "+" }) }), (0, import_jsx_runtime3.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: (0, import_jsx_runtime3.jsx)("input", {
364
+ type: "range",
365
+ value: clampedZoom,
366
+ min: minZoom,
367
+ max: maxZoom,
368
+ step: this.step,
369
+ onInput: (event) => this.handleZoomTo(Number(event.target.value)),
370
+ onChange: (event) => this.handleZoomTo(Number(event.target.value)),
371
+ onPointerDown: stopEventPropagation,
372
+ onPointerMove: stopEventPropagation,
373
+ onPointerUp: stopEventPropagation,
374
+ onMouseDown: stopEventPropagation,
375
+ onMouseMove: stopEventPropagation,
376
+ onMouseUp: stopEventPropagation,
377
+ onClick: stopEventPropagation,
378
+ onWheel: stopEventPropagation,
379
+ onTouchStart: stopEventPropagation,
380
+ onTouchMove: stopEventPropagation,
381
+ onTouchEnd: stopEventPropagation,
382
+ /* @ts-expect-error - non-standard attribute for vertical sliders */
383
+ orient: "vertical",
384
+ style: VERTICAL_SLIDER_STYLE
385
+ }) }), (0, import_jsx_runtime3.jsx)("div", { style: ZOOM_BUTTON_STYLE, children: (0, import_jsx_runtime3.jsx)(LongPressButton, { onClick: () => this.handleZoomDelta(-this.step), children: "-" }) })] });
386
+ (0, import_preact3.render)(ui, rootElement);
387
+ }
388
+ onViewportChange(viewport) {
389
+ const viewState = this.getViewState(viewport);
390
+ const zoom = Number(viewState == null ? void 0 : viewState.zoom);
391
+ if (Number.isFinite(zoom)) {
392
+ this.currentZoom = zoom;
393
+ }
394
+ if (this.props.minZoom === void 0) {
395
+ const minZoom = Number(viewState == null ? void 0 : viewState.minZoom);
396
+ if (Number.isFinite(minZoom)) {
397
+ this.inferredMinZoom = minZoom;
398
+ }
399
+ }
400
+ if (this.props.maxZoom === void 0) {
401
+ const maxZoom = Number(viewState == null ? void 0 : viewState.maxZoom);
402
+ if (Number.isFinite(maxZoom)) {
403
+ this.inferredMaxZoom = maxZoom;
404
+ }
405
+ }
406
+ this.updateHTML();
407
+ }
408
+ getZoomBounds() {
409
+ const minZoom = this.props.minZoom ?? this.inferredMinZoom ?? Number.NEGATIVE_INFINITY;
410
+ const maxZoom = this.props.maxZoom ?? this.inferredMaxZoom ?? Number.POSITIVE_INFINITY;
411
+ if (minZoom > maxZoom) {
412
+ return { minZoom: maxZoom, maxZoom: minZoom };
413
+ }
414
+ return {
415
+ minZoom: Number.isFinite(minZoom) ? minZoom : -20,
416
+ maxZoom: Number.isFinite(maxZoom) ? maxZoom : 20
417
+ };
418
+ }
419
+ getTargetViewports() {
420
+ var _a;
421
+ const deck = this.deck;
422
+ if (!deck) {
423
+ return [];
424
+ }
425
+ if (this.viewId) {
426
+ if (hasViewManager(deck)) {
427
+ const viewport = (_a = deck.viewManager) == null ? void 0 : _a.getViewport(this.viewId);
428
+ return viewport ? [viewport] : [];
429
+ }
430
+ return [];
431
+ }
432
+ return deck.getViewports();
433
+ }
434
+ getViewState(viewport) {
435
+ const deck = this.deck;
436
+ const viewManager = hasViewManager(deck) ? deck.viewManager : null;
437
+ const viewId = this.viewId || viewport.id;
438
+ if (viewManager) {
439
+ try {
440
+ return { ...viewManager.getViewState(viewId) };
441
+ } catch (err) {
442
+ return cloneViewState(viewManager.viewState);
443
+ }
444
+ }
445
+ return cloneViewState(viewport);
446
+ }
447
+ handleZoomDelta(delta) {
448
+ const { minZoom, maxZoom } = this.getZoomBounds();
449
+ for (const viewport of this.getTargetViewports()) {
450
+ const viewState = this.getViewState(viewport);
451
+ const baseZoom = Number(viewState.zoom);
452
+ const current = Number.isFinite(baseZoom) ? baseZoom : this.currentZoom;
453
+ const nextZoom = Math.max(minZoom, Math.min(maxZoom, current + delta));
454
+ this.updateViewState(viewport, { ...viewState, zoom: nextZoom });
455
+ }
456
+ }
457
+ handleZoomTo(zoom) {
458
+ const { minZoom, maxZoom } = this.getZoomBounds();
459
+ const nextZoom = Math.max(minZoom, Math.min(maxZoom, zoom));
460
+ for (const viewport of this.getTargetViewports()) {
461
+ const viewState = this.getViewState(viewport);
462
+ this.updateViewState(viewport, { ...viewState, zoom: nextZoom });
463
+ }
464
+ }
465
+ updateViewState(viewport, viewState) {
466
+ if (!this.deck) {
467
+ return;
468
+ }
469
+ const viewId = this.viewId || viewport.id || "default-view";
470
+ this.currentZoom = Number(viewState.zoom) || this.currentZoom;
471
+ this.updateHTML();
472
+ this.deck._onViewStateChange({ viewId, viewState, interactionState: {} });
473
+ }
474
+ };
475
+ var ZoomRangeWidget = _ZoomRangeWidget;
476
+ __publicField(ZoomRangeWidget, "defaultProps", {
477
+ id: "zoom-range",
478
+ viewId: null,
479
+ placement: "top-left",
480
+ minZoom: void 0,
481
+ maxZoom: void 0,
482
+ step: 0.1,
483
+ style: {},
484
+ className: ""
485
+ });
486
+
487
+ // dist/widgets/html-overlay-widget.js
488
+ var import_jsx_runtime4 = require("preact/jsx-runtime");
489
+ var import_preact4 = require("preact");
490
+ var import_core3 = require("@deck.gl/core");
491
+ var ROOT_STYLE = {
492
+ width: "100%",
493
+ height: "100%",
494
+ position: "absolute",
495
+ pointerEvents: "none",
496
+ overflow: "hidden"
497
+ };
498
+ var _HtmlOverlayWidget = class extends import_core3.Widget {
499
+ placement = "fill";
500
+ className = "deck-widget-html-overlay";
501
+ deck = null;
502
+ viewport = null;
503
+ constructor(props = {}) {
504
+ super({ ..._HtmlOverlayWidget.defaultProps, ...props });
505
+ this.viewId = props.viewId ?? null;
506
+ }
507
+ setProps(props) {
508
+ if (props.viewId !== void 0) {
509
+ this.viewId = props.viewId;
510
+ }
511
+ super.setProps(props);
512
+ }
513
+ onAdd({ deck, viewId }) {
514
+ this.deck = deck;
515
+ if (this.viewId === void 0) {
516
+ this.viewId = viewId;
517
+ }
518
+ }
519
+ onRemove() {
520
+ this.deck = null;
521
+ this.viewport = null;
522
+ }
523
+ onViewportChange(viewport) {
524
+ if (!this.viewId || this.viewId === viewport.id) {
525
+ this.viewport = viewport;
526
+ this.updateHTML();
527
+ }
528
+ }
529
+ getViewport() {
530
+ return this.viewport;
531
+ }
532
+ getZoom() {
533
+ var _a;
534
+ return ((_a = this.viewport) == null ? void 0 : _a.zoom) ?? 0;
535
+ }
536
+ scaleWithZoom(n) {
537
+ return n / Math.pow(2, 20 - this.getZoom());
538
+ }
539
+ breakpointWithZoom(threshold, a, b) {
540
+ return this.getZoom() > threshold ? a : b;
541
+ }
542
+ getCoords(viewport, coordinates) {
543
+ const pos = viewport.project(coordinates);
544
+ if (!pos)
545
+ return [-1, -1];
546
+ return pos;
547
+ }
548
+ inView(viewport, [x, y]) {
549
+ const overflowMargin = this.props.overflowMargin ?? 0;
550
+ const { width, height } = viewport;
551
+ return !(x < -overflowMargin || y < -overflowMargin || x > width + overflowMargin || y > height + overflowMargin);
552
+ }
553
+ getOverlayItems(viewport) {
554
+ const { items } = this.props;
555
+ return items ? (0, import_preact4.toChildArray)(items) : [];
556
+ }
557
+ projectItems(items, viewport) {
558
+ const renderItems = [];
559
+ items.filter(Boolean).forEach((item, index) => {
560
+ var _a;
561
+ const coordinates = (_a = item.props) == null ? void 0 : _a.coordinates;
562
+ if (!coordinates) {
563
+ return;
564
+ }
565
+ const [x, y] = this.getCoords(viewport, coordinates);
566
+ if (this.inView(viewport, [x, y])) {
567
+ const key = item.key === null || item.key === void 0 ? index : item.key;
568
+ renderItems.push((0, import_preact4.cloneElement)(item, { x, y, key }));
569
+ }
570
+ });
571
+ return renderItems;
572
+ }
573
+ onRenderHTML(rootElement) {
574
+ Object.assign(rootElement.style, ROOT_STYLE, { zIndex: `${this.props.zIndex ?? 1}` });
575
+ const viewport = this.getViewport();
576
+ if (!viewport) {
577
+ (0, import_preact4.render)(null, rootElement);
578
+ return;
579
+ }
580
+ const overlayItems = this.getOverlayItems(viewport);
581
+ const renderedItems = this.projectItems(overlayItems, viewport);
582
+ (0, import_preact4.render)((0, import_jsx_runtime4.jsx)(import_preact4.Fragment, { children: renderedItems }), rootElement);
583
+ }
584
+ };
585
+ var HtmlOverlayWidget = _HtmlOverlayWidget;
586
+ __publicField(HtmlOverlayWidget, "defaultProps", {
587
+ id: "html-overlay",
588
+ viewId: null,
589
+ overflowMargin: 0,
590
+ zIndex: 1,
591
+ style: {},
592
+ className: ""
593
+ });
594
+
595
+ // dist/widgets/html-overlay-item.js
596
+ var import_jsx_runtime5 = require("preact/jsx-runtime");
597
+ function HtmlOverlayItem({ x = 0, y = 0, children, style, ...props }) {
598
+ const { zIndex = "auto", ...remainingStyle } = style || {};
599
+ return (
600
+ // Using transform translate to position overlay items will result in a smooth zooming
601
+ // effect, whereas using the top/left css properties will cause overlay items to
602
+ // jiggle when zooming
603
+ (0, import_jsx_runtime5.jsx)("div", { style: { transform: `translate(${x}px, ${y}px)`, position: "absolute", zIndex: `${zIndex}` }, children: (0, import_jsx_runtime5.jsx)("div", { style: { userSelect: "none", ...remainingStyle }, ...props, children }) })
604
+ );
605
+ }
606
+
607
+ // dist/widgets/html-cluster-widget.js
608
+ var import_helpers = require("@turf/helpers");
609
+ var import_supercluster = __toESM(require("supercluster"), 1);
610
+ var HtmlClusterWidget = class extends HtmlOverlayWidget {
611
+ superCluster = null;
612
+ lastObjects = null;
613
+ getOverlayItems(viewport) {
614
+ var _a;
615
+ const newObjects = this.getAllObjects();
616
+ if (newObjects !== this.lastObjects) {
617
+ this.superCluster = new import_supercluster.default(this.getClusterOptions());
618
+ this.superCluster.load(newObjects.map((object) => (0, import_helpers.point)(this.getObjectCoordinates(object), { object })));
619
+ this.lastObjects = newObjects;
620
+ }
621
+ const clusters = ((_a = this.superCluster) == null ? void 0 : _a.getClusters([-180, -90, 180, 90], Math.round(this.getZoom()))) ?? [];
622
+ const overlayItems = clusters.map(({ geometry: { coordinates }, properties: { cluster, point_count: pointCount, cluster_id: clusterId, object } }) => cluster ? this.renderCluster(coordinates, clusterId, pointCount) : this.renderObject(coordinates, object));
623
+ return overlayItems.filter(Boolean);
624
+ }
625
+ getClusterObjects(clusterId) {
626
+ var _a;
627
+ return ((_a = this.superCluster) == null ? void 0 : _a.getLeaves(clusterId, Infinity).map((leaf) => leaf.properties.object)) ?? [];
628
+ }
629
+ // Get options object used when instantiating supercluster
630
+ getClusterOptions() {
631
+ return {
632
+ maxZoom: 20
633
+ };
634
+ }
635
+ };
636
+ __publicField(HtmlClusterWidget, "defaultProps", {
637
+ ...HtmlOverlayWidget.defaultProps,
638
+ id: "html-cluster-overlay"
639
+ });
640
+
641
+ // dist/widgets/html-tooltip-widget.js
642
+ var import_jsx_runtime6 = require("preact/jsx-runtime");
643
+ var TOOLTIP_STYLE = {
644
+ transform: "translate(-50%,-100%)",
645
+ backgroundColor: "rgba(0, 0, 0, 0.3)",
646
+ padding: "4px 8px",
647
+ borderRadius: 8,
648
+ color: "white"
649
+ };
650
+ var SHOW_TOOLTIP_TIMEOUT = 250;
651
+ function defaultGetTooltip(pickingInfo) {
652
+ var _a, _b;
653
+ return (_b = (_a = pickingInfo.object) == null ? void 0 : _a.style) == null ? void 0 : _b.tooltip;
654
+ }
655
+ var HtmlTooltipWidget = class extends HtmlOverlayWidget {
656
+ timeoutID = null;
657
+ pickingInfo = null;
658
+ visible = false;
659
+ onRemove() {
660
+ if (this.timeoutID !== null) {
661
+ globalThis.clearTimeout(this.timeoutID);
662
+ this.timeoutID = null;
663
+ }
664
+ this.visible = false;
665
+ this.pickingInfo = null;
666
+ }
667
+ onHover(pickingInfo) {
668
+ var _a, _b;
669
+ if (this.timeoutID !== null) {
670
+ globalThis.clearTimeout(this.timeoutID);
671
+ this.timeoutID = null;
672
+ }
673
+ const tooltipContent = (_b = (_a = this.props).getTooltip) == null ? void 0 : _b.call(_a, pickingInfo);
674
+ if (pickingInfo && tooltipContent) {
675
+ const delay = this.props.showDelay ?? SHOW_TOOLTIP_TIMEOUT;
676
+ this.timeoutID = globalThis.setTimeout(() => {
677
+ this.visible = true;
678
+ this.pickingInfo = pickingInfo;
679
+ this.updateHTML();
680
+ }, delay);
681
+ } else {
682
+ this.visible = false;
683
+ this.pickingInfo = null;
684
+ this.updateHTML();
685
+ }
686
+ }
687
+ getOverlayItems(viewport) {
688
+ var _a, _b;
689
+ if (!this.visible || !this.pickingInfo) {
690
+ return [];
691
+ }
692
+ const tooltipContent = (_b = (_a = this.props).getTooltip) == null ? void 0 : _b.call(_a, this.pickingInfo);
693
+ const coordinates = this.pickingInfo.coordinate ?? this.pickingInfo.lngLat ?? null;
694
+ if (!tooltipContent || !coordinates) {
695
+ return [];
696
+ }
697
+ return [
698
+ (0, import_jsx_runtime6.jsx)(HtmlOverlayItem, { coordinates, style: TOOLTIP_STYLE, children: tooltipContent }, "tooltip")
699
+ ];
700
+ }
701
+ };
702
+ __publicField(HtmlTooltipWidget, "defaultProps", {
703
+ ...HtmlOverlayWidget.defaultProps,
704
+ id: "html-tooltip-overlay",
705
+ showDelay: SHOW_TOOLTIP_TIMEOUT,
706
+ getTooltip: defaultGetTooltip
707
+ });
708
+ //# sourceMappingURL=index.cjs.map