@mapsight/lib-ol 4.0.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/README.md +20 -0
- package/dist/coordinate/add.d.ts +3 -0
- package/dist/coordinate/add.d.ts.map +1 -0
- package/dist/coordinate/add.js +8 -0
- package/dist/coordinate/add.js.map +1 -0
- package/dist/coordinate/addPixelPadding.d.ts +10 -0
- package/dist/coordinate/addPixelPadding.d.ts.map +1 -0
- package/dist/coordinate/addPixelPadding.js +13 -0
- package/dist/coordinate/addPixelPadding.js.map +1 -0
- package/dist/coordinate/fromPixel.d.ts +3 -0
- package/dist/coordinate/fromPixel.d.ts.map +1 -0
- package/dist/coordinate/fromPixel.js +8 -0
- package/dist/coordinate/fromPixel.js.map +1 -0
- package/dist/coordinate/scale.d.ts +3 -0
- package/dist/coordinate/scale.d.ts.map +1 -0
- package/dist/coordinate/scale.js +5 -0
- package/dist/coordinate/scale.js.map +1 -0
- package/dist/coordinate/toPixel.d.ts +3 -0
- package/dist/coordinate/toPixel.d.ts.map +1 -0
- package/dist/coordinate/toPixel.js +8 -0
- package/dist/coordinate/toPixel.js.map +1 -0
- package/dist/coordinates/equals.d.ts +3 -0
- package/dist/coordinates/equals.d.ts.map +1 -0
- package/dist/coordinates/equals.js +5 -0
- package/dist/coordinates/equals.js.map +1 -0
- package/dist/coordinates/middleCoordinate.d.ts +3 -0
- package/dist/coordinates/middleCoordinate.d.ts.map +1 -0
- package/dist/coordinates/middleCoordinate.js +5 -0
- package/dist/coordinates/middleCoordinate.js.map +1 -0
- package/dist/events/condition/clickOnFeature.d.ts +9 -0
- package/dist/events/condition/clickOnFeature.d.ts.map +1 -0
- package/dist/events/condition/clickOnFeature.js +10 -0
- package/dist/events/condition/clickOnFeature.js.map +1 -0
- package/dist/extent/getCentroid.d.ts +6 -0
- package/dist/extent/getCentroid.d.ts.map +1 -0
- package/dist/extent/getCentroid.js +9 -0
- package/dist/extent/getCentroid.js.map +1 -0
- package/dist/extent/isFiniteExtent.d.ts +3 -0
- package/dist/extent/isFiniteExtent.d.ts.map +1 -0
- package/dist/extent/isFiniteExtent.js +4 -0
- package/dist/extent/isFiniteExtent.js.map +1 -0
- package/dist/extents/combineExtents.d.ts +3 -0
- package/dist/extents/combineExtents.d.ts.map +1 -0
- package/dist/extents/combineExtents.js +9 -0
- package/dist/extents/combineExtents.js.map +1 -0
- package/dist/feature/animator.d.ts +9 -0
- package/dist/feature/animator.d.ts.map +1 -0
- package/dist/feature/animator.js +33 -0
- package/dist/feature/animator.js.map +1 -0
- package/dist/feature/cluster.d.ts +8 -0
- package/dist/feature/cluster.d.ts.map +1 -0
- package/dist/feature/cluster.js +50 -0
- package/dist/feature/cluster.js.map +1 -0
- package/dist/feature/detectFeatureHits.d.ts +11 -0
- package/dist/feature/detectFeatureHits.d.ts.map +1 -0
- package/dist/feature/detectFeatureHits.js +34 -0
- package/dist/feature/detectFeatureHits.js.map +1 -0
- package/dist/feature/ensureId.d.ts +3 -0
- package/dist/feature/ensureId.d.ts.map +1 -0
- package/dist/feature/ensureId.js +7 -0
- package/dist/feature/ensureId.js.map +1 -0
- package/dist/feature/getCentroid.d.ts +3 -0
- package/dist/feature/getCentroid.d.ts.map +1 -0
- package/dist/feature/getCentroid.js +13 -0
- package/dist/feature/getCentroid.js.map +1 -0
- package/dist/feature/getExtent.d.ts +3 -0
- package/dist/feature/getExtent.d.ts.map +1 -0
- package/dist/feature/getExtent.js +8 -0
- package/dist/feature/getExtent.js.map +1 -0
- package/dist/feature/getLayer.d.ts +4 -0
- package/dist/feature/getLayer.d.ts.map +1 -0
- package/dist/feature/getLayer.js +23 -0
- package/dist/feature/getLayer.js.map +1 -0
- package/dist/feature/getUid.d.ts +3 -0
- package/dist/feature/getUid.d.ts.map +1 -0
- package/dist/feature/getUid.js +5 -0
- package/dist/feature/getUid.js.map +1 -0
- package/dist/features/getCentroidForFeatures.d.ts +3 -0
- package/dist/features/getCentroidForFeatures.d.ts.map +1 -0
- package/dist/features/getCentroidForFeatures.js +7 -0
- package/dist/features/getCentroidForFeatures.js.map +1 -0
- package/dist/features/getExtentForFeatures.d.ts +3 -0
- package/dist/features/getExtentForFeatures.d.ts.map +1 -0
- package/dist/features/getExtentForFeatures.js +7 -0
- package/dist/features/getExtentForFeatures.js.map +1 -0
- package/dist/geometry/deriveGeometriesFromBase.d.ts +8 -0
- package/dist/geometry/deriveGeometriesFromBase.d.ts.map +1 -0
- package/dist/geometry/deriveGeometriesFromBase.js +69 -0
- package/dist/geometry/deriveGeometriesFromBase.js.map +1 -0
- package/dist/geometry/getDominantGeometryType.d.ts +4 -0
- package/dist/geometry/getDominantGeometryType.d.ts.map +1 -0
- package/dist/geometry/getDominantGeometryType.js +30 -0
- package/dist/geometry/getDominantGeometryType.js.map +1 -0
- package/dist/geometry/getLineStringSegmentVerticesWithRotation.d.ts +4 -0
- package/dist/geometry/getLineStringSegmentVerticesWithRotation.d.ts.map +1 -0
- package/dist/geometry/getLineStringSegmentVerticesWithRotation.js +28 -0
- package/dist/geometry/getLineStringSegmentVerticesWithRotation.js.map +1 -0
- package/dist/geometry/getPolygonRingSegmentVerticesWithRotation.d.ts +4 -0
- package/dist/geometry/getPolygonRingSegmentVerticesWithRotation.d.ts.map +1 -0
- package/dist/geometry/getPolygonRingSegmentVerticesWithRotation.js +49 -0
- package/dist/geometry/getPolygonRingSegmentVerticesWithRotation.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/map/animateDuringTransition.d.ts +4 -0
- package/dist/map/animateDuringTransition.d.ts.map +1 -0
- package/dist/map/animateDuringTransition.js +41 -0
- package/dist/map/animateDuringTransition.js.map +1 -0
- package/dist/map/canvasSizeFixer.d.ts +10 -0
- package/dist/map/canvasSizeFixer.d.ts.map +1 -0
- package/dist/map/canvasSizeFixer.js +35 -0
- package/dist/map/canvasSizeFixer.js.map +1 -0
- package/dist/map/containsExtentWithPadding.d.ts +5 -0
- package/dist/map/containsExtentWithPadding.d.ts.map +1 -0
- package/dist/map/containsExtentWithPadding.js +9 -0
- package/dist/map/containsExtentWithPadding.js.map +1 -0
- package/dist/map/fitToExtent.d.ts +10 -0
- package/dist/map/fitToExtent.d.ts.map +1 -0
- package/dist/map/fitToExtent.js +26 -0
- package/dist/map/fitToExtent.js.map +1 -0
- package/dist/map/fitToFeature.d.ts +17 -0
- package/dist/map/fitToFeature.d.ts.map +1 -0
- package/dist/map/fitToFeature.js +16 -0
- package/dist/map/fitToFeature.js.map +1 -0
- package/dist/map/fitToFeatures.d.ts +17 -0
- package/dist/map/fitToFeatures.d.ts.map +1 -0
- package/dist/map/fitToFeatures.js +11 -0
- package/dist/map/fitToFeatures.js.map +1 -0
- package/dist/map/getPaddedViewExtent.d.ts +5 -0
- package/dist/map/getPaddedViewExtent.d.ts.map +1 -0
- package/dist/map/getPaddedViewExtent.js +28 -0
- package/dist/map/getPaddedViewExtent.js.map +1 -0
- package/dist/map/getVisibleLayersFromFramestate.d.ts +5 -0
- package/dist/map/getVisibleLayersFromFramestate.d.ts.map +1 -0
- package/dist/map/getVisibleLayersFromFramestate.js +8 -0
- package/dist/map/getVisibleLayersFromFramestate.js.map +1 -0
- package/dist/map/updateSizeDuringTransition.d.ts +3 -0
- package/dist/map/updateSizeDuringTransition.d.ts.map +1 -0
- package/dist/map/updateSizeDuringTransition.js +7 -0
- package/dist/map/updateSizeDuringTransition.js.map +1 -0
- package/dist/map/updateSizeOnTransitionEnd.d.ts +3 -0
- package/dist/map/updateSizeOnTransitionEnd.d.ts.map +1 -0
- package/dist/map/updateSizeOnTransitionEnd.js +19 -0
- package/dist/map/updateSizeOnTransitionEnd.js.map +1 -0
- package/dist/points/findClosestPoint.d.ts +11 -0
- package/dist/points/findClosestPoint.d.ts.map +1 -0
- package/dist/points/findClosestPoint.js +32 -0
- package/dist/points/findClosestPoint.js.map +1 -0
- package/dist/points/spreadPointClusterInRadius.d.ts +14 -0
- package/dist/points/spreadPointClusterInRadius.d.ts.map +1 -0
- package/dist/points/spreadPointClusterInRadius.js +53 -0
- package/dist/points/spreadPointClusterInRadius.js.map +1 -0
- package/dist/style/bindStyleToGeometry.d.ts +4 -0
- package/dist/style/bindStyleToGeometry.d.ts.map +1 -0
- package/dist/style/bindStyleToGeometry.js +6 -0
- package/dist/style/bindStyleToGeometry.js.map +1 -0
- package/dist/style/createCachedStyleFunction.d.ts +45 -0
- package/dist/style/createCachedStyleFunction.d.ts.map +1 -0
- package/dist/style/createCachedStyleFunction.js +175 -0
- package/dist/style/createCachedStyleFunction.js.map +1 -0
- package/dist/style/declarationToGeometry.d.ts +3 -0
- package/dist/style/declarationToGeometry.d.ts.map +1 -0
- package/dist/style/declarationToGeometry.js +4 -0
- package/dist/style/declarationToGeometry.js.map +1 -0
- package/dist/style/declarationToStyle.d.ts +6 -0
- package/dist/style/declarationToStyle.d.ts.map +1 -0
- package/dist/style/declarationToStyle.js +167 -0
- package/dist/style/declarationToStyle.js.map +1 -0
- package/dist/style/styleFunction.d.ts +21 -0
- package/dist/style/styleFunction.d.ts.map +1 -0
- package/dist/style/styleFunction.js +13 -0
- package/dist/style/styleFunction.js.map +1 -0
- package/dist/tileGrid/getTileUrlsForExtent.d.ts +4 -0
- package/dist/tileGrid/getTileUrlsForExtent.d.ts.map +1 -0
- package/dist/tileGrid/getTileUrlsForExtent.js +23 -0
- package/dist/tileGrid/getTileUrlsForExtent.js.map +1 -0
- package/dist/view/centerOnFeature.d.ts +10 -0
- package/dist/view/centerOnFeature.d.ts.map +1 -0
- package/dist/view/centerOnFeature.js +12 -0
- package/dist/view/centerOnFeature.js.map +1 -0
- package/dist/view/centerOnFeatures.d.ts +8 -0
- package/dist/view/centerOnFeatures.d.ts.map +1 -0
- package/dist/view/centerOnFeatures.js +19 -0
- package/dist/view/centerOnFeatures.js.map +1 -0
- package/dist/view/getMinZoomFittingContentInView.d.ts +15 -0
- package/dist/view/getMinZoomFittingContentInView.d.ts.map +1 -0
- package/dist/view/getMinZoomFittingContentInView.js +29 -0
- package/dist/view/getMinZoomFittingContentInView.js.map +1 -0
- package/package.json +36 -0
- package/src/js/coordinate/add.ts +13 -0
- package/src/js/coordinate/addPixelPadding.ts +21 -0
- package/src/js/coordinate/fromPixel.ts +10 -0
- package/src/js/coordinate/scale.ts +7 -0
- package/src/js/coordinate/toPixel.ts +13 -0
- package/src/js/coordinates/equals.ts +6 -0
- package/src/js/coordinates/middleCoordinate.ts +7 -0
- package/src/js/events/condition/clickOnFeature.ts +13 -0
- package/src/js/extent/getCentroid.ts +14 -0
- package/src/js/extent/isFiniteExtent.ts +7 -0
- package/src/js/extents/combineExtents.ts +11 -0
- package/src/js/feature/animator.ts +91 -0
- package/src/js/feature/cluster.ts +86 -0
- package/src/js/feature/detectFeatureHits.ts +57 -0
- package/src/js/feature/ensureId.ts +9 -0
- package/src/js/feature/getCentroid.ts +18 -0
- package/src/js/feature/getExtent.ts +10 -0
- package/src/js/feature/getLayer.ts +39 -0
- package/src/js/feature/getUid.ts +6 -0
- package/src/js/features/getCentroidForFeatures.ts +10 -0
- package/src/js/features/getExtentForFeatures.ts +10 -0
- package/src/js/geometry/deriveGeometriesFromBase.ts +122 -0
- package/src/js/geometry/getDominantGeometryType.ts +40 -0
- package/src/js/geometry/getLineStringSegmentVerticesWithRotation.ts +48 -0
- package/src/js/geometry/getPolygonRingSegmentVerticesWithRotation.ts +90 -0
- package/src/js/index.ts +62 -0
- package/src/js/map/animateDuringTransition.ts +58 -0
- package/src/js/map/canvasSizeFixer.ts +46 -0
- package/src/js/map/containsExtentWithPadding.ts +17 -0
- package/src/js/map/fitToExtent.ts +45 -0
- package/src/js/map/fitToFeature.ts +29 -0
- package/src/js/map/fitToFeatures.ts +21 -0
- package/src/js/map/getPaddedViewExtent.ts +42 -0
- package/src/js/map/getVisibleLayersFromFramestate.ts +14 -0
- package/src/js/map/updateSizeDuringTransition.ts +9 -0
- package/src/js/map/updateSizeOnTransitionEnd.ts +28 -0
- package/src/js/points/findClosestPoint.ts +51 -0
- package/src/js/points/spreadPointClusterInRadius.ts +84 -0
- package/src/js/style/bindStyleToGeometry.ts +11 -0
- package/src/js/style/createCachedStyleFunction.ts +344 -0
- package/src/js/style/declarationToGeometry.ts +7 -0
- package/src/js/style/declarationToStyle.ts +277 -0
- package/src/js/style/styleFunction.ts +42 -0
- package/src/js/tileGrid/getTileUrlsForExtent.ts +41 -0
- package/src/js/view/centerOnFeature.ts +23 -0
- package/src/js/view/centerOnFeatures.ts +30 -0
- package/src/js/view/getMinZoomFittingContentInView.ts +50 -0
package/src/js/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {Coordinate} from "ol/coordinate";
|
|
2
|
+
import type {Type as GeometryType} from "ol/geom/Geometry";
|
|
3
|
+
import type Image from "ol/style/Image";
|
|
4
|
+
import type Style from "ol/style/Style";
|
|
5
|
+
|
|
6
|
+
import type {Derivation} from "./geometry/deriveGeometriesFromBase";
|
|
7
|
+
|
|
8
|
+
export type StyleLiteral = {
|
|
9
|
+
[styleKey: string]: number | boolean | string | Style | null;
|
|
10
|
+
} & {
|
|
11
|
+
image?: Image | null;
|
|
12
|
+
anchor?: Array<number>;
|
|
13
|
+
size?: Array<number>;
|
|
14
|
+
imgSize?: Array<number>;
|
|
15
|
+
offset?: Array<number>;
|
|
16
|
+
color?: [number, number, number, number];
|
|
17
|
+
lineDash?: Array<number>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type UnitStyleValue = `${string}px` | `${string}%` | null;
|
|
21
|
+
export type BoolishStyleValue =
|
|
22
|
+
| boolean
|
|
23
|
+
| 1
|
|
24
|
+
| 0
|
|
25
|
+
| "1"
|
|
26
|
+
| "0"
|
|
27
|
+
| "true"
|
|
28
|
+
| "false"
|
|
29
|
+
| null;
|
|
30
|
+
|
|
31
|
+
export type NumberArrayStyleValue = Array<string | number> | string;
|
|
32
|
+
export type NoneAble<T> = "unset" | "none" | T;
|
|
33
|
+
|
|
34
|
+
export type StyleType = "circle" | "icon" | "stroke" | "fill" | "text";
|
|
35
|
+
|
|
36
|
+
export type StyleValues = Record<string, {value: string | number}>;
|
|
37
|
+
export type NoneAbleStyleValues = {value?: "none" | "unset"} | StyleValues;
|
|
38
|
+
|
|
39
|
+
export type StyleDeclaration =
|
|
40
|
+
| NoneAbleStyleValues
|
|
41
|
+
| Partial<Record<StyleType, NoneAbleStyleValues>>;
|
|
42
|
+
|
|
43
|
+
export type RootStyleDeclaration = {
|
|
44
|
+
display?: {value: "none"};
|
|
45
|
+
image?: {type: {value: "icon" | "circle"}};
|
|
46
|
+
geometry?: {value: GeometryType | Derivation};
|
|
47
|
+
zIndex?: {value: number};
|
|
48
|
+
} & Partial<Record<StyleType, StyleDeclaration>>;
|
|
49
|
+
|
|
50
|
+
export type GroupedRootStyleDeclaration = Record<string, RootStyleDeclaration>;
|
|
51
|
+
|
|
52
|
+
export type Padding = [number, number, number, number];
|
|
53
|
+
|
|
54
|
+
export type Resolution = number;
|
|
55
|
+
|
|
56
|
+
export type Vertex = [Coordinate, number];
|
|
57
|
+
|
|
58
|
+
export type VERTICES_FILTER = "all" | "first" | "start" | "last" | "end";
|
|
59
|
+
|
|
60
|
+
export type INTERMEDIATE_FILTER = "all" | "intermediate";
|
|
61
|
+
|
|
62
|
+
export type RING_FILTER = "all" | "inner" | "outer";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* From Modernizr */
|
|
2
|
+
import type OlMap from "ol/Map";
|
|
3
|
+
|
|
4
|
+
export type AnimateFunction = (deltaT: number) => void | boolean;
|
|
5
|
+
|
|
6
|
+
function hasTransitionEndEvent() {
|
|
7
|
+
const el = document.createElement("fakeelement");
|
|
8
|
+
return el.style.transition !== undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function animationLoop(render: AnimateFunction) {
|
|
12
|
+
let running = true;
|
|
13
|
+
let lastFrame = +new Date();
|
|
14
|
+
|
|
15
|
+
function loop(now: number) {
|
|
16
|
+
// stop the loop if render returned false
|
|
17
|
+
if (running) {
|
|
18
|
+
window.requestAnimationFrame(loop);
|
|
19
|
+
const deltaT = now - lastFrame;
|
|
20
|
+
if (deltaT < 160) {
|
|
21
|
+
running = render(deltaT) || running;
|
|
22
|
+
}
|
|
23
|
+
lastFrame = now;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
loop(lastFrame);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function animateDuringTransition(
|
|
31
|
+
map: OlMap,
|
|
32
|
+
render: AnimateFunction,
|
|
33
|
+
maxTime = 10000,
|
|
34
|
+
) {
|
|
35
|
+
const hasTransitionEvent = hasTransitionEndEvent();
|
|
36
|
+
if (!hasTransitionEvent || !window.requestAnimationFrame) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const targetElement = map.getTargetElement();
|
|
41
|
+
if (!targetElement) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let isTransitionRunning = true;
|
|
46
|
+
const maxTimeTimeout = setTimeout(endAnimation, maxTime);
|
|
47
|
+
|
|
48
|
+
function endAnimation() {
|
|
49
|
+
isTransitionRunning = false;
|
|
50
|
+
clearTimeout(maxTimeTimeout);
|
|
51
|
+
targetElement.removeEventListener("transitionend", endAnimation);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
animationLoop((deltaT) => render(deltaT) !== false && isTransitionRunning);
|
|
55
|
+
targetElement.addEventListener("transitionend", endAnimation);
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|