@guardian/interactive-component-library 0.5.7 → 0.7.0
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/components/molecules/canvas-map/controls/ZoomControl.d.ts +14 -5
- package/dist/components/molecules/canvas-map/controls/ZoomControl.js +8 -1
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +9 -2
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +16 -1
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +3 -3
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +14 -9
- package/package.json +1 -1
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} props
|
|
3
|
+
* @param {boolean} props.resetEnabled
|
|
4
|
+
* @param {boolean} props.resetVisible
|
|
5
|
+
* @param {(event: MouseEvent) => {}} props.onZoomIn
|
|
6
|
+
* @param {(event: MouseEvent) => {}} props.onZoomOut
|
|
7
|
+
* @param {(event: MouseEvent) => {}} props.onReset
|
|
8
|
+
*/
|
|
9
|
+
export function ZoomControl({ resetEnabled, resetVisible, onZoomIn, onZoomOut, onReset, }: {
|
|
10
|
+
resetEnabled: boolean;
|
|
11
|
+
resetVisible: boolean;
|
|
12
|
+
onZoomIn: (event: MouseEvent) => {};
|
|
13
|
+
onZoomOut: (event: MouseEvent) => {};
|
|
14
|
+
onReset: (event: MouseEvent) => {};
|
|
6
15
|
}): import("preact").JSX.Element;
|
|
@@ -3,7 +3,13 @@ import { IconMinus } from "./icons/minus.js";
|
|
|
3
3
|
import { IconPlus } from "./icons/plus.js";
|
|
4
4
|
import { IconReset } from "./icons/reset.js";
|
|
5
5
|
import styles from "./style.module.css.js";
|
|
6
|
-
function ZoomControl({
|
|
6
|
+
function ZoomControl({
|
|
7
|
+
resetEnabled,
|
|
8
|
+
resetVisible,
|
|
9
|
+
onZoomIn,
|
|
10
|
+
onZoomOut,
|
|
11
|
+
onReset
|
|
12
|
+
}) {
|
|
7
13
|
const _onZoomIn = (event) => {
|
|
8
14
|
event.stopPropagation();
|
|
9
15
|
onZoomIn(event);
|
|
@@ -23,6 +29,7 @@ function ZoomControl({ resetEnabled, onZoomIn, onZoomOut, onReset }) {
|
|
|
23
29
|
"button",
|
|
24
30
|
{
|
|
25
31
|
className: styles.button,
|
|
32
|
+
style: { display: resetVisible ? "block" : "none" },
|
|
26
33
|
onClick: _onReset,
|
|
27
34
|
disabled: !resetEnabled,
|
|
28
35
|
children: /* @__PURE__ */ jsx(
|
|
@@ -18,6 +18,7 @@ export class TextLayer {
|
|
|
18
18
|
* @param {number} [params.minZoom=0]
|
|
19
19
|
* @param {number} [params.opacity=1]
|
|
20
20
|
* @param {boolean} [params.declutter=true]
|
|
21
|
+
* @param {number} [params.declutterBoundingBoxPadding=2] Padding added to the bounding box around the TextLayer, that's used to detect collisions for decluttering.
|
|
21
22
|
* @param {boolean} [params.drawCollisionBoxes=false]
|
|
22
23
|
* @param {(feature: import('../Feature').Feature, event: MouseEvent) => void} [params.onClick]
|
|
23
24
|
* @param {(feature: import('../Feature').Feature, event: MouseEvent) => (() => void) | void} [params.onHover]
|
|
@@ -29,12 +30,13 @@ export class TextLayer {
|
|
|
29
30
|
*
|
|
30
31
|
* The provided style function will be called with the `isHovering` parameter set to `true` for the hovered feature.
|
|
31
32
|
*/
|
|
32
|
-
constructor({ source, style, minZoom, opacity, declutter, drawCollisionBoxes, onClick, onHover, restyleOnHover, }: {
|
|
33
|
+
constructor({ source, style, minZoom, opacity, declutter, declutterBoundingBoxPadding, drawCollisionBoxes, onClick, onHover, restyleOnHover, }: {
|
|
33
34
|
source: VectorSource;
|
|
34
35
|
style?: Style | (() => Style);
|
|
35
36
|
minZoom?: number;
|
|
36
37
|
opacity?: number;
|
|
37
38
|
declutter?: boolean;
|
|
39
|
+
declutterBoundingBoxPadding?: number;
|
|
38
40
|
drawCollisionBoxes?: boolean;
|
|
39
41
|
onClick?: (feature: import('../Feature').Feature, event: MouseEvent) => void;
|
|
40
42
|
onHover?: (feature: import('../Feature').Feature, event: MouseEvent) => (() => void) | void;
|
|
@@ -69,6 +71,11 @@ export class TextLayer {
|
|
|
69
71
|
* @public
|
|
70
72
|
*/
|
|
71
73
|
public drawCollisionBoxes: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* @type {number}
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
public declutterBoundingBoxPadding: number;
|
|
72
79
|
onClick: (feature: import('../Feature').Feature, event: MouseEvent) => void;
|
|
73
80
|
onHover: (feature: import('../Feature').Feature, event: MouseEvent) => (() => void) | void;
|
|
74
81
|
restyleOnHover: boolean;
|
|
@@ -95,7 +102,7 @@ export class TextLayer {
|
|
|
95
102
|
}
|
|
96
103
|
export namespace TextLayer {
|
|
97
104
|
/** @param {TextLayerComponentProps} props */
|
|
98
|
-
function Component({ features: featureCollection, style, minZoom, opacity, declutter, drawCollisionBoxes, onClick, onHover, restyleOnHover, }: TextLayerComponentProps): any;
|
|
105
|
+
function Component({ features: featureCollection, style, minZoom, opacity, declutter, declutterBoundingBoxPadding, drawCollisionBoxes, onClick, onHover, restyleOnHover, }: TextLayerComponentProps): any;
|
|
99
106
|
namespace Component {
|
|
100
107
|
let displayName: string;
|
|
101
108
|
}
|
|
@@ -16,6 +16,7 @@ class TextLayer {
|
|
|
16
16
|
minZoom,
|
|
17
17
|
opacity,
|
|
18
18
|
declutter,
|
|
19
|
+
declutterBoundingBoxPadding,
|
|
19
20
|
drawCollisionBoxes,
|
|
20
21
|
onClick,
|
|
21
22
|
onHover,
|
|
@@ -33,6 +34,7 @@ class TextLayer {
|
|
|
33
34
|
minZoom,
|
|
34
35
|
opacity,
|
|
35
36
|
declutter,
|
|
37
|
+
declutterBoundingBoxPadding,
|
|
36
38
|
drawCollisionBoxes,
|
|
37
39
|
onClick,
|
|
38
40
|
onHover,
|
|
@@ -40,7 +42,17 @@ class TextLayer {
|
|
|
40
42
|
});
|
|
41
43
|
},
|
|
42
44
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
-
[
|
|
45
|
+
[
|
|
46
|
+
featureCollection,
|
|
47
|
+
minZoom,
|
|
48
|
+
opacity,
|
|
49
|
+
declutter,
|
|
50
|
+
declutterBoundingBoxPadding,
|
|
51
|
+
drawCollisionBoxes,
|
|
52
|
+
onClick,
|
|
53
|
+
onHover,
|
|
54
|
+
restyleOnHover
|
|
55
|
+
]
|
|
44
56
|
);
|
|
45
57
|
useEffect(() => {
|
|
46
58
|
registerLayer(layer, this);
|
|
@@ -69,6 +81,7 @@ class TextLayer {
|
|
|
69
81
|
* @param {number} [params.minZoom=0]
|
|
70
82
|
* @param {number} [params.opacity=1]
|
|
71
83
|
* @param {boolean} [params.declutter=true]
|
|
84
|
+
* @param {number} [params.declutterBoundingBoxPadding=2] Padding added to the bounding box around the TextLayer, that's used to detect collisions for decluttering.
|
|
72
85
|
* @param {boolean} [params.drawCollisionBoxes=false]
|
|
73
86
|
* @param {(feature: import('../Feature').Feature, event: MouseEvent) => void} [params.onClick]
|
|
74
87
|
* @param {(feature: import('../Feature').Feature, event: MouseEvent) => (() => void) | void} [params.onHover]
|
|
@@ -86,6 +99,7 @@ class TextLayer {
|
|
|
86
99
|
minZoom = 0,
|
|
87
100
|
opacity = 1,
|
|
88
101
|
declutter = true,
|
|
102
|
+
declutterBoundingBoxPadding = 2,
|
|
89
103
|
drawCollisionBoxes = false,
|
|
90
104
|
onClick,
|
|
91
105
|
onHover,
|
|
@@ -97,6 +111,7 @@ class TextLayer {
|
|
|
97
111
|
this.opacity = opacity;
|
|
98
112
|
this.declutter = declutter;
|
|
99
113
|
this.drawCollisionBoxes = drawCollisionBoxes;
|
|
114
|
+
this.declutterBoundingBoxPadding = declutterBoundingBoxPadding;
|
|
100
115
|
this.onClick = onClick;
|
|
101
116
|
this.onHover = onHover;
|
|
102
117
|
this.restyleOnHover = restyleOnHover;
|
|
@@ -43,11 +43,11 @@ export class TextLayerRenderer {
|
|
|
43
43
|
}, textStyle: import('../styles/Text').Text, position: {
|
|
44
44
|
x: number;
|
|
45
45
|
y: number;
|
|
46
|
-
}): {
|
|
46
|
+
}, padding: any): {
|
|
47
47
|
minX: number;
|
|
48
48
|
minY: number;
|
|
49
|
-
maxX:
|
|
50
|
-
maxY:
|
|
49
|
+
maxX: any;
|
|
50
|
+
maxY: any;
|
|
51
51
|
};
|
|
52
52
|
getCollisionBoxElement(bbox: any): HTMLDivElement;
|
|
53
53
|
/**
|
|
@@ -67,10 +67,15 @@ class TextLayerRenderer {
|
|
|
67
67
|
featureStyle.text,
|
|
68
68
|
position
|
|
69
69
|
);
|
|
70
|
-
const bbox = this.getElementBBox(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const bbox = this.getElementBBox(
|
|
71
|
+
elementDimens,
|
|
72
|
+
featureStyle.text,
|
|
73
|
+
{
|
|
74
|
+
x: relativeX * viewPortSize[0],
|
|
75
|
+
y: relativeY * viewPortSize[1]
|
|
76
|
+
},
|
|
77
|
+
this.layer.declutterBoundingBoxPadding
|
|
78
|
+
);
|
|
74
79
|
if (declutterTree) {
|
|
75
80
|
if (declutterTree.collides(bbox)) {
|
|
76
81
|
continue;
|
|
@@ -187,12 +192,12 @@ class TextLayerRenderer {
|
|
|
187
192
|
* @param {import("../styles/Text").Text} textStyle
|
|
188
193
|
* @param {{x: number, y: number}} position
|
|
189
194
|
*/
|
|
190
|
-
getElementBBox(dimens, textStyle, position) {
|
|
195
|
+
getElementBBox(dimens, textStyle, position, padding) {
|
|
191
196
|
const collisionPadding = {
|
|
192
|
-
top:
|
|
193
|
-
right:
|
|
194
|
-
bottom:
|
|
195
|
-
left:
|
|
197
|
+
top: padding,
|
|
198
|
+
right: padding,
|
|
199
|
+
bottom: padding,
|
|
200
|
+
left: padding
|
|
196
201
|
};
|
|
197
202
|
const { x: translateX, y: translateY } = textStyle.getTranslation(
|
|
198
203
|
dimens.width,
|