@deck.gl-community/react 9.0.1
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/README.md +3 -0
- package/dist/components/icon.d.ts +3 -0
- package/dist/components/icon.js +6 -0
- package/dist/components/long-press-button.d.ts +13 -0
- package/dist/components/long-press-button.js +31 -0
- package/dist/components/modal.d.ts +8 -0
- package/dist/components/modal.js +70 -0
- package/dist/components/positioned-view-control.d.ts +9 -0
- package/dist/components/positioned-view-control.js +5 -0
- package/dist/components/view-control.d.ts +38 -0
- package/dist/components/view-control.js +128 -0
- package/dist/index.cjs +521 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +13 -0
- package/dist/overlays/html-cluster-overlay.d.ts +13 -0
- package/dist/overlays/html-cluster-overlay.js +53 -0
- package/dist/overlays/html-overlay-item.d.ts +12 -0
- package/dist/overlays/html-overlay-item.js +13 -0
- package/dist/overlays/html-overlay.d.ts +19 -0
- package/dist/overlays/html-overlay.js +65 -0
- package/dist/overlays/html-tooltip-overlay.d.ts +16 -0
- package/dist/overlays/html-tooltip-overlay.js +53 -0
- package/package.json +50 -0
- package/src/components/icon.tsx +7 -0
- package/src/components/long-press-button.tsx +43 -0
- package/src/components/modal.tsx +92 -0
- package/src/components/positioned-view-control.tsx +16 -0
- package/src/components/view-control.tsx +163 -0
- package/src/index.ts +19 -0
- package/src/overlays/html-cluster-overlay.ts +80 -0
- package/src/overlays/html-overlay-item.tsx +30 -0
- package/src/overlays/html-overlay.tsx +91 -0
- package/src/overlays/html-tooltip-overlay.tsx +74 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
const styles = {
|
|
4
|
+
mainContainer: {
|
|
5
|
+
width: '100%',
|
|
6
|
+
height: '100%',
|
|
7
|
+
position: 'absolute',
|
|
8
|
+
pointerEvents: 'none',
|
|
9
|
+
overflow: 'hidden'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
viewport?: Record<string, any>;
|
|
15
|
+
zIndex?: number;
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
// Overlay items abruptly disappear when their anchor point passes the edge of the map, which is
|
|
18
|
+
// visible to the user. The overflowMargin prop is used to effectively create a hidden buffer
|
|
19
|
+
// zone that extends from all sides of the map while leaving the visible edge of the map
|
|
20
|
+
// unchanged. With this, overlay items can move into the buffer zone and disappear only when
|
|
21
|
+
// their anchor passes the edge of the buffer zone. This produces a perceived effect of overlay
|
|
22
|
+
// items being rendered as part of the map, instead of separate entities tacked on to the map.
|
|
23
|
+
overflowMargin?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class HtmlOverlay extends React.Component<Props> {
|
|
27
|
+
// This is needed for Deck.gl 8.0+
|
|
28
|
+
static deckGLViewProps = true;
|
|
29
|
+
|
|
30
|
+
// Override this to provide your items
|
|
31
|
+
getItems(): Array<any> {
|
|
32
|
+
const {children} = this.props;
|
|
33
|
+
if (children) {
|
|
34
|
+
return Array.isArray(children) ? children : [children];
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCoords(coordinates: number[]): [number, number] {
|
|
40
|
+
const pos = this.props.viewport.project(coordinates);
|
|
41
|
+
if (!pos) return [-1, -1];
|
|
42
|
+
return pos;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
inView([x, y]: number[]): boolean {
|
|
46
|
+
const {viewport, overflowMargin = 0} = this.props;
|
|
47
|
+
const {width, height} = viewport;
|
|
48
|
+
return !(
|
|
49
|
+
x < -overflowMargin ||
|
|
50
|
+
y < -overflowMargin ||
|
|
51
|
+
x > width + overflowMargin ||
|
|
52
|
+
y > height + overflowMargin
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
scaleWithZoom(n: number) {
|
|
57
|
+
const {zoom} = this.props.viewport;
|
|
58
|
+
return n / Math.pow(2, 20 - zoom);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
breakpointWithZoom(threshold: number, a: any, b: any): any {
|
|
62
|
+
const {zoom} = this.props.viewport;
|
|
63
|
+
return zoom > threshold ? a : b;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getViewport() {
|
|
67
|
+
return this.props.viewport;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getZoom() {
|
|
71
|
+
return this.props.viewport.zoom;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
render() {
|
|
75
|
+
const {zIndex = 1} = this.props;
|
|
76
|
+
const style = Object.assign({zIndex} as any, styles.mainContainer);
|
|
77
|
+
|
|
78
|
+
const renderItems = [];
|
|
79
|
+
this.getItems()
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.forEach((item, index) => {
|
|
82
|
+
const [x, y] = this.getCoords(item.props.coordinates);
|
|
83
|
+
if (this.inView([x, y])) {
|
|
84
|
+
const key = item.key === null || item.key === undefined ? index : item.key;
|
|
85
|
+
renderItems.push(React.cloneElement(item, {x, y, key}));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return <div style={style}>{renderItems}</div>;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import {HtmlOverlay} from './html-overlay';
|
|
4
|
+
import {HtmlOverlayItem} from './html-overlay-item';
|
|
5
|
+
|
|
6
|
+
type State = {
|
|
7
|
+
visible: boolean;
|
|
8
|
+
pickingInfo: Record<string, any> | null | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const styles = {
|
|
12
|
+
tooltip: {
|
|
13
|
+
transform: 'translate(-50%,-100%)',
|
|
14
|
+
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
|
15
|
+
padding: '4px 8px',
|
|
16
|
+
borderRadius: 8,
|
|
17
|
+
color: 'white'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const SHOW_TOOLTIP_TIMEOUT = 250;
|
|
22
|
+
|
|
23
|
+
export class HtmlTooltipOverlay extends HtmlOverlay {
|
|
24
|
+
constructor(props: any) {
|
|
25
|
+
super(props);
|
|
26
|
+
this.state = {visible: false, pickingInfo: null};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
componentWillMount() {
|
|
30
|
+
(this.context as any).nebula.queryObjectEvents.on('pick', ({event, pickingInfo}) => {
|
|
31
|
+
if (this.timeoutID !== null) {
|
|
32
|
+
window.clearTimeout(this.timeoutID);
|
|
33
|
+
}
|
|
34
|
+
this.timeoutID = null;
|
|
35
|
+
|
|
36
|
+
if (pickingInfo && this._getTooltip(pickingInfo)) {
|
|
37
|
+
this.timeoutID = window.setTimeout(() => {
|
|
38
|
+
this.setState({visible: true, pickingInfo});
|
|
39
|
+
}, SHOW_TOOLTIP_TIMEOUT);
|
|
40
|
+
} else {
|
|
41
|
+
this.setState({visible: false});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
timeoutID: number | null | undefined = null;
|
|
47
|
+
state: State = undefined!;
|
|
48
|
+
|
|
49
|
+
_getTooltip(pickingInfo: Record<string, any>): string {
|
|
50
|
+
return pickingInfo.object.style.tooltip;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_makeOverlay() {
|
|
54
|
+
const {pickingInfo} = this.state;
|
|
55
|
+
|
|
56
|
+
if (pickingInfo) {
|
|
57
|
+
return (
|
|
58
|
+
<HtmlOverlayItem key={0} coordinates={pickingInfo.lngLat} style={styles.tooltip}>
|
|
59
|
+
{this._getTooltip(pickingInfo)}
|
|
60
|
+
</HtmlOverlayItem>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getItems(): Array<Record<string, any> | null | undefined> {
|
|
68
|
+
if (this.state.visible) {
|
|
69
|
+
return [this._makeOverlay()];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|