@guardian/interactive-component-library 0.5.0 → 0.5.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.
|
@@ -9,7 +9,8 @@ const Component = ({
|
|
|
9
9
|
inModalState = false,
|
|
10
10
|
onLoad,
|
|
11
11
|
children,
|
|
12
|
-
mapRef
|
|
12
|
+
mapRef,
|
|
13
|
+
allowZoomPan = true
|
|
13
14
|
}) => {
|
|
14
15
|
const targetRef = useRef();
|
|
15
16
|
const [map, setMap] = useState(
|
|
@@ -21,11 +22,12 @@ const Component = ({
|
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
var _a;
|
|
23
24
|
if (!targetRef.current) return;
|
|
25
|
+
config.allowZoomPan = allowZoomPan;
|
|
24
26
|
const map2 = new Map({
|
|
25
27
|
...config,
|
|
26
28
|
target: targetRef.current
|
|
27
29
|
});
|
|
28
|
-
map2.collaborativeGesturesEnabled(true);
|
|
30
|
+
if (allowZoomPan) map2.collaborativeGesturesEnabled(true);
|
|
29
31
|
setMap(map2);
|
|
30
32
|
if (mapRef) {
|
|
31
33
|
mapRef.current = map2;
|
|
@@ -50,9 +52,9 @@ const Component = ({
|
|
|
50
52
|
mapRef.current = null;
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
|
-
}, [config, onLoad, mapRef]);
|
|
55
|
+
}, [config, onLoad, mapRef, allowZoomPan]);
|
|
54
56
|
useEffect(() => {
|
|
55
|
-
if (!map) return;
|
|
57
|
+
if (!map || !allowZoomPan) return;
|
|
56
58
|
let timeoutID;
|
|
57
59
|
map.onFilterEvent((showHelpText2) => {
|
|
58
60
|
if (timeoutID) clearTimeout(timeoutID);
|
|
@@ -66,13 +68,13 @@ const Component = ({
|
|
|
66
68
|
return () => {
|
|
67
69
|
if (timeoutID) clearTimeout(timeoutID);
|
|
68
70
|
};
|
|
69
|
-
}, [map]);
|
|
71
|
+
}, [map, allowZoomPan]);
|
|
70
72
|
useEffect(() => {
|
|
71
|
-
if (!map) return;
|
|
73
|
+
if (!map || !allowZoomPan) return;
|
|
72
74
|
map.collaborativeGesturesEnabled(!inModalState);
|
|
73
|
-
}, [map, inModalState]);
|
|
75
|
+
}, [map, inModalState, allowZoomPan]);
|
|
74
76
|
return /* @__PURE__ */ jsxs("figure", { ref: targetRef, className: styles.mapContainer, children: [
|
|
75
|
-
/* @__PURE__ */ jsxs(
|
|
77
|
+
allowZoomPan && /* @__PURE__ */ jsxs(
|
|
76
78
|
"div",
|
|
77
79
|
{
|
|
78
80
|
className: styles.helpTextContainer,
|
|
@@ -11,16 +11,20 @@ export class Map {
|
|
|
11
11
|
* @param {Object} config - The configuration for the map.
|
|
12
12
|
* @param {Object} config.view - The view configuration for the map.
|
|
13
13
|
* @param {boolean} config.debug - Whether to enable debug mode or not.
|
|
14
|
+
* @param {boolean} config.allowZoomPan - Whether to enable zoom and pan functionality or not.
|
|
14
15
|
* @param {HTMLElement} config.target - The target element to render the map into.
|
|
15
16
|
*/
|
|
16
17
|
constructor(config: {
|
|
17
18
|
view: any;
|
|
18
19
|
debug: boolean;
|
|
20
|
+
allowZoomPan: boolean;
|
|
19
21
|
target: HTMLElement;
|
|
20
22
|
});
|
|
23
|
+
allowZoomPan: boolean;
|
|
21
24
|
options: {
|
|
22
25
|
view: any;
|
|
23
26
|
debug: boolean;
|
|
27
|
+
allowZoomPan: boolean;
|
|
24
28
|
target: HTMLElement;
|
|
25
29
|
};
|
|
26
30
|
view: View;
|
|
@@ -15,12 +15,14 @@ class Map {
|
|
|
15
15
|
* @param {Object} config - The configuration for the map.
|
|
16
16
|
* @param {Object} config.view - The view configuration for the map.
|
|
17
17
|
* @param {boolean} config.debug - Whether to enable debug mode or not.
|
|
18
|
+
* @param {boolean} config.allowZoomPan - Whether to enable zoom and pan functionality or not.
|
|
18
19
|
* @param {HTMLElement} config.target - The target element to render the map into.
|
|
19
20
|
*/
|
|
20
21
|
constructor(config) {
|
|
21
22
|
if (config.debug) {
|
|
22
23
|
console.log("Map config", config);
|
|
23
24
|
}
|
|
25
|
+
this.allowZoomPan = config.allowZoomPan;
|
|
24
26
|
this.options = config;
|
|
25
27
|
this.view = new View(config.view, config.debug);
|
|
26
28
|
this.target = config.target;
|
|
@@ -236,6 +238,9 @@ class Map {
|
|
|
236
238
|
}
|
|
237
239
|
return (!event.ctrlKey || event.type === "wheel") && !event.button;
|
|
238
240
|
}).on("zoom", (event) => {
|
|
241
|
+
if (!this.allowZoomPan) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
239
244
|
this.view.transform = event.transform;
|
|
240
245
|
this._requestRender();
|
|
241
246
|
this.dispatcher.dispatch(MapEvent.ZOOM, {
|