@guardian/interactive-component-library 0.2.0 → 0.3.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.
|
@@ -3658,9 +3658,33 @@
|
|
|
3658
3658
|
this.maxX = maxX;
|
|
3659
3659
|
this.maxY = maxY;
|
|
3660
3660
|
}
|
|
3661
|
+
get width() {
|
|
3662
|
+
return this.maxX - this.minX;
|
|
3663
|
+
}
|
|
3664
|
+
get height() {
|
|
3665
|
+
return this.maxY - this.minY;
|
|
3666
|
+
}
|
|
3667
|
+
/**
|
|
3668
|
+
* Turn extent into a flat array of numbers: [minX, minY, maxX, maxY].
|
|
3669
|
+
*
|
|
3670
|
+
* @returns {[number, number, number, number]} - The extent as a flat array
|
|
3671
|
+
*/
|
|
3661
3672
|
flat() {
|
|
3662
3673
|
return [this.minX, this.minY, this.maxX, this.maxY];
|
|
3663
3674
|
}
|
|
3675
|
+
/**
|
|
3676
|
+
* Create a new extent where the coordinates are multiplied by scaleFactor.
|
|
3677
|
+
*
|
|
3678
|
+
* @param {number} scaleFactor
|
|
3679
|
+
* @returns {Extent} - The scaled
|
|
3680
|
+
*/
|
|
3681
|
+
scale(scaleFactor) {
|
|
3682
|
+
const scaled = (
|
|
3683
|
+
/** @type {ExtentLike} */
|
|
3684
|
+
[this.minX, this.minY, this.maxX, this.maxY].map((d2) => d2 * scaleFactor)
|
|
3685
|
+
);
|
|
3686
|
+
return Extent.convert(scaled);
|
|
3687
|
+
}
|
|
3664
3688
|
/**
|
|
3665
3689
|
* Check if the passed coordinate is contained or on the edge of the extent.
|
|
3666
3690
|
*
|
|
@@ -3923,7 +3947,10 @@
|
|
|
3923
3947
|
const baseResolution = resolutionForExtent(baseExtent, this.viewPortSize);
|
|
3924
3948
|
return baseResolution;
|
|
3925
3949
|
}
|
|
3926
|
-
|
|
3950
|
+
/**
|
|
3951
|
+
* Get the lower and upper zoom scales
|
|
3952
|
+
* @returns {[number, number]} - The lower and upper zoom scales
|
|
3953
|
+
*/
|
|
3927
3954
|
get scaleExtent() {
|
|
3928
3955
|
const maxScale = zoomLevelToZoomScale(this.maxZoom, this.baseResolution);
|
|
3929
3956
|
return [1, maxScale];
|
|
@@ -3954,27 +3981,22 @@
|
|
|
3954
3981
|
}
|
|
3955
3982
|
}
|
|
3956
3983
|
/**
|
|
3957
|
-
*
|
|
3958
3984
|
* @param {import("./formats/GeoJSON").GeoJSONFeature} geoJSON
|
|
3959
3985
|
*/
|
|
3960
3986
|
fitObject(geoJSON) {
|
|
3961
3987
|
this.projection.fitExtent(this.getMapExtent(), geoJSON);
|
|
3962
3988
|
++this.projection.revision;
|
|
3963
3989
|
}
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
const
|
|
3972
|
-
const
|
|
3973
|
-
|
|
3974
|
-
return [
|
|
3975
|
-
[minX, minY],
|
|
3976
|
-
[width, height]
|
|
3977
|
-
];
|
|
3990
|
+
/**
|
|
3991
|
+
* Returns extent in projection coordinates
|
|
3992
|
+
*
|
|
3993
|
+
* @param {Extent} extent
|
|
3994
|
+
* @returns {Extent} - The extent relative to the current viewport
|
|
3995
|
+
*/
|
|
3996
|
+
projectExtent(extent) {
|
|
3997
|
+
const [minX, minY] = this.projection([extent.minX, extent.minY]);
|
|
3998
|
+
const [maxX, maxY] = this.projection([extent.maxX, extent.maxY]);
|
|
3999
|
+
return new Extent(minX, minY, maxX, maxY).scale(1 / this.pixelRatio);
|
|
3978
4000
|
}
|
|
3979
4001
|
invert(point) {
|
|
3980
4002
|
const { projection, pixelRatio, transform } = this.getState();
|
|
@@ -6009,7 +6031,12 @@
|
|
|
6009
6031
|
}
|
|
6010
6032
|
zoomToFeature(feature, focalPoint, padding = { top: 40, right: 40, bottom: 40, left: 40 }) {
|
|
6011
6033
|
const extent = feature.getExtent();
|
|
6012
|
-
const
|
|
6034
|
+
const {
|
|
6035
|
+
minX: featureX,
|
|
6036
|
+
minY: featureY,
|
|
6037
|
+
width: featureWidth,
|
|
6038
|
+
height: featureHeight
|
|
6039
|
+
} = this.view.projectExtent(extent);
|
|
6013
6040
|
const [viewPortWidth, viewPortHeight] = this.view.viewPortSize;
|
|
6014
6041
|
const paddedViewPortWidth = viewPortWidth - padding.left - padding.right;
|
|
6015
6042
|
const paddedViewPortHeight = viewPortHeight - padding.top - padding.bottom;
|
|
@@ -6472,7 +6499,12 @@
|
|
|
6472
6499
|
class Point extends Geometry {
|
|
6473
6500
|
constructor({ type = "Point", coordinates }) {
|
|
6474
6501
|
super({ type, extent: null, coordinates });
|
|
6475
|
-
this.extent =
|
|
6502
|
+
this.extent = new Extent(
|
|
6503
|
+
coordinates[0],
|
|
6504
|
+
coordinates[1],
|
|
6505
|
+
coordinates[0],
|
|
6506
|
+
coordinates[1]
|
|
6507
|
+
);
|
|
6476
6508
|
}
|
|
6477
6509
|
_getProjected(projection) {
|
|
6478
6510
|
return {
|
|
@@ -7625,90 +7657,90 @@
|
|
|
7625
7657
|
mobileHelpText: mobileHelpText$1
|
|
7626
7658
|
};
|
|
7627
7659
|
const mobileHelpText = "Use two fingers to zoom";
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7660
|
+
const Component = ({
|
|
7661
|
+
config,
|
|
7662
|
+
inModalState = false,
|
|
7663
|
+
onLoad,
|
|
7664
|
+
children,
|
|
7665
|
+
mapRef
|
|
7666
|
+
}) => {
|
|
7667
|
+
const targetRef = hooks.useRef();
|
|
7668
|
+
const [map, setMap] = hooks.useState(
|
|
7669
|
+
/** @type {Map | null} */
|
|
7670
|
+
null
|
|
7671
|
+
);
|
|
7672
|
+
const [zoomHelpText, setZoomHelpText] = hooks.useState("");
|
|
7673
|
+
const [showHelpText, setShowHelpText] = hooks.useState(false);
|
|
7674
|
+
hooks.useEffect(() => {
|
|
7675
|
+
var _a;
|
|
7676
|
+
if (!targetRef.current) return;
|
|
7677
|
+
const map2 = new Map$1({
|
|
7678
|
+
...config,
|
|
7679
|
+
target: targetRef.current
|
|
7680
|
+
});
|
|
7681
|
+
map2.collaborativeGesturesEnabled(true);
|
|
7682
|
+
setMap(map2);
|
|
7683
|
+
if (mapRef) {
|
|
7684
|
+
mapRef.current = map2;
|
|
7685
|
+
}
|
|
7686
|
+
if (onLoad) {
|
|
7687
|
+
onLoad(map2);
|
|
7688
|
+
}
|
|
7689
|
+
let zoomHelpText2 = "";
|
|
7690
|
+
if (
|
|
7691
|
+
// @ts-ignore
|
|
7692
|
+
((_a = navigator.userAgentData) == null ? void 0 : _a.mobile) || navigator.userAgent.indexOf("Mobile") !== -1
|
|
7693
|
+
) {
|
|
7694
|
+
zoomHelpText2 = mobileHelpText;
|
|
7695
|
+
} else {
|
|
7696
|
+
zoomHelpText2 = navigator.userAgent.indexOf("Mac") !== -1 ? "Use ⌘ + scroll to zoom" : "Use Ctrl + scroll to zoom";
|
|
7697
|
+
}
|
|
7698
|
+
setZoomHelpText(zoomHelpText2);
|
|
7699
|
+
return () => {
|
|
7700
|
+
map2.destroy();
|
|
7701
|
+
setMap(null);
|
|
7702
|
+
if (mapRef) {
|
|
7703
|
+
mapRef.current = null;
|
|
7653
7704
|
}
|
|
7654
|
-
|
|
7655
|
-
|
|
7705
|
+
};
|
|
7706
|
+
}, [config, onLoad, mapRef]);
|
|
7707
|
+
hooks.useEffect(() => {
|
|
7708
|
+
if (!map) return;
|
|
7709
|
+
let timeoutID;
|
|
7710
|
+
map.onFilterEvent((showHelpText2) => {
|
|
7711
|
+
if (timeoutID) clearTimeout(timeoutID);
|
|
7712
|
+
setShowHelpText(showHelpText2);
|
|
7713
|
+
if (showHelpText2) {
|
|
7714
|
+
timeoutID = setTimeout(() => {
|
|
7715
|
+
setShowHelpText(false);
|
|
7716
|
+
}, 1e3);
|
|
7656
7717
|
}
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7718
|
+
});
|
|
7719
|
+
return () => {
|
|
7720
|
+
if (timeoutID) clearTimeout(timeoutID);
|
|
7721
|
+
};
|
|
7722
|
+
}, [map]);
|
|
7723
|
+
hooks.useEffect(() => {
|
|
7724
|
+
if (!map) return;
|
|
7725
|
+
map.collaborativeGesturesEnabled(!inModalState);
|
|
7726
|
+
}, [map, inModalState]);
|
|
7727
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("figure", { ref: targetRef, className: styles$2.mapContainer, children: [
|
|
7728
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7729
|
+
"div",
|
|
7730
|
+
{
|
|
7731
|
+
className: styles$2.helpTextContainer,
|
|
7732
|
+
style: { opacity: showHelpText ? 1 : 0 },
|
|
7733
|
+
"aria-hidden": true,
|
|
7734
|
+
children: [
|
|
7735
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: [styles$2.helpText, styles$2.desktopHelpText].join(" "), children: zoomHelpText }),
|
|
7736
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: [styles$2.helpText, styles$2.mobileHelpText].join(" "), children: mobileHelpText })
|
|
7737
|
+
]
|
|
7665
7738
|
}
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
ref.current = null;
|
|
7672
|
-
}
|
|
7673
|
-
};
|
|
7674
|
-
}, [config, onLoad, ref]);
|
|
7675
|
-
hooks.useEffect(() => {
|
|
7676
|
-
if (!map) return;
|
|
7677
|
-
let timeoutID;
|
|
7678
|
-
map.onFilterEvent((showHelpText2) => {
|
|
7679
|
-
if (timeoutID) clearTimeout(timeoutID);
|
|
7680
|
-
setShowHelpText(showHelpText2);
|
|
7681
|
-
if (showHelpText2) {
|
|
7682
|
-
timeoutID = setTimeout(() => {
|
|
7683
|
-
setShowHelpText(false);
|
|
7684
|
-
}, 1e3);
|
|
7685
|
-
}
|
|
7686
|
-
});
|
|
7687
|
-
return () => {
|
|
7688
|
-
if (timeoutID) clearTimeout(timeoutID);
|
|
7689
|
-
};
|
|
7690
|
-
}, [map]);
|
|
7691
|
-
hooks.useEffect(() => {
|
|
7692
|
-
if (!map) return;
|
|
7693
|
-
map.collaborativeGesturesEnabled(!inModalState);
|
|
7694
|
-
}, [map, inModalState]);
|
|
7695
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("figure", { ref: targetRef, className: styles$2.mapContainer, children: [
|
|
7696
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7697
|
-
"div",
|
|
7698
|
-
{
|
|
7699
|
-
className: styles$2.helpTextContainer,
|
|
7700
|
-
style: { opacity: showHelpText ? 1 : 0 },
|
|
7701
|
-
"aria-hidden": true,
|
|
7702
|
-
children: [
|
|
7703
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: [styles$2.helpText, styles$2.desktopHelpText].join(" "), children: zoomHelpText }),
|
|
7704
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: [styles$2.helpText, styles$2.mobileHelpText].join(" "), children: mobileHelpText })
|
|
7705
|
-
]
|
|
7706
|
-
}
|
|
7707
|
-
),
|
|
7708
|
-
/* @__PURE__ */ jsxRuntime.jsx(MapProvider, { map, children })
|
|
7709
|
-
] });
|
|
7710
|
-
}
|
|
7711
|
-
);
|
|
7739
|
+
),
|
|
7740
|
+
/* @__PURE__ */ jsxRuntime.jsx(MapProvider, { map, children })
|
|
7741
|
+
] });
|
|
7742
|
+
};
|
|
7743
|
+
Map$1.Component = Component;
|
|
7712
7744
|
const optionPicker = "_optionPicker_1b561_1";
|
|
7713
7745
|
const title$1 = "_title_1b561_13";
|
|
7714
7746
|
const options = "_options_1b561_20";
|