@mapsight/lib-ol 4.0.2 → 4.1.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.
Files changed (61) hide show
  1. package/README.md +20 -13
  2. package/dist/feature/getGeoJsonFeatureSortAnchor.d.ts +21 -0
  3. package/dist/feature/getGeoJsonFeatureSortAnchor.d.ts.map +1 -0
  4. package/dist/feature/getGeoJsonFeatureSortAnchor.js +76 -0
  5. package/dist/feature/getGeoJsonFeatureSortAnchor.js.map +1 -0
  6. package/dist/style/createCachedStyleFunction.d.ts +3 -1
  7. package/dist/style/createCachedStyleFunction.d.ts.map +1 -1
  8. package/dist/style/createCachedStyleFunction.js +32 -17
  9. package/dist/style/createCachedStyleFunction.js.map +1 -1
  10. package/dist/style/styleFeatureScope.d.ts +10 -0
  11. package/dist/style/styleFeatureScope.d.ts.map +1 -0
  12. package/dist/style/styleFeatureScope.js +16 -0
  13. package/dist/style/styleFeatureScope.js.map +1 -0
  14. package/package.json +5 -2
  15. package/src/js/coordinate/add.ts +0 -13
  16. package/src/js/coordinate/addPixelPadding.ts +0 -21
  17. package/src/js/coordinate/fromPixel.ts +0 -10
  18. package/src/js/coordinate/scale.ts +0 -7
  19. package/src/js/coordinate/toPixel.ts +0 -13
  20. package/src/js/coordinates/equals.ts +0 -6
  21. package/src/js/coordinates/middleCoordinate.ts +0 -7
  22. package/src/js/events/condition/clickOnFeature.ts +0 -13
  23. package/src/js/extent/getCentroid.ts +0 -14
  24. package/src/js/extent/isFiniteExtent.ts +0 -7
  25. package/src/js/extents/combineExtents.ts +0 -11
  26. package/src/js/feature/animator.ts +0 -91
  27. package/src/js/feature/cluster.ts +0 -86
  28. package/src/js/feature/detectFeatureHits.ts +0 -57
  29. package/src/js/feature/ensureId.ts +0 -9
  30. package/src/js/feature/getCentroid.ts +0 -18
  31. package/src/js/feature/getExtent.ts +0 -10
  32. package/src/js/feature/getLayer.ts +0 -39
  33. package/src/js/feature/getUid.ts +0 -6
  34. package/src/js/features/getCentroidForFeatures.ts +0 -10
  35. package/src/js/features/getExtentForFeatures.ts +0 -10
  36. package/src/js/geometry/deriveGeometriesFromBase.ts +0 -122
  37. package/src/js/geometry/getDominantGeometryType.ts +0 -40
  38. package/src/js/geometry/getLineStringSegmentVerticesWithRotation.ts +0 -48
  39. package/src/js/geometry/getPolygonRingSegmentVerticesWithRotation.ts +0 -90
  40. package/src/js/index.ts +0 -62
  41. package/src/js/map/animateDuringTransition.ts +0 -58
  42. package/src/js/map/canvasSizeFixer.ts +0 -46
  43. package/src/js/map/containsExtentWithPadding.ts +0 -17
  44. package/src/js/map/fitToExtent.ts +0 -45
  45. package/src/js/map/fitToFeature.ts +0 -29
  46. package/src/js/map/fitToFeatures.ts +0 -21
  47. package/src/js/map/getPaddedViewExtent.ts +0 -42
  48. package/src/js/map/getVisibleLayersFromFramestate.ts +0 -14
  49. package/src/js/map/updateSizeDuringTransition.ts +0 -9
  50. package/src/js/map/updateSizeOnTransitionEnd.ts +0 -28
  51. package/src/js/points/findClosestPoint.ts +0 -51
  52. package/src/js/points/spreadPointClusterInRadius.ts +0 -84
  53. package/src/js/style/bindStyleToGeometry.ts +0 -11
  54. package/src/js/style/createCachedStyleFunction.ts +0 -344
  55. package/src/js/style/declarationToGeometry.ts +0 -7
  56. package/src/js/style/declarationToStyle.ts +0 -277
  57. package/src/js/style/styleFunction.ts +0 -42
  58. package/src/js/tileGrid/getTileUrlsForExtent.ts +0 -41
  59. package/src/js/view/centerOnFeature.ts +0 -23
  60. package/src/js/view/centerOnFeatures.ts +0 -30
  61. package/src/js/view/getMinZoomFittingContentInView.ts +0 -50
@@ -1,46 +0,0 @@
1
- import type OlMap from "ol/Map";
2
-
3
- /**
4
- * This updates the canvas size attribute (width/height) after composition.
5
- * This is used in combination with anchored viewport pattern to make panels
6
- * transition into the viewport possible without the map jumping around.
7
- *
8
- * @param map map
9
- */
10
- export default function canvasSizeFixer(map: OlMap) {
11
- let canvases: Array<HTMLCanvasElement> = [];
12
-
13
- function updateCanvasSize() {
14
- const size = map.getSize();
15
- if (!size) {
16
- return;
17
- }
18
-
19
- const width = size[0] + "px";
20
- const height = size[1] + "px";
21
-
22
- canvases.forEach((canvas) => {
23
- if (
24
- canvas.style.width !== width ||
25
- canvas.style.height !== height
26
- ) {
27
- canvas.style.width = width;
28
- canvas.style.height = height;
29
- }
30
- });
31
- }
32
-
33
- function updateTargetCanvases() {
34
- const targetElement = map.getTargetElement();
35
- if (targetElement) {
36
- canvases = Array.from(
37
- targetElement.querySelectorAll(".ol-viewport canvas"),
38
- );
39
- }
40
- }
41
-
42
- map.on("change:target", updateTargetCanvases);
43
- updateTargetCanvases();
44
-
45
- map.on("postcompose", updateCanvasSize);
46
- }
@@ -1,17 +0,0 @@
1
- import type OlMap from "ol/Map";
2
- import type {Extent} from "ol/extent";
3
- import {containsExtent} from "ol/extent";
4
-
5
- import type {Padding} from "../index";
6
- import getPaddedViewExtent from "./getPaddedViewExtent";
7
-
8
- export default function containsExtentWithPadding(
9
- map: OlMap,
10
- extent: Extent,
11
- padding?: Padding,
12
- ) {
13
- const viewExtent = padding
14
- ? getPaddedViewExtent(map, padding)
15
- : map.getView().calculateExtent(map.getSize());
16
- return viewExtent && containsExtent(viewExtent, extent);
17
- }
@@ -1,45 +0,0 @@
1
- import type OlMap from "ol/Map";
2
- import type {FitOptions} from "ol/View";
3
- import type {Extent} from "ol/extent";
4
-
5
- import isFiniteExtent from "../extent/isFiniteExtent";
6
- import type {Padding} from "../index";
7
- import containsExtentWithPadding from "./containsExtentWithPadding";
8
-
9
- export type ExtendedFitOptions = FitOptions & {
10
- keepZoom: boolean;
11
- skipIfInView: boolean;
12
- };
13
-
14
- export const DEFAULT_OPTIONS: ExtendedFitOptions = {
15
- duration: 300, // TODO: MAGIC NUMBER!
16
- padding: [60, 100, 60, 100], // TODO: MAGIC NUMBER!
17
- keepZoom: false, // TODO: Document keepZoom option!
18
- maxZoom: 17, // TODO: MAGIC NUMBER!
19
- skipIfInView: true, // TODO: Document skipIfInView option!
20
- };
21
-
22
- // TODO: Document keepZoom option!
23
- // TODO: Document skipIfInView option!
24
- export default function fitToExtent(
25
- map: OlMap,
26
- extent: Extent,
27
- options: ExtendedFitOptions = DEFAULT_OPTIONS,
28
- ) {
29
- if (!isFiniteExtent(extent)) {
30
- return;
31
- }
32
-
33
- const padding = (options.padding || [0, 0, 0, 0]) as Padding;
34
-
35
- if (
36
- options.skipIfInView === false ||
37
- !containsExtentWithPadding(map, extent, padding)
38
- ) {
39
- const view = map.getView();
40
- view.fit(extent, {
41
- ...options,
42
- maxZoom: options.keepZoom ? view.getZoom() : options.maxZoom,
43
- });
44
- }
45
- }
@@ -1,29 +0,0 @@
1
- import type Feature from "ol/Feature";
2
- import type OlMap from "ol/Map";
3
-
4
- import getExtent from "../feature/getExtent";
5
- import type {ExtendedFitOptions} from "./fitToExtent";
6
- import fitToExtent, {
7
- DEFAULT_OPTIONS as DEFAULT_OPTIONS_BASE,
8
- } from "./fitToExtent";
9
-
10
- export const DEFAULT_OPTIONS = {...DEFAULT_OPTIONS_BASE};
11
-
12
- // TODO: Document keepZoom option!
13
- // TODO: Document skipIfInView option!
14
- export default function fitToFeature(
15
- map: OlMap,
16
- feature: Feature,
17
- options: ExtendedFitOptions = DEFAULT_OPTIONS,
18
- ) {
19
- if (!feature) {
20
- return;
21
- }
22
-
23
- const extent = getExtent(feature);
24
- if (!extent) {
25
- return;
26
- }
27
-
28
- fitToExtent(map, extent, options);
29
- }
@@ -1,21 +0,0 @@
1
- import type Feature from "ol/Feature";
2
- import type OlMap from "ol/Map";
3
-
4
- import getExtent from "../features/getExtentForFeatures";
5
- import type {ExtendedFitOptions} from "./fitToExtent";
6
- import fitToExtent from "./fitToExtent";
7
- import {DEFAULT_OPTIONS as SINGLE_FEATURE_DEFAULT_OPTIONS} from "./fitToFeature";
8
-
9
- export const DEFAULT_OPTIONS = {...SINGLE_FEATURE_DEFAULT_OPTIONS};
10
-
11
- export default function fitToFeatures(
12
- map: OlMap,
13
- features: Array<Feature>,
14
- options: ExtendedFitOptions = DEFAULT_OPTIONS,
15
- ) {
16
- if (!features.length) {
17
- return;
18
- }
19
-
20
- fitToExtent(map, getExtent(features), options);
21
- }
@@ -1,42 +0,0 @@
1
- import type OlMap from "ol/Map";
2
- import * as olExtent from "ol/extent";
3
-
4
- import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
5
-
6
- import type {Padding} from "../index";
7
-
8
- export default function getPaddedViewExtent(map: OlMap, padding: Padding) {
9
- const size = map.getSize();
10
- if (size === undefined) {
11
- return null;
12
- }
13
-
14
- // remove padding from size (pixels)
15
- const [mapWidth, mapHeight] = size;
16
- const [top, right, bottom, left] = padding;
17
- const innerMapWith = ensureNonNullable(mapWidth) - left - right;
18
- const innerMapHeight = ensureNonNullable(mapHeight) - top - bottom;
19
- const innerMapSize = [innerMapWith, innerMapHeight];
20
-
21
- // pixels -> coondinate
22
- const paddedCenterPixel = [
23
- left + innerMapWith / 2,
24
- top + innerMapHeight / 2,
25
- ];
26
- const innerCenterCoordinate = map.getCoordinateFromPixel(paddedCenterPixel);
27
-
28
- const view = map.getView();
29
- const resolution = view.getResolution();
30
- const rotation = view.getRotation();
31
-
32
- if (!resolution) {
33
- return null;
34
- }
35
-
36
- return olExtent.getForViewAndSize(
37
- innerCenterCoordinate,
38
- resolution,
39
- rotation,
40
- innerMapSize,
41
- );
42
- }
@@ -1,14 +0,0 @@
1
- import type {FrameState} from "ol/Map";
2
- import {inView as layerInView} from "ol/layer/Layer";
3
-
4
- import unique from "lodash/uniq";
5
-
6
- export default function getVisibleLayersFromFramestate(frameState: FrameState) {
7
- return unique(
8
- frameState.layerStatesArray
9
- .filter((layerState) =>
10
- layerInView(layerState, frameState.viewState),
11
- )
12
- .map(({layer}) => layer),
13
- );
14
- }
@@ -1,9 +0,0 @@
1
- import type OlMap from "ol/Map";
2
-
3
- import animateDuringTransition from "./animateDuringTransition";
4
-
5
- export default function updateSizeDuringTransition(map: OlMap) {
6
- return animateDuringTransition(map, () => {
7
- map.updateSize();
8
- });
9
- }
@@ -1,28 +0,0 @@
1
- import type OlMap from "ol/Map";
2
-
3
- export default function updateSizeOnTransitionEnd(map: OlMap) {
4
- let previousTargetElement: undefined | HTMLElement;
5
-
6
- function updateSize() {
7
- map.updateSize();
8
- }
9
-
10
- function addEventListener() {
11
- const targetElement = map.getTargetElement();
12
-
13
- if (previousTargetElement) {
14
- previousTargetElement.removeEventListener(
15
- "transitionend",
16
- updateSize,
17
- );
18
- }
19
-
20
- if (targetElement) {
21
- targetElement.addEventListener("transitionend", updateSize);
22
- }
23
- previousTargetElement = targetElement;
24
- }
25
-
26
- map.on("change:target", addEventListener);
27
- addEventListener();
28
- }
@@ -1,51 +0,0 @@
1
- import type {Coordinate} from "ol/coordinate";
2
-
3
- import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
4
-
5
- /**
6
- * Gets distance between points
7
- *
8
- * @param a point a
9
- * @param b point b
10
- * @returns distance
11
- */
12
- function getDistance(a: Coordinate, b: Coordinate): number {
13
- const [aX, aY] = a;
14
- const [bX, bY] = b;
15
-
16
- return (
17
- Math.abs(ensureNonNullable(aX) - ensureNonNullable(bX)) +
18
- Math.abs(ensureNonNullable(aY) - ensureNonNullable(bY))
19
- );
20
- }
21
-
22
- export type PointsMap = Record<string, Coordinate>;
23
-
24
- type PointDistance = [string, number];
25
-
26
- /**
27
- * Finds the closest point to given basePoint [x, y] in map. Returns the key.
28
- *
29
- * @param basePoint base point
30
- * @param pointsMap map of
31
- * @returns key of the closest point in given pointsMap
32
- */
33
- export default function findClosestPoint(
34
- basePoint: Coordinate,
35
- pointsMap: PointsMap,
36
- ): string | null {
37
- const keys = Object.keys(pointsMap);
38
- const keyDistances = keys.map(
39
- (key): PointDistance => [
40
- key,
41
- getDistance(basePoint, ensureNonNullable(pointsMap[key])),
42
- ],
43
- );
44
- const reduceToSmallestDistance = (
45
- a: PointDistance | null,
46
- b: PointDistance,
47
- ) => (a !== null && a[1] > b[1] ? a : b);
48
- const smallest = keyDistances.reduce(reduceToSmallestDistance, null);
49
-
50
- return smallest === null ? null : smallest[0];
51
- }
@@ -1,84 +0,0 @@
1
- import type {Coordinate} from "ol/coordinate";
2
-
3
- import range from "lodash/range";
4
-
5
- import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
6
-
7
- import type {Resolution} from "../index";
8
- import type {PointsMap} from "./findClosestPoint";
9
- import findClosestPoint from "./findClosestPoint";
10
-
11
- const FULL_CIRCLE_ANGLE = 2 * Math.PI; // 360 degrees
12
-
13
- /**
14
- * Calculates points evenly spread on circle around center [x, y] on the given radius.
15
- *
16
- * @todo consider exporting / moving into separate file
17
- *
18
- * @param center center coordinates
19
- * @param resolution resolution
20
- * @param radius radius
21
- * @param number number of points
22
- * @returns points on circle
23
- */
24
- function calcPointsOnCircle(
25
- center: Coordinate,
26
- resolution: Resolution,
27
- radius: number,
28
- number: number,
29
- ): Array<Coordinate> {
30
- const [x, y] = center;
31
- const spreadRadius = resolution * radius;
32
- const spreadAngle = FULL_CIRCLE_ANGLE / number;
33
-
34
- return range(number).map((j: number) => [
35
- ensureNonNullable(x) + spreadRadius * Math.cos(j * spreadAngle),
36
- ensureNonNullable(y) + spreadRadius * Math.sin(j * spreadAngle),
37
- ]);
38
- }
39
-
40
- /**
41
- * Spreads points around coords in circle around radius
42
- *
43
- * @param coords center of the cluster
44
- * @param resolution current resolution
45
- * @param radius radius to spread in
46
- * @param points points to spread
47
- * @returns spread points
48
- */
49
- export default function spreadPointClusterInRadius(
50
- coords: Coordinate,
51
- resolution: Resolution,
52
- radius: number,
53
- points: Array<Coordinate>,
54
- ): PointsMap {
55
- // Check if too close/too many icons?
56
- //const sehnenLaenge = 2 * spreadRadius * Math.sin(spreadAngle / 2);
57
- //console.log({sehnenLaenge: sehnenLaenge});
58
-
59
- // We calculate ideal points on the circle with the given radius
60
- const targetPoints = calcPointsOnCircle(
61
- coords,
62
- resolution,
63
- radius,
64
- points.length,
65
- );
66
-
67
- // Copy real points to object
68
- const realPoints: PointsMap = points.reduce(
69
- (a, v, k) => ({...a, [String(k)]: v}),
70
- {},
71
- );
72
-
73
- // Find the closest real point for each point on the circle, save in object keeping the key of the real point
74
- const spreadPoints: PointsMap = {};
75
- for (const targetPoint of targetPoints) {
76
- const key = findClosestPoint(targetPoint, realPoints);
77
- if (key) {
78
- delete realPoints[key];
79
- spreadPoints[key] = targetPoint;
80
- }
81
- }
82
-
83
- return spreadPoints;
84
- }
@@ -1,11 +0,0 @@
1
- import type Geometry from "ol/geom/Geometry";
2
- import type Style from "ol/style/Style";
3
-
4
- export default function bindStyleToGeometry(
5
- baseStyle: Style,
6
- geometry: Geometry,
7
- ) {
8
- const style = baseStyle.clone();
9
- style.setGeometry(geometry);
10
- return style;
11
- }