@guardian/interactive-component-library 0.3.0 → 0.3.2-rc1
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/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/Map.d.ts +8 -0
- package/dist/components/molecules/canvas-map/Map.js +90 -0
- package/dist/components/molecules/canvas-map/context/MapContext.d.ts +19 -0
- package/dist/components/molecules/canvas-map/context/MapContext.js +20 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.d.ts +6 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.js +40 -0
- package/dist/components/molecules/canvas-map/controls/icons/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.js +25 -0
- package/dist/components/molecules/canvas-map/controls/index.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/style.module.css.js +11 -0
- package/dist/components/molecules/canvas-map/index.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/Feature.d.ts +44 -0
- package/dist/components/molecules/canvas-map/lib/Feature.js +113 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +24 -0
- package/dist/components/molecules/canvas-map/lib/Map.d.ts +82 -0
- package/dist/components/molecules/canvas-map/lib/Map.js +267 -0
- package/dist/components/molecules/canvas-map/lib/View.d.ts +222 -0
- package/dist/components/molecules/canvas-map/lib/View.js +208 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.js +35 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.js +9 -0
- package/dist/components/molecules/canvas-map/lib/events/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.d.ts +63 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +122 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.js +41 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.js +19 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.js +22 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.js +46 -0
- package/dist/components/molecules/canvas-map/lib/geometry/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js +95 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +65 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +52 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +118 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +57 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +136 -0
- package/dist/components/molecules/canvas-map/lib/layers/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.d.ts +27 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.js +12 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +90 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +53 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +133 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +79 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +15 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +53 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +7 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.js +15 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +22 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.js +17 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +146 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.js +116 -0
- package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/util/array.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/array.js +15 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.js +24 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.d.ts +47 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.js +61 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.d.ts +26 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.js +35 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.js +27 -0
- package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +36 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.js +12 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.js +28 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +98 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.js +118 -0
- package/dist/components/molecules/canvas-map/lib/util/index.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.js +20 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.js +11 -0
- package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +114 -0
- package/dist/components/molecules/canvas-map/lib/util/size.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/util/size.js +53 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.js +25 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.js +7 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +14 -0
- package/dist/components/molecules/canvas-map/style.module.scss.js +20 -0
- package/dist/components/molecules/column-chart/column-chart-example.d.ts +35 -0
- package/dist/components/molecules/column-chart/column-chart-util.d.ts +1 -0
- package/dist/components/molecules/column-chart/index.d.ts +11 -0
- package/dist/components/molecules/column-chart/index.js +63 -0
- package/dist/components/molecules/column-chart/style.module.css.js +14 -0
- package/dist/components/molecules/control-change/index.d.ts +6 -0
- package/dist/components/molecules/control-change/index.js +29 -0
- package/dist/components/molecules/control-change/style.module.css.js +11 -0
- package/dist/components/molecules/dropdown/index.d.ts +11 -0
- package/dist/components/molecules/dropdown/index.js +191 -0
- package/dist/components/molecules/dropdown/style.module.css.js +50 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +5 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.js +14 -0
- package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +14 -0
- package/dist/components/molecules/index.d.ts +18 -0
- package/dist/components/molecules/modal/index.d.ts +8 -0
- package/dist/components/molecules/modal/index.js +59 -0
- package/dist/components/molecules/modal/style.module.css.js +26 -0
- package/dist/components/molecules/option-picker/index.d.ts +26 -0
- package/dist/components/molecules/option-picker/index.js +94 -0
- package/dist/components/molecules/option-picker/style.module.css.js +35 -0
- package/dist/components/molecules/page-section/index.d.ts +8 -0
- package/dist/components/molecules/page-section/index.js +52 -0
- package/dist/components/molecules/page-section/style.module.scss.js +20 -0
- package/dist/components/molecules/party-profile/index.d.ts +10 -0
- package/dist/components/molecules/party-profile/index.js +29 -0
- package/dist/components/molecules/party-profile/style.module.css.js +26 -0
- package/dist/components/molecules/refresh-indicator/index.d.ts +4 -0
- package/dist/components/molecules/refresh-indicator/index.js +18 -0
- package/dist/components/molecules/refresh-indicator/style.module.scss.js +17 -0
- package/dist/components/molecules/responsive-grid/index.d.ts +10 -0
- package/dist/components/molecules/responsive-grid/index.js +19 -0
- package/dist/components/molecules/responsive-grid/style.module.scss.js +8 -0
- package/dist/components/molecules/result-summary/index.d.ts +8 -0
- package/dist/components/molecules/result-summary/index.js +40 -0
- package/dist/components/molecules/result-summary/style.module.css.js +11 -0
- package/dist/components/molecules/search-input/icons/search.d.ts +1 -0
- package/dist/components/molecules/search-input/icons/search.js +24 -0
- package/dist/components/molecules/search-input/icons/search.module.css.js +11 -0
- package/dist/components/molecules/search-input/index.d.ts +11 -0
- package/dist/components/molecules/search-input/index.js +165 -0
- package/dist/components/molecules/search-input/style.module.css.js +32 -0
- package/dist/components/molecules/slope-chart/index.d.ts +16 -0
- package/dist/components/molecules/slope-chart/index.js +139 -0
- package/dist/components/molecules/slope-chart/style.module.css.js +35 -0
- package/dist/components/molecules/svg-map/context/MapContext.d.ts +1 -0
- package/dist/components/molecules/svg-map/context/MapContext.js +5 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +10 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.js +88 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.js +26 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +1 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +9 -0
- package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +4 -0
- package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +1 -0
- package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +4 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +19 -0
- package/dist/components/molecules/svg-map/index.d.ts +38 -0
- package/dist/components/molecules/svg-map/index.js +121 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.js +14 -0
- package/dist/components/molecules/svg-map/layers/Line.d.ts +7 -0
- package/dist/components/molecules/svg-map/layers/Line.js +48 -0
- package/dist/components/molecules/svg-map/layers/Point.d.ts +10 -0
- package/dist/components/molecules/svg-map/layers/Point.js +59 -0
- package/dist/components/molecules/svg-map/layers/Polygon.d.ts +9 -0
- package/dist/components/molecules/svg-map/layers/Polygon.js +75 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.js +11 -0
- package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +8 -0
- package/dist/components/molecules/svg-map/layers/index.d.ts +5 -0
- package/dist/components/molecules/svg-map/layers/index.js +12 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +3 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +32 -0
- package/dist/components/molecules/svg-map/style.module.css.js +11 -0
- package/dist/components/molecules/table/index.d.ts +7 -0
- package/dist/components/molecules/table/index.js +90 -0
- package/dist/components/molecules/table/style.module.scss.js +29 -0
- package/dist/components/molecules/table/useTable.d.ts +8 -0
- package/dist/components/molecules/table/useTable.js +128 -0
- package/dist/components/molecules/tooltip/index.d.ts +82 -0
- package/dist/components/molecules/tooltip/index.js +117 -0
- package/dist/components/molecules/tooltip/style.module.css.js +8 -0
- package/dist/components/molecules/topline-result/index.d.ts +3 -0
- package/dist/components/molecules/topline-result/index.js +61 -0
- package/dist/components/molecules/topline-result/style.module.scss.js +38 -0
- package/dist/components/organisms/coalitions-tracker/index.d.ts +16 -0
- package/dist/components/organisms/coalitions-tracker/index.js +151 -0
- package/dist/components/organisms/coalitions-tracker/style.module.scss.js +32 -0
- package/dist/components/organisms/index.d.ts +2 -0
- package/dist/components/organisms/ticker/gradient/index.d.ts +1 -0
- package/dist/components/organisms/ticker/gradient/index.js +35 -0
- package/dist/components/organisms/ticker/gradient/style.module.scss.js +14 -0
- package/dist/components/organisms/ticker/index.d.ts +5 -0
- package/dist/components/organisms/ticker/index.js +102 -0
- package/dist/components/organisms/ticker/style.module.scss.js +32 -0
- package/dist/components/particles/ad-slot/index.d.ts +40 -0
- package/dist/components/particles/ad-slot/index.js +34 -0
- package/dist/components/particles/ad-slot/style.module.css.js +11 -0
- package/dist/components/particles/arrow-button/index.d.ts +6 -0
- package/dist/components/particles/arrow-button/index.js +32 -0
- package/dist/components/particles/arrow-button/style.module.css.js +11 -0
- package/dist/components/particles/aspect-ratio-box/index.d.ts +4 -0
- package/dist/components/particles/aspect-ratio-box/index.js +15 -0
- package/dist/components/particles/aspect-ratio-box/style.module.css.js +6 -0
- package/dist/components/particles/button/index.d.ts +6 -0
- package/dist/components/particles/button/index.js +10 -0
- package/dist/components/particles/button/style.module.css.js +11 -0
- package/dist/components/particles/change-bar/index.d.ts +8 -0
- package/dist/components/particles/change-bar/index.js +27 -0
- package/dist/components/particles/change-bar/style.module.scss.js +14 -0
- package/dist/components/particles/chevron/index.d.ts +6 -0
- package/dist/components/particles/chevron/index.js +78 -0
- package/dist/components/particles/chevron/style.module.css.js +20 -0
- package/dist/components/particles/circle-icon/index.d.ts +6 -0
- package/dist/components/particles/circle-icon/index.js +32 -0
- package/dist/components/particles/circle-icon/style.module.css.js +14 -0
- package/dist/components/particles/close-button/index.d.ts +5 -0
- package/dist/components/particles/close-button/index.js +35 -0
- package/dist/components/particles/close-button/style.module.css.js +17 -0
- package/dist/components/particles/container/index.d.ts +5 -0
- package/dist/components/particles/container/index.js +13 -0
- package/dist/components/particles/container/style.module.scss.js +11 -0
- package/dist/components/particles/gradient-icon/index.d.ts +1 -0
- package/dist/components/particles/gradient-icon/index.js +46 -0
- package/dist/components/particles/gradient-icon/style.module.css.js +14 -0
- package/dist/components/particles/index.d.ts +18 -0
- package/dist/components/particles/info-button/index.d.ts +3 -0
- package/dist/components/particles/info-button/index.js +19 -0
- package/dist/components/particles/info-button/style.module.css.js +11 -0
- package/dist/components/particles/legend-item/index.d.ts +6 -0
- package/dist/components/particles/legend-item/index.js +26 -0
- package/dist/components/particles/legend-item/style.module.css.js +17 -0
- package/dist/components/particles/relative-time-sentence/index.d.ts +4 -0
- package/dist/components/particles/relative-time-sentence/index.js +14 -0
- package/dist/components/particles/relative-time-sentence/style.module.css.js +8 -0
- package/dist/components/particles/square-cut-corner-icon/index.d.ts +6 -0
- package/dist/components/particles/square-cut-corner-icon/index.js +56 -0
- package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +17 -0
- package/dist/components/particles/square-icon/index.d.ts +5 -0
- package/dist/components/particles/square-icon/index.js +28 -0
- package/dist/components/particles/square-icon/style.module.scss.js +11 -0
- package/dist/components/particles/stacked-bar/index.d.ts +23 -0
- package/dist/components/particles/stacked-bar/index.js +140 -0
- package/dist/components/particles/stacked-bar/style.module.css.js +17 -0
- package/dist/components/particles/stacked-grid/index.d.ts +6 -0
- package/dist/components/particles/stacked-grid/index.js +35 -0
- package/dist/components/particles/stacked-grid/style.module.css.js +20 -0
- package/dist/components/particles/waffle/index.d.ts +14 -0
- package/dist/components/particles/waffle/index.js +76 -0
- package/dist/components/particles/waffle/style.module.css.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +147 -0
- package/dist/shared/colors/index.d.ts +2 -0
- package/dist/shared/helpers/createStore.d.ts +1 -0
- package/dist/shared/helpers/geometry.d.ts +3 -0
- package/dist/shared/helpers/geometry.js +16 -0
- package/dist/shared/helpers/geometry.test.d.ts +1 -0
- package/dist/shared/helpers/labelsUtil.d.ts +54 -0
- package/dist/shared/helpers/labelsUtil.js +58 -0
- package/dist/shared/helpers/labelsUtils.test.d.ts +1 -0
- package/dist/shared/helpers/shouldUpdate.d.ts +7 -0
- package/dist/shared/hooks/index.d.ts +3 -0
- package/dist/shared/hooks/useContainerSize.d.ts +1 -0
- package/dist/shared/hooks/useContainerSize.js +24 -0
- package/dist/shared/hooks/useTouchOrHover.d.ts +7 -0
- package/dist/shared/hooks/useTouchOrHover.js +103 -0
- package/dist/shared/hooks/useWindowSize.d.ts +4 -0
- package/dist/shared/hooks/useWindowSize.js +27 -0
- package/dist/style.css +74 -74
- package/dist/styles/helpers/mergeStyles.d.ts +1 -0
- package/dist/styles/helpers/mergeStyles.js +22 -0
- package/dist/styles/helpers/mergeStyles.test.d.ts +1 -0
- package/dist/styles/theme.config.d.ts +124 -0
- package/package.json +19 -10
- package/dist/interactive-component-library.js +0 -8365
- package/dist/interactive-component-library.js.map +0 -1
- package/dist/interactive-component-library.umd.cjs +0 -8360
- package/dist/interactive-component-library.umd.cjs.map +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function arrayEquals(arr1, arr2) {
|
|
2
|
+
const len1 = arr1.length;
|
|
3
|
+
if (len1 !== arr2.length) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
for (let i = 0; i < len1; i++) {
|
|
7
|
+
if (arr1[i] !== arr2[i]) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
arrayEquals
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create a GeoJSON feature from a GeoBoundsLike object.
|
|
3
|
+
* @function
|
|
4
|
+
* @param {import("./extent").ExtentLike} extent
|
|
5
|
+
* @returns {import("../formats/GeoJSON").GeoJSONFeature} A GeoJSON feature representing a rectangle for the given bounds.
|
|
6
|
+
* @note The reverse winding order of coordinates. This is essential in D3 https://stackoverflow.com/questions/49311001/d3-js-drawing-geojson-incorrectly
|
|
7
|
+
*/
|
|
8
|
+
export function bboxFeature(extent: import('./extent').ExtentLike): import('../formats/GeoJSON').GeoJSONFeature;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Extent } from "./extent.js";
|
|
2
|
+
function bboxFeature(extent) {
|
|
3
|
+
const { minX, minY, maxX, maxY } = Extent.convert(extent);
|
|
4
|
+
const feature = {
|
|
5
|
+
type: "Feature",
|
|
6
|
+
properties: {},
|
|
7
|
+
geometry: {
|
|
8
|
+
coordinates: [
|
|
9
|
+
[
|
|
10
|
+
[minX, minY],
|
|
11
|
+
[minX, maxY],
|
|
12
|
+
[maxX, maxY],
|
|
13
|
+
[maxX, minY],
|
|
14
|
+
[minX, minY]
|
|
15
|
+
]
|
|
16
|
+
],
|
|
17
|
+
type: "Polygon"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return feature;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
bboxFeature
|
|
24
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GeoCoordinate } from './coordinate';
|
|
2
|
+
import { Extent } from './extent';
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import("./coordinate").GeoCoordinateLike} Coordinate
|
|
5
|
+
* @typedef {[number, number, number, number] | [Coordinate, Coordinate] | {sw: Coordinate, ne: Coordinate}} GeoBoundsLike
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A GeoBounds object represents a geographical bounding box, defined by its southwest and northeast points in longitude and latitude.
|
|
9
|
+
*
|
|
10
|
+
* @property {GeoCoordinate} southWest
|
|
11
|
+
* @property {GeoCoordinate} northEast
|
|
12
|
+
*/
|
|
13
|
+
export class GeoBounds {
|
|
14
|
+
/**
|
|
15
|
+
* Converts an array to a `GeoBounds` object.
|
|
16
|
+
*
|
|
17
|
+
* If a `GeoBounds` object is passed in, the function returns it unchanged.
|
|
18
|
+
*
|
|
19
|
+
* Internally, the function calls `GeoCoordinate#convert` to convert arrays to `GeoCoordinate` values.
|
|
20
|
+
*
|
|
21
|
+
* @param {GeoBoundsLike} input - An array of two coordinates to convert
|
|
22
|
+
* @returns {GeoBounds | null} A new `GeoBounds` object, if a conversion occurred, or the original `GeoBounds` object.
|
|
23
|
+
*/
|
|
24
|
+
static convert(input: GeoBoundsLike): GeoBounds | null;
|
|
25
|
+
/**
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {Object} bounds
|
|
28
|
+
* @param {GeoCoordinate} bounds.southWest
|
|
29
|
+
* @param {GeoCoordinate} bounds.northEast
|
|
30
|
+
*/
|
|
31
|
+
constructor({ southWest, northEast }: {
|
|
32
|
+
southWest: GeoCoordinate;
|
|
33
|
+
northEast: GeoCoordinate;
|
|
34
|
+
});
|
|
35
|
+
southWest: GeoCoordinate;
|
|
36
|
+
northEast: GeoCoordinate;
|
|
37
|
+
/**
|
|
38
|
+
* @returns {[number, number, number, number]}
|
|
39
|
+
*/
|
|
40
|
+
flat(): [number, number, number, number];
|
|
41
|
+
toExtent(): Extent;
|
|
42
|
+
}
|
|
43
|
+
export type Coordinate = import('./coordinate').GeoCoordinateLike;
|
|
44
|
+
export type GeoBoundsLike = [number, number, number, number] | [Coordinate, Coordinate] | {
|
|
45
|
+
sw: Coordinate;
|
|
46
|
+
ne: Coordinate;
|
|
47
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { GeoCoordinate } from "./coordinate.js";
|
|
2
|
+
import { Extent } from "./extent.js";
|
|
3
|
+
class GeoBounds {
|
|
4
|
+
/**
|
|
5
|
+
* @constructor
|
|
6
|
+
* @param {Object} bounds
|
|
7
|
+
* @param {GeoCoordinate} bounds.southWest
|
|
8
|
+
* @param {GeoCoordinate} bounds.northEast
|
|
9
|
+
*/
|
|
10
|
+
constructor({ southWest, northEast }) {
|
|
11
|
+
this.southWest = southWest;
|
|
12
|
+
this.northEast = northEast;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @returns {[number, number, number, number]}
|
|
16
|
+
*/
|
|
17
|
+
flat() {
|
|
18
|
+
return [
|
|
19
|
+
this.southWest.lng,
|
|
20
|
+
this.southWest.lat,
|
|
21
|
+
this.northEast.lng,
|
|
22
|
+
this.northEast.lat
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
toExtent() {
|
|
26
|
+
return new Extent(
|
|
27
|
+
this.southWest.lng,
|
|
28
|
+
this.southWest.lat,
|
|
29
|
+
this.northEast.lng,
|
|
30
|
+
this.northEast.lat
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts an array to a `GeoBounds` object.
|
|
35
|
+
*
|
|
36
|
+
* If a `GeoBounds` object is passed in, the function returns it unchanged.
|
|
37
|
+
*
|
|
38
|
+
* Internally, the function calls `GeoCoordinate#convert` to convert arrays to `GeoCoordinate` values.
|
|
39
|
+
*
|
|
40
|
+
* @param {GeoBoundsLike} input - An array of two coordinates to convert
|
|
41
|
+
* @returns {GeoBounds | null} A new `GeoBounds` object, if a conversion occurred, or the original `GeoBounds` object.
|
|
42
|
+
*/
|
|
43
|
+
static convert(input) {
|
|
44
|
+
if (input instanceof GeoBounds) return input;
|
|
45
|
+
if (!input) return null;
|
|
46
|
+
if (Array.isArray(input)) {
|
|
47
|
+
const [sw, ne] = input.map((d) => GeoCoordinate.convert(d));
|
|
48
|
+
return new GeoBounds({ southWest: sw, northEast: ne });
|
|
49
|
+
} else if (typeof input === "object" && input !== null) {
|
|
50
|
+
const { sw, ne } = input;
|
|
51
|
+
return new GeoBounds({
|
|
52
|
+
southWest: GeoCoordinate.convert(sw),
|
|
53
|
+
northEast: GeoCoordinate.convert(ne)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
throw new Error("`input` argument must be of type `GeoBoundsLike`");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
GeoBounds
|
|
61
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @typedef {[number, number] | {lng: number, lat: number}} GeoCoordinateLike */
|
|
2
|
+
/**
|
|
3
|
+
* A `GeoCoordinate` object represents a given longitude and latitude coordinate, measured in degrees.
|
|
4
|
+
* These coordinates are based on the [WGS84 (EPSG:4326) standard](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
|
|
5
|
+
*
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export class GeoCoordinate {
|
|
9
|
+
/**
|
|
10
|
+
* Converts an array of two numbers or an object with `lng` and `lat` properties
|
|
11
|
+
* to a `GeoCoordinate` object.
|
|
12
|
+
*
|
|
13
|
+
* If a `GeoCoordinate` object is passed in, the function returns it unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @param {GeoCoordinateLike} input - An array of two numbers ([lng<number>, lat<number>]), a {lng: number, lat: number} object, or an instance of `GeoCoordinate`.
|
|
16
|
+
* @returns {GeoCoordinate} A new `GeoCoordinate` object, if a conversion occurred, or the original `GeoCoordinate` object.
|
|
17
|
+
*/
|
|
18
|
+
static convert(input: GeoCoordinateLike): GeoCoordinate;
|
|
19
|
+
constructor(longitude: any, latitude: any);
|
|
20
|
+
lng: any;
|
|
21
|
+
lat: any;
|
|
22
|
+
}
|
|
23
|
+
export type GeoCoordinateLike = [number, number] | {
|
|
24
|
+
lng: number;
|
|
25
|
+
lat: number;
|
|
26
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class GeoCoordinate {
|
|
2
|
+
constructor(longitude, latitude) {
|
|
3
|
+
if (isNaN(longitude) || isNaN(latitude)) {
|
|
4
|
+
throw new Error(`Invalid GeoCoordinate: (${longitude}, ${latitude})`);
|
|
5
|
+
}
|
|
6
|
+
this.lng = longitude;
|
|
7
|
+
this.lat = latitude;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Converts an array of two numbers or an object with `lng` and `lat` properties
|
|
11
|
+
* to a `GeoCoordinate` object.
|
|
12
|
+
*
|
|
13
|
+
* If a `GeoCoordinate` object is passed in, the function returns it unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @param {GeoCoordinateLike} input - An array of two numbers ([lng<number>, lat<number>]), a {lng: number, lat: number} object, or an instance of `GeoCoordinate`.
|
|
16
|
+
* @returns {GeoCoordinate} A new `GeoCoordinate` object, if a conversion occurred, or the original `GeoCoordinate` object.
|
|
17
|
+
*/
|
|
18
|
+
static convert(input) {
|
|
19
|
+
if (input instanceof GeoCoordinate) {
|
|
20
|
+
return input;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
|
|
23
|
+
return new GeoCoordinate(Number(input[0]), Number(input[1]));
|
|
24
|
+
}
|
|
25
|
+
if (!Array.isArray(input) && typeof input === "object" && input !== null) {
|
|
26
|
+
return new GeoCoordinate(Number(input.lng), Number(input.lat));
|
|
27
|
+
}
|
|
28
|
+
throw new Error(
|
|
29
|
+
"`input` argument must be specified as an object {lng: <lng>, lat: <lat>} or an array [lng<number>, lat<number>]"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
GeoCoordinate
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function
|
|
3
|
+
* @param {Array<import('../geometry').Geometry>} geometries
|
|
4
|
+
*/
|
|
5
|
+
export function validateGeometries(geometries: Array<import('../geometry').Geometry>): void;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {import('../Feature').Feature | Object} feature - The feature you want to inspect
|
|
9
|
+
* @returns {string} URL to geojson.io, with feature embedded
|
|
10
|
+
*/
|
|
11
|
+
export function generateDebugUrl(feature: import('../Feature').Feature | any, convertToGeoJSON?: boolean): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function validateGeometries(geometries) {
|
|
2
|
+
if (!Array.isArray(geometries)) {
|
|
3
|
+
throw new Error("geometries must be an array");
|
|
4
|
+
}
|
|
5
|
+
geometries.forEach((geometry) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!geometry.type) {
|
|
8
|
+
throw new Error("geometry must have a type");
|
|
9
|
+
}
|
|
10
|
+
if (!((_a = geometry.coordinates) == null ? void 0 : _a.length)) {
|
|
11
|
+
throw new Error("geometry must have coordinates");
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function generateDebugUrl(feature, convertToGeoJSON = true) {
|
|
16
|
+
const featureGeoJSON = convertToGeoJSON ? feature.getGeoJSON() : feature;
|
|
17
|
+
const featureCollection = {
|
|
18
|
+
type: "FeatureCollection",
|
|
19
|
+
features: [featureGeoJSON]
|
|
20
|
+
};
|
|
21
|
+
const jsonString = encodeURIComponent(JSON.stringify(featureCollection));
|
|
22
|
+
return `https://geojson.io/#data=data:application/json,${jsonString}`;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
generateDebugUrl,
|
|
26
|
+
validateGeometries
|
|
27
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ol/geom/flat/deflate
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @param {Array<number>} flatCoordinates Flat coordinates.
|
|
6
|
+
* @param {number} offset Offset.
|
|
7
|
+
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
|
8
|
+
* @return {number} offset Offset.
|
|
9
|
+
*/
|
|
10
|
+
export function deflateCoordinate(flatCoordinates: Array<number>, offset: number, coordinate: any): number;
|
|
11
|
+
/**
|
|
12
|
+
* @param {Array<number>} flatCoordinates Flat coordinates.
|
|
13
|
+
* @param {number} offset Offset.
|
|
14
|
+
* @param {Array<import("../../coordinate.js").Coordinate>} coordinates Coordinates.
|
|
15
|
+
* @param {number} stride Stride.
|
|
16
|
+
* @return {number} offset Offset.
|
|
17
|
+
*/
|
|
18
|
+
export function deflateCoordinates(flatCoordinates: Array<number>, offset: number, coordinates: Array<any>, stride: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* @param {Array<number>} flatCoordinates Flat coordinates.
|
|
21
|
+
* @param {number} offset Offset.
|
|
22
|
+
* @param {Array<Array<import("../../coordinate.js").Coordinate>>} coordinatess Coordinatess.
|
|
23
|
+
* @param {number} stride Stride.
|
|
24
|
+
* @param {Array<number>} [ends] Ends.
|
|
25
|
+
* @return {Array<number>} Ends.
|
|
26
|
+
*/
|
|
27
|
+
export function deflateCoordinatesArray(flatCoordinates: Array<number>, offset: number, coordinatess: Array<Array<any>>, stride: number, ends?: Array<number>): Array<number>;
|
|
28
|
+
/**
|
|
29
|
+
* @param {Array<number>} flatCoordinates Flat coordinates.
|
|
30
|
+
* @param {number} offset Offset.
|
|
31
|
+
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} coordinatesss Coordinatesss.
|
|
32
|
+
* @param {number} stride Stride.
|
|
33
|
+
* @param {Array<Array<number>>} [endss] Endss.
|
|
34
|
+
* @return {Array<Array<number>>} Endss.
|
|
35
|
+
*/
|
|
36
|
+
export function deflateMultiCoordinatesArray(flatCoordinates: Array<number>, offset: number, coordinatesss: Array<Array<Array<any>>>, stride: number, endss?: Array<Array<number>>): Array<Array<number>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function haversineDistance(lat1: any, lon1: any, lat2: any, lon2: any): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function haversineDistance(lat1, lon1, lat2, lon2) {
|
|
2
|
+
const R = 6371e3;
|
|
3
|
+
const toRadians = (degrees) => degrees * Math.PI / 180;
|
|
4
|
+
const dLat = toRadians(lat2 - lat1);
|
|
5
|
+
const dLon = toRadians(lon2 - lon1);
|
|
6
|
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
7
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
8
|
+
return R * c;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
haversineDistance
|
|
12
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform the children of a parent node so they match the
|
|
3
|
+
* provided list of children. This function aims to efficiently
|
|
4
|
+
* remove, add, and reorder child nodes while maintaining a simple
|
|
5
|
+
* implementation (it is not guaranteed to minimize DOM operations).
|
|
6
|
+
* @param {Node} node The parent node whose children need reworking.
|
|
7
|
+
* @param {Array<Node>} children The desired children.
|
|
8
|
+
*/
|
|
9
|
+
export function replaceChildren(node: Node, children: Array<Node>): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function replaceChildren(node, children) {
|
|
2
|
+
const oldChildren = node.childNodes;
|
|
3
|
+
let done = false;
|
|
4
|
+
for (let i = 0; !done; ++i) {
|
|
5
|
+
const oldChild = oldChildren[i];
|
|
6
|
+
const newChild = children[i];
|
|
7
|
+
if (!oldChild && !newChild) {
|
|
8
|
+
done = true;
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
if (oldChild === newChild) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (!oldChild) {
|
|
15
|
+
node.appendChild(newChild);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!newChild) {
|
|
19
|
+
node.removeChild(oldChild);
|
|
20
|
+
--i;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
node.insertBefore(newChild, oldChild);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
replaceChildren
|
|
28
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get extent for array of coordinates
|
|
3
|
+
* @param {[[number, number]]} coordinates
|
|
4
|
+
* @returns {Extent}
|
|
5
|
+
*/
|
|
6
|
+
export function extentForCoordinates(coordinates: [[number, number]]): Extent;
|
|
7
|
+
/**
|
|
8
|
+
* Combine two extents into a single extent that contains both.
|
|
9
|
+
*
|
|
10
|
+
* @param {ExtentLike} extent1
|
|
11
|
+
* @param {ExtentLike} extent2
|
|
12
|
+
* @returns {Extent} The combined extent.
|
|
13
|
+
*/
|
|
14
|
+
export function combineExtents(extent1: ExtentLike, extent2: ExtentLike): Extent;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the passed coordinate is contained or on the edge of the extent.
|
|
17
|
+
*
|
|
18
|
+
* @param {Extent} extent Extent.
|
|
19
|
+
* @param {[number, number]} coordinate Coordinate.
|
|
20
|
+
* @return {boolean} The coordinate is contained in the extent.
|
|
21
|
+
*/
|
|
22
|
+
export function containsCoordinate(extent: Extent, coordinate: [number, number]): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Check if the passed coordinate is contained or on the edge of the extent.
|
|
25
|
+
*
|
|
26
|
+
* @param {Extent} extent Extent.
|
|
27
|
+
* @param {number} x X coordinate.
|
|
28
|
+
* @param {number} y Y coordinate.
|
|
29
|
+
* @return {boolean} The x, y values are contained in the extent.
|
|
30
|
+
*/
|
|
31
|
+
export function containsXY(extent: Extent, x: number, y: number): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {[number, number, number, number] | [[number, number], [number, number]] | {minX: number, minY: number, maxX: number, maxY: number}} ExtentLike
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* @class Extent
|
|
37
|
+
* @property {number} minX The minimum x value of the extent.
|
|
38
|
+
* @property {number} minY The minimum y value of the extent.
|
|
39
|
+
* @property {number} maxX The maximum x value of the extent.
|
|
40
|
+
* @property {number} maxY The maximum y value of the extent.
|
|
41
|
+
* @property {ExtentLike} array The extent as an array of numbers.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // The extent of a 975x610 viewport
|
|
45
|
+
* const viewPortExtent = new Extent([0, 0, 975, 610])
|
|
46
|
+
*/
|
|
47
|
+
export class Extent {
|
|
48
|
+
/**
|
|
49
|
+
* Converts {@link ExtentLike} to an {@link Extent} object.
|
|
50
|
+
*
|
|
51
|
+
* If an {@link Extent} object is passed in, the function returns it unchanged.
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* @param {ExtentLike} input - Extent defined as {@link ExtentLike}.
|
|
55
|
+
* @returns {Extent} A new `Extent` object, if a conversion occurred, or the original `Extent` object.
|
|
56
|
+
*/
|
|
57
|
+
static convert(input: ExtentLike): Extent;
|
|
58
|
+
constructor(minX: any, minY: any, maxX: any, maxY: any);
|
|
59
|
+
minX: any;
|
|
60
|
+
minY: any;
|
|
61
|
+
maxX: any;
|
|
62
|
+
maxY: any;
|
|
63
|
+
get width(): number;
|
|
64
|
+
get height(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Turn extent into a flat array of numbers: [minX, minY, maxX, maxY].
|
|
67
|
+
*
|
|
68
|
+
* @returns {[number, number, number, number]} - The extent as a flat array
|
|
69
|
+
*/
|
|
70
|
+
flat(): [number, number, number, number];
|
|
71
|
+
/**
|
|
72
|
+
* Create a new extent where the coordinates are multiplied by scaleFactor.
|
|
73
|
+
*
|
|
74
|
+
* @param {number} scaleFactor
|
|
75
|
+
* @returns {Extent} - The scaled
|
|
76
|
+
*/
|
|
77
|
+
scale(scaleFactor: number): Extent;
|
|
78
|
+
/**
|
|
79
|
+
* Check if the passed coordinate is contained or on the edge of the extent.
|
|
80
|
+
*
|
|
81
|
+
* @param {[number, number]} coordinate Coordinate.
|
|
82
|
+
* @return {boolean} The coordinate is contained in the extent.
|
|
83
|
+
*/
|
|
84
|
+
containsCoordinate(coordinate: [number, number]): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Combine with another extent
|
|
87
|
+
*
|
|
88
|
+
* @param {ExtentLike} extent
|
|
89
|
+
* @returns {Extent} A new extent that fits both this extent add the added one
|
|
90
|
+
*/
|
|
91
|
+
combineWith(extent: ExtentLike): Extent;
|
|
92
|
+
}
|
|
93
|
+
export type ExtentLike = [number, number, number, number] | [[number, number], [number, number]] | {
|
|
94
|
+
minX: number;
|
|
95
|
+
minY: number;
|
|
96
|
+
maxX: number;
|
|
97
|
+
maxY: number;
|
|
98
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
class Extent {
|
|
2
|
+
constructor(minX, minY, maxX, maxY) {
|
|
3
|
+
this.minX = minX;
|
|
4
|
+
this.minY = minY;
|
|
5
|
+
this.maxX = maxX;
|
|
6
|
+
this.maxY = maxY;
|
|
7
|
+
}
|
|
8
|
+
get width() {
|
|
9
|
+
return this.maxX - this.minX;
|
|
10
|
+
}
|
|
11
|
+
get height() {
|
|
12
|
+
return this.maxY - this.minY;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Turn extent into a flat array of numbers: [minX, minY, maxX, maxY].
|
|
16
|
+
*
|
|
17
|
+
* @returns {[number, number, number, number]} - The extent as a flat array
|
|
18
|
+
*/
|
|
19
|
+
flat() {
|
|
20
|
+
return [this.minX, this.minY, this.maxX, this.maxY];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new extent where the coordinates are multiplied by scaleFactor.
|
|
24
|
+
*
|
|
25
|
+
* @param {number} scaleFactor
|
|
26
|
+
* @returns {Extent} - The scaled
|
|
27
|
+
*/
|
|
28
|
+
scale(scaleFactor) {
|
|
29
|
+
const scaled = (
|
|
30
|
+
/** @type {ExtentLike} */
|
|
31
|
+
[this.minX, this.minY, this.maxX, this.maxY].map((d) => d * scaleFactor)
|
|
32
|
+
);
|
|
33
|
+
return Extent.convert(scaled);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if the passed coordinate is contained or on the edge of the extent.
|
|
37
|
+
*
|
|
38
|
+
* @param {[number, number]} coordinate Coordinate.
|
|
39
|
+
* @return {boolean} The coordinate is contained in the extent.
|
|
40
|
+
*/
|
|
41
|
+
containsCoordinate(coordinate) {
|
|
42
|
+
return containsXY(this, coordinate[0], coordinate[1]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Combine with another extent
|
|
46
|
+
*
|
|
47
|
+
* @param {ExtentLike} extent
|
|
48
|
+
* @returns {Extent} A new extent that fits both this extent add the added one
|
|
49
|
+
*/
|
|
50
|
+
combineWith(extent) {
|
|
51
|
+
return combineExtents(this, extent);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts {@link ExtentLike} to an {@link Extent} object.
|
|
55
|
+
*
|
|
56
|
+
* If an {@link Extent} object is passed in, the function returns it unchanged.
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
* @param {ExtentLike} input - Extent defined as {@link ExtentLike}.
|
|
60
|
+
* @returns {Extent} A new `Extent` object, if a conversion occurred, or the original `Extent` object.
|
|
61
|
+
*/
|
|
62
|
+
static convert(input) {
|
|
63
|
+
if (input instanceof Extent) return input;
|
|
64
|
+
if (!input) return null;
|
|
65
|
+
if (Array.isArray(input) && input.length === 4) {
|
|
66
|
+
const [minX, minY, maxX, maxY] = input;
|
|
67
|
+
return new Extent(minX, minY, maxX, maxY);
|
|
68
|
+
} else if (Array.isArray(input) && input.length === 2) {
|
|
69
|
+
const [min, max] = input;
|
|
70
|
+
return new Extent(min[0], min[1], max[0], max[1]);
|
|
71
|
+
} else if (typeof input === "object" && input !== null) {
|
|
72
|
+
const { minX, minY, maxX, maxY } = input;
|
|
73
|
+
return new Extent(minX, minY, maxX, maxY);
|
|
74
|
+
}
|
|
75
|
+
throw new Error("`input` argument must be of type `ExtentLike`");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function extentForCoordinates(coordinates) {
|
|
79
|
+
let minX = Infinity, minY = Infinity;
|
|
80
|
+
let maxX = -Infinity, maxY = -Infinity;
|
|
81
|
+
for (const coordinate of coordinates) {
|
|
82
|
+
if (coordinate[0] < minX) {
|
|
83
|
+
minX = coordinate[0];
|
|
84
|
+
}
|
|
85
|
+
if (coordinate[0] > maxX) {
|
|
86
|
+
maxX = coordinate[0];
|
|
87
|
+
}
|
|
88
|
+
if (coordinate[1] < minY) {
|
|
89
|
+
minY = coordinate[1];
|
|
90
|
+
}
|
|
91
|
+
if (coordinate[1] > maxY) {
|
|
92
|
+
maxY = coordinate[1];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return new Extent(minX, minY, maxX, maxY);
|
|
96
|
+
}
|
|
97
|
+
function combineExtents(extent1, extent2) {
|
|
98
|
+
const e1 = Extent.convert(extent1);
|
|
99
|
+
const e2 = Extent.convert(extent2);
|
|
100
|
+
const minX = Math.min(e1.minX, e2.minX);
|
|
101
|
+
const minY = Math.min(e1.minY, e2.minY);
|
|
102
|
+
const maxX = Math.max(e1.maxX, e2.maxX);
|
|
103
|
+
const maxY = Math.max(e1.maxY, e2.maxY);
|
|
104
|
+
return new Extent(minX, minY, maxX, maxY);
|
|
105
|
+
}
|
|
106
|
+
function containsCoordinate(extent, coordinate) {
|
|
107
|
+
return containsXY(extent, coordinate[0], coordinate[1]);
|
|
108
|
+
}
|
|
109
|
+
function containsXY(extent, x, y) {
|
|
110
|
+
return x >= extent.minX && x <= extent.maxX && y >= extent.minY && y <= extent.maxY;
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
Extent,
|
|
114
|
+
combineExtents,
|
|
115
|
+
containsCoordinate,
|
|
116
|
+
containsXY,
|
|
117
|
+
extentForCoordinates
|
|
118
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a function in another function that remembers the last return. If the
|
|
3
|
+
* returned function is called twice in a row with the same arguments and the same
|
|
4
|
+
* this object, it will return the value from the first call in the second call.
|
|
5
|
+
* @function
|
|
6
|
+
* @template ReturnType
|
|
7
|
+
* @param {function(...any): ReturnType} fn - The function to memoise
|
|
8
|
+
* @returns {function(...any): ReturnType} The memoised function
|
|
9
|
+
*/
|
|
10
|
+
export function memoise<ReturnType>(fn: (...args: any[]) => ReturnType): (...args: any[]) => ReturnType;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { arrayEquals } from "./array.js";
|
|
2
|
+
function memoise(fn) {
|
|
3
|
+
let called = false;
|
|
4
|
+
let lastResult;
|
|
5
|
+
let lastArgs;
|
|
6
|
+
let lastThis;
|
|
7
|
+
return function(...args) {
|
|
8
|
+
const nextArgs = Array.prototype.slice.call(args);
|
|
9
|
+
if (!called || this !== lastThis || !arrayEquals(nextArgs, lastArgs)) {
|
|
10
|
+
called = true;
|
|
11
|
+
lastThis = this;
|
|
12
|
+
lastArgs = nextArgs;
|
|
13
|
+
lastResult = fn.apply(this, args);
|
|
14
|
+
}
|
|
15
|
+
return lastResult;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
memoise
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get map resolution
|
|
3
|
+
*
|
|
4
|
+
* @param {Extent} extent Geographical extent: [ lonMin, latMin, lonMax, latMax ]
|
|
5
|
+
* @param {size} viewportSize Viewport size: [ width, height ]
|
|
6
|
+
* @return {number} Map resolution (horizontal)
|
|
7
|
+
* @api
|
|
8
|
+
*/
|
|
9
|
+
export function resolutionForExtent(extent: Extent, viewportSize: size): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { haversineDistance } from "./distance.js";
|
|
2
|
+
function resolutionForExtent(extent, viewportSize) {
|
|
3
|
+
const [lonMin, latMin, lonMax, latMax] = extent;
|
|
4
|
+
const latMid = (latMin + latMax) / 2;
|
|
5
|
+
const distance = haversineDistance(latMid, lonMin, latMid, lonMax);
|
|
6
|
+
const resolution = distance / viewportSize[0];
|
|
7
|
+
return resolution;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
resolutionForExtent
|
|
11
|
+
};
|