@mapsight/lib-ol 4.0.3 → 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.
- package/README.md +20 -13
- package/dist/feature/getGeoJsonFeatureSortAnchor.d.ts +21 -0
- package/dist/feature/getGeoJsonFeatureSortAnchor.d.ts.map +1 -0
- package/dist/feature/getGeoJsonFeatureSortAnchor.js +76 -0
- package/dist/feature/getGeoJsonFeatureSortAnchor.js.map +1 -0
- package/dist/style/createCachedStyleFunction.d.ts +3 -1
- package/dist/style/createCachedStyleFunction.d.ts.map +1 -1
- package/dist/style/createCachedStyleFunction.js +32 -17
- package/dist/style/createCachedStyleFunction.js.map +1 -1
- package/dist/style/styleFeatureScope.d.ts +10 -0
- package/dist/style/styleFeatureScope.d.ts.map +1 -0
- package/dist/style/styleFeatureScope.js +16 -0
- package/dist/style/styleFeatureScope.js.map +1 -0
- package/package.json +5 -2
- package/src/js/coordinate/add.ts +0 -13
- package/src/js/coordinate/addPixelPadding.ts +0 -21
- package/src/js/coordinate/fromPixel.ts +0 -10
- package/src/js/coordinate/scale.ts +0 -7
- package/src/js/coordinate/toPixel.ts +0 -13
- package/src/js/coordinates/equals.ts +0 -6
- package/src/js/coordinates/middleCoordinate.ts +0 -7
- package/src/js/events/condition/clickOnFeature.ts +0 -13
- package/src/js/extent/getCentroid.ts +0 -14
- package/src/js/extent/isFiniteExtent.ts +0 -7
- package/src/js/extents/combineExtents.ts +0 -11
- package/src/js/feature/animator.ts +0 -91
- package/src/js/feature/cluster.ts +0 -86
- package/src/js/feature/detectFeatureHits.ts +0 -57
- package/src/js/feature/ensureId.ts +0 -9
- package/src/js/feature/getCentroid.ts +0 -18
- package/src/js/feature/getExtent.ts +0 -10
- package/src/js/feature/getLayer.ts +0 -39
- package/src/js/feature/getUid.ts +0 -6
- package/src/js/features/getCentroidForFeatures.ts +0 -10
- package/src/js/features/getExtentForFeatures.ts +0 -10
- package/src/js/geometry/deriveGeometriesFromBase.ts +0 -122
- package/src/js/geometry/getDominantGeometryType.ts +0 -40
- package/src/js/geometry/getLineStringSegmentVerticesWithRotation.ts +0 -48
- package/src/js/geometry/getPolygonRingSegmentVerticesWithRotation.ts +0 -90
- package/src/js/index.ts +0 -62
- package/src/js/map/animateDuringTransition.ts +0 -58
- package/src/js/map/canvasSizeFixer.ts +0 -46
- package/src/js/map/containsExtentWithPadding.ts +0 -17
- package/src/js/map/fitToExtent.ts +0 -45
- package/src/js/map/fitToFeature.ts +0 -29
- package/src/js/map/fitToFeatures.ts +0 -21
- package/src/js/map/getPaddedViewExtent.ts +0 -42
- package/src/js/map/getVisibleLayersFromFramestate.ts +0 -14
- package/src/js/map/updateSizeDuringTransition.ts +0 -9
- package/src/js/map/updateSizeOnTransitionEnd.ts +0 -28
- package/src/js/points/findClosestPoint.ts +0 -51
- package/src/js/points/spreadPointClusterInRadius.ts +0 -84
- package/src/js/style/bindStyleToGeometry.ts +0 -11
- package/src/js/style/createCachedStyleFunction.ts +0 -344
- package/src/js/style/declarationToGeometry.ts +0 -7
- package/src/js/style/declarationToStyle.ts +0 -277
- package/src/js/style/styleFunction.ts +0 -42
- package/src/js/tileGrid/getTileUrlsForExtent.ts +0 -41
- package/src/js/view/centerOnFeature.ts +0 -23
- package/src/js/view/centerOnFeatures.ts +0 -30
- package/src/js/view/getMinZoomFittingContentInView.ts +0 -50
package/README.md
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
# @mapsight/lib-ol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared **OpenLayers helpers** used across Mapsight packages — style function types, multi-level style caching, map fit/animation utilities, feature hit-testing, clustering, and geometry derivation. Import subpaths directly (there is no single barrel export).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
See the [documentation hub](https://github.com/open-mapsight/mapsight/blob/main/docs/README.md) for architecture and integration context.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Common imports
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
| Module | Purpose |
|
|
10
|
+
| ------------------------------------------------------------------- | ------------------------------------------------------ |
|
|
11
|
+
| `@mapsight/lib-ol/style/createCachedStyleFunction` | 3-level LRU cache wrapper for compiled style functions |
|
|
12
|
+
| `@mapsight/lib-ol/style/styleFunction` | `MapsightStyleFunction` and env types |
|
|
13
|
+
| `@mapsight/lib-ol/style/styleFeatureScope` | Hooks for runtime icon and style scope |
|
|
14
|
+
| `@mapsight/lib-ol/map/fitToFeature`, `fitToExtent`, `fitToFeatures` | View fitting with padding |
|
|
15
|
+
| `@mapsight/lib-ol/feature/detectFeatureHits` | Pointer hit detection |
|
|
16
|
+
| `@mapsight/lib-ol/feature/getGeoJsonFeatureSortAnchor` | Distance sorting anchor for lists |
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
Peer dependency: `ol`.
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
## Related packages
|
|
21
|
+
|
|
22
|
+
| Package | Role |
|
|
23
|
+
| --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
|
24
|
+
| [`@mapsight/vector-style-compiler`](https://github.com/open-mapsight/mapsight/blob/main/packages/vector-style-compiler/README.md) | Emits imports of `createCachedStyleFunction` in compiled output |
|
|
25
|
+
| [`@mapsight/traffic-style`](https://github.com/open-mapsight/mapsight/blob/main/packages/traffic-style/README.md) | Default compiled style built on this cache |
|
|
26
|
+
| [`@mapsight/core`](https://github.com/open-mapsight/mapsight/blob/main/packages/core/README.md) | Map controller uses style and fit helpers |
|
|
27
|
+
| [`@mapsight/ui`](https://github.com/open-mapsight/mapsight/blob/main/packages/ui/README.md) | UI plugins and config types |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Coordinate } from "ol/coordinate";
|
|
2
|
+
type GeoJsonBbox = [number, number, number, number];
|
|
3
|
+
type GeoJsonGeometryLike = {
|
|
4
|
+
type: string;
|
|
5
|
+
coordinates?: unknown;
|
|
6
|
+
};
|
|
7
|
+
export type GeoJsonFeatureLike = {
|
|
8
|
+
bbox?: GeoJsonBbox;
|
|
9
|
+
geometry?: GeoJsonGeometryLike | null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Returns a WGS84 lon/lat anchor suitable for `ol/sphere.getDistance`.
|
|
13
|
+
*
|
|
14
|
+
* Prefers `feature.bbox` when present. For Point geometries without bbox,
|
|
15
|
+
* reads coordinates directly. Other geometry types fall back to OpenLayers
|
|
16
|
+
* geometry parsing and extent center (with a one-time console warning).
|
|
17
|
+
*/
|
|
18
|
+
export default function getGeoJsonFeatureSortAnchor(feature: GeoJsonFeatureLike | null | undefined): Coordinate | null;
|
|
19
|
+
export declare function resetGeoJsonFeatureSortAnchorWarningForTests(): void;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=getGeoJsonFeatureSortAnchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGeoJsonFeatureSortAnchor.d.ts","sourceRoot":"","sources":["../../src/js/feature/getGeoJsonFeatureSortAnchor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAK9C,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD,KAAK,mBAAmB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAChC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACtC,CAAC;AAkEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,2BAA2B,CAClD,OAAO,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAC5C,UAAU,GAAG,IAAI,CAsBnB;AAED,wBAAgB,4CAA4C,SAE3D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import GeoJSON from "ol/format/GeoJSON";
|
|
2
|
+
import getExtentCentroid from "../extent/getCentroid";
|
|
3
|
+
const geoJsonFormat = new GeoJSON();
|
|
4
|
+
let hasLoggedNonPointGeometryFallbackWarning = false;
|
|
5
|
+
function isFiniteBbox(bbox) {
|
|
6
|
+
return bbox.every(Number.isFinite);
|
|
7
|
+
}
|
|
8
|
+
function getBboxCenter(bbox) {
|
|
9
|
+
if (!isFiniteBbox(bbox)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const [minX, minY, maxX, maxY] = bbox;
|
|
13
|
+
return getExtentCentroid([minX, minY, maxX, maxY]);
|
|
14
|
+
}
|
|
15
|
+
function isLonLatPair(value) {
|
|
16
|
+
return (Array.isArray(value) &&
|
|
17
|
+
value.length >= 2 &&
|
|
18
|
+
typeof value[0] === "number" &&
|
|
19
|
+
typeof value[1] === "number" &&
|
|
20
|
+
Number.isFinite(value[0]) &&
|
|
21
|
+
Number.isFinite(value[1]));
|
|
22
|
+
}
|
|
23
|
+
function getPointCoordinates(geometry) {
|
|
24
|
+
if (geometry.type !== "Point") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!isLonLatPair(geometry.coordinates)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return [geometry.coordinates[0], geometry.coordinates[1]];
|
|
31
|
+
}
|
|
32
|
+
function warnNonPointGeometryFallbackOnce() {
|
|
33
|
+
if (hasLoggedNonPointGeometryFallbackWarning) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
hasLoggedNonPointGeometryFallbackWarning = true;
|
|
37
|
+
console.warn("@mapsight/lib-ol: deriving feature sort anchors from non-Point GeoJSON geometries; add feature.bbox where possible for better performance.");
|
|
38
|
+
}
|
|
39
|
+
function getNonPointGeometryCenter(geometry) {
|
|
40
|
+
warnNonPointGeometryFallbackOnce();
|
|
41
|
+
const olGeometry = geoJsonFormat.readGeometry(geometry);
|
|
42
|
+
if (!olGeometry) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return getExtentCentroid(olGeometry.getExtent());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a WGS84 lon/lat anchor suitable for `ol/sphere.getDistance`.
|
|
49
|
+
*
|
|
50
|
+
* Prefers `feature.bbox` when present. For Point geometries without bbox,
|
|
51
|
+
* reads coordinates directly. Other geometry types fall back to OpenLayers
|
|
52
|
+
* geometry parsing and extent center (with a one-time console warning).
|
|
53
|
+
*/
|
|
54
|
+
export default function getGeoJsonFeatureSortAnchor(feature) {
|
|
55
|
+
if (!feature) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (feature.bbox) {
|
|
59
|
+
const bboxCenter = getBboxCenter(feature.bbox);
|
|
60
|
+
if (bboxCenter) {
|
|
61
|
+
return bboxCenter;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const geometry = feature.geometry;
|
|
65
|
+
if (!geometry) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (geometry.type === "Point") {
|
|
69
|
+
return getPointCoordinates(geometry);
|
|
70
|
+
}
|
|
71
|
+
return getNonPointGeometryCenter(geometry);
|
|
72
|
+
}
|
|
73
|
+
export function resetGeoJsonFeatureSortAnchorWarningForTests() {
|
|
74
|
+
hasLoggedNonPointGeometryFallbackWarning = false;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=getGeoJsonFeatureSortAnchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGeoJsonFeatureSortAnchor.js","sourceRoot":"","sources":["../../src/js/feature/getGeoJsonFeatureSortAnchor.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,iBAAiB,MAAM,uBAAuB,C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apsightStyleFunctionEnv, props: MapsightStyleFunctionProps, envHash: string, geometryType: GeometryType, styleName: string) => string;
|
|
22
22
|
declarationFunction: (env: MapsightStyleFunctionEnv, props: MapsightStyleFunctionProps, geometryType: GeometryType, styleName: string) => unknown;
|
|
23
|
+
volatileHashFunction?: (env: MapsightStyleFunctionEnv, props: MapsightStyleFunctionProps, geometryType: GeometryType, styleName: string) => string;
|
|
23
24
|
allowedProps?: Array<string> | false;
|
|
24
25
|
allowedStyles?: Array<string> | false;
|
|
25
26
|
cacheLevel1Size?: number;
|
|
@@ -33,6 +34,7 @@ export type StyleFunctionOptions = {
|
|
|
33
34
|
* @param [metricsCollector] optional callback receiving per-invocation runtime metrics (hash timing, cache hit/miss, and declaration/style timings)
|
|
34
35
|
* @param declarationHashFunction style declaration hash function
|
|
35
36
|
* @param declarationFunction style declaration function
|
|
37
|
+
* @param [volatileHashFunction] optional volatile hash function for values that should trigger a cache miss when changed, even if the declaration hash is the same (e.g. for time-based styling)
|
|
36
38
|
* @param [allowedProps=false] list of props allowed, false = all allowed
|
|
37
39
|
* @param [allowedStyles=false] list of styles allowed, false = all allowed
|
|
38
40
|
* @param [cacheLevel1Size=100] size of first level cache that caches feature geometry styles based on feature and environment state
|
|
@@ -41,5 +43,5 @@ export type StyleFunctionOptions = {
|
|
|
41
43
|
*
|
|
42
44
|
* @returns style function
|
|
43
45
|
*/
|
|
44
|
-
export default function createCachedStyleFunction({ constructorsMap, metricsCollector, declarationHashFunction, declarationFunction, allowedProps, allowedStyles, cacheLevel1Size, cacheLevel2Size, cacheLevel3Size, }: StyleFunctionOptions): MapsightStyleFunction;
|
|
46
|
+
export default function createCachedStyleFunction({ constructorsMap, metricsCollector, declarationHashFunction, declarationFunction, volatileHashFunction, allowedProps, allowedStyles, cacheLevel1Size, cacheLevel2Size, cacheLevel3Size, }: StyleFunctionOptions): MapsightStyleFunction;
|
|
45
47
|
//# sourceMappingURL=createCachedStyleFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCachedStyleFunction.d.ts","sourceRoot":"","sources":["../../src/js/style/createCachedStyleFunction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createCachedStyleFunction.d.ts","sourceRoot":"","sources":["../../src/js/style/createCachedStyleFunction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,IAAI,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAa3D,OAAO,KAAK,EACX,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,MAAM,oBAAoB,CAAC;AAmB5B,MAAM,MAAM,oBAAoB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,4BAA4B,EAAE,MAAM,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,CAC3C,OAAO,EAAE,oBAAoB,KACzB,IAAI,CAAC;AAEV,MAAM,MAAM,oBAAoB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,6BAA6B,CAAC;IACjD,uBAAuB,EAAE,CACxB,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,0BAA0B,EACjC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,KACb,MAAM,CAAC;IACZ,mBAAmB,EAAE,CACpB,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,0BAA0B,EACjC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,KACb,OAAO,CAAC;IACb,oBAAoB,CAAC,EAAE,CACtB,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,0BAA0B,EACjC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,KACb,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IACrC,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,EACjD,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,YAAoB,EACpB,aAAqB,EACrB,eAA4C,EAC5C,eAA4C,EAC5C,eAA4C,GAC5C,EAAE,oBAAoB,yBAgRtB"}
|
|
@@ -3,6 +3,7 @@ import { ensureNonNullable } from "@mapsight/lib-js/nonNullable";
|
|
|
3
3
|
import deriveGeometriesFromBase from "../geometry/deriveGeometriesFromBase.js";
|
|
4
4
|
import declarationToGeometry from "./declarationToGeometry.js";
|
|
5
5
|
import declarationToStyle from "./declarationToStyle.js";
|
|
6
|
+
import { enterStyleFeatureScope } from "./styleFeatureScope.js";
|
|
6
7
|
import { STYLE_ENV_FIELD_NAME, createPropsFilter } from "./styleFunction.js";
|
|
7
8
|
const TYPE_GEOMETRY_COLLECTION = "GeometryCollection";
|
|
8
9
|
const DEFAULT_STYLE = "default";
|
|
@@ -18,6 +19,7 @@ const DEFAULT_CACHE_LEVEL_3_SIZE = 100;
|
|
|
18
19
|
* @param [metricsCollector] optional callback receiving per-invocation runtime metrics (hash timing, cache hit/miss, and declaration/style timings)
|
|
19
20
|
* @param declarationHashFunction style declaration hash function
|
|
20
21
|
* @param declarationFunction style declaration function
|
|
22
|
+
* @param [volatileHashFunction] optional volatile hash function for values that should trigger a cache miss when changed, even if the declaration hash is the same (e.g. for time-based styling)
|
|
21
23
|
* @param [allowedProps=false] list of props allowed, false = all allowed
|
|
22
24
|
* @param [allowedStyles=false] list of styles allowed, false = all allowed
|
|
23
25
|
* @param [cacheLevel1Size=100] size of first level cache that caches feature geometry styles based on feature and environment state
|
|
@@ -26,15 +28,36 @@ const DEFAULT_CACHE_LEVEL_3_SIZE = 100;
|
|
|
26
28
|
*
|
|
27
29
|
* @returns style function
|
|
28
30
|
*/
|
|
29
|
-
export default function createCachedStyleFunction({ constructorsMap, metricsCollector, declarationHashFunction, declarationFunction, allowedProps = false, allowedStyles = false, cacheLevel1Size = DEFAULT_CACHE_LEVEL_1_SIZE, cacheLevel2Size = DEFAULT_CACHE_LEVEL_2_SIZE, cacheLevel3Size = DEFAULT_CACHE_LEVEL_3_SIZE, }) {
|
|
31
|
+
export default function createCachedStyleFunction({ constructorsMap, metricsCollector, declarationHashFunction, declarationFunction, volatileHashFunction, allowedProps = false, allowedStyles = false, cacheLevel1Size = DEFAULT_CACHE_LEVEL_1_SIZE, cacheLevel2Size = DEFAULT_CACHE_LEVEL_2_SIZE, cacheLevel3Size = DEFAULT_CACHE_LEVEL_3_SIZE, }) {
|
|
30
32
|
const hasMetricsCollector = typeof metricsCollector === "function";
|
|
31
33
|
const filterProps = createPropsFilter(allowedProps);
|
|
32
34
|
const createHash = (value) => JSON.stringify(value);
|
|
33
35
|
const cacheLevel1 = new LRUCache(cacheLevel1Size); // the first level cache caches feature geometry styles based on feature and environment state
|
|
34
36
|
const cacheLevel2 = new LRUCache(cacheLevel2Size); // the second level cache caches style objects based on the rules that apply and the environment state
|
|
35
37
|
const cacheLevel3 = new LRUCache(cacheLevel3Size); // the third level cache caches style objects based on the rules that apply and the environment state
|
|
38
|
+
function resolveStyleName(env) {
|
|
39
|
+
let styleName = DEFAULT_STYLE;
|
|
40
|
+
const envStyle = env[STYLE_ENV_FIELD_NAME];
|
|
41
|
+
if (typeof envStyle === "string") {
|
|
42
|
+
if (allowedStyles === false) {
|
|
43
|
+
styleName = envStyle;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
styleName =
|
|
47
|
+
allowedStyles.indexOf(envStyle) > -1
|
|
48
|
+
? envStyle
|
|
49
|
+
: DEFAULT_STYLE;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return styleName;
|
|
53
|
+
}
|
|
36
54
|
function level1(env, props, envHash, propsHash, geometryType, metrics) {
|
|
55
|
+
const volatileHash = volatileHashFunction
|
|
56
|
+
? volatileHashFunction(env, props, geometryType, resolveStyleName(env))
|
|
57
|
+
: "";
|
|
37
58
|
const cacheHashL1 = envHash +
|
|
59
|
+
HASH_STRING_DELIMITER +
|
|
60
|
+
volatileHash +
|
|
38
61
|
HASH_STRING_DELIMITER +
|
|
39
62
|
geometryType +
|
|
40
63
|
HASH_STRING_DELIMITER +
|
|
@@ -49,25 +72,15 @@ export default function createCachedStyleFunction({ constructorsMap, metricsColl
|
|
|
49
72
|
}
|
|
50
73
|
}
|
|
51
74
|
if (!hasLevel1) {
|
|
52
|
-
cacheLevel1.set(cacheHashL1, level2(env, props, envHash, propsHash, geometryType, metrics));
|
|
75
|
+
cacheLevel1.set(cacheHashL1, level2(env, props, envHash, propsHash, geometryType, volatileHash, metrics));
|
|
53
76
|
}
|
|
54
77
|
return cacheLevel1.get(cacheHashL1);
|
|
55
78
|
}
|
|
56
|
-
function level2(env, props, envHash, propsHash, geometryType, metrics) {
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
styleName = envStyle;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
styleName =
|
|
65
|
-
allowedStyles.indexOf(envStyle) > -1
|
|
66
|
-
? envStyle
|
|
67
|
-
: DEFAULT_STYLE;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const cacheHashL2 = declarationHashFunction(env, props, envHash, geometryType, styleName);
|
|
79
|
+
function level2(env, props, envHash, propsHash, geometryType, volatileHash, metrics) {
|
|
80
|
+
const styleName = resolveStyleName(env);
|
|
81
|
+
const cacheHashL2 = declarationHashFunction(env, props, envHash, geometryType, styleName) +
|
|
82
|
+
HASH_STRING_DELIMITER +
|
|
83
|
+
volatileHash;
|
|
71
84
|
if (cacheLevel2.containsKey(cacheHashL2)) {
|
|
72
85
|
if (metrics) {
|
|
73
86
|
metrics.level2Hits += 1;
|
|
@@ -150,6 +163,7 @@ export default function createCachedStyleFunction({ constructorsMap, metricsColl
|
|
|
150
163
|
totalMs: 0,
|
|
151
164
|
}
|
|
152
165
|
: undefined;
|
|
166
|
+
const exit = enterStyleFeatureScope(feature);
|
|
153
167
|
// subset of feature properties that are relevant for styling (also used for caching decisions)
|
|
154
168
|
const filteredProps = filterProps(feature.getProperties());
|
|
155
169
|
const envHashStart = hasMetricsCollector ? performance.now() : 0;
|
|
@@ -163,6 +177,7 @@ export default function createCachedStyleFunction({ constructorsMap, metricsColl
|
|
|
163
177
|
metrics.propsHashMs = performance.now() - propsHashStart;
|
|
164
178
|
}
|
|
165
179
|
const styles = styleGeometryOrGeometryCollectionCached(env, filteredProps, envHash, propsHash, feature.getGeometry(), metrics);
|
|
180
|
+
exit();
|
|
166
181
|
if (metrics && metricsCollector) {
|
|
167
182
|
metrics.outputStylesCount = styles.length;
|
|
168
183
|
metrics.totalMs = performance.now() - totalStart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCachedStyleFunction.js","sourceRoot":"","sources":["../../src/js/style/createCachedStyleFunction.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAG3C,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAG/D,OAAO,wBAAwB,MAAM,yCAAyC,CAAC;AAE/E,OAAO,qBAAqB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UAAU,CAAC,aAAa,CAAC,CAAC;QAC5C,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC;QAC1D,CAAC;QAED,MAAM,MAAM,GAAG,uCAAuC,CACrD,GAAG,EACH,aAAa,EACb,OAAO,EACP,SAAS,EACT,OAAO,CAAC,WAAW,EAAc,EACjC,OAAO,CACP,CAAC;QAEF,IAAI,EAAE,CAAC;QAEP,IAAI,OAAO,IAAI,gBAAgB,EAAE,CAAC;YACjC,OAAO,CAAC,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;YAC1C,OAAO,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC;YACjD,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FeatureLike } from "ol/Feature";
|
|
2
|
+
export type StyleFeatureScopeHooks = {
|
|
3
|
+
enter: (feature: {
|
|
4
|
+
changed: () => void;
|
|
5
|
+
}) => void;
|
|
6
|
+
exit: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function addStyleFeatureScopeHooks(newHook: StyleFeatureScopeHooks | null): void;
|
|
9
|
+
export declare function enterStyleFeatureScope(feature: FeatureLike): () => void;
|
|
10
|
+
//# sourceMappingURL=styleFeatureScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleFeatureScope.d.ts","sourceRoot":"","sources":["../../src/js/style/styleFeatureScope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,sBAAsB,GAAG;IACpC,KAAK,EAAE,CAAC,OAAO,EAAE;QAAC,OAAO,EAAE,MAAM,IAAI,CAAA;KAAC,KAAK,IAAI,CAAC;IAChD,IAAI,EAAE,MAAM,IAAI,CAAC;CACjB,CAAC;AAIF,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,sBAAsB,GAAG,IAAI,GACpC,IAAI,CAIN;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,cAS1D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const hooks = [];
|
|
2
|
+
export function addStyleFeatureScopeHooks(newHook) {
|
|
3
|
+
if (newHook) {
|
|
4
|
+
hooks.push(newHook);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function enterStyleFeatureScope(feature) {
|
|
8
|
+
if ("changed" in feature && typeof feature.changed === "function") {
|
|
9
|
+
hooks.forEach((hook) => hook.enter(feature));
|
|
10
|
+
return () => {
|
|
11
|
+
hooks.forEach((hook) => hook.exit());
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return () => { };
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=styleFeatureScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleFeatureScope.js","sourceRoot":"","sources":["../../src/js/style/styleFeatureScope.ts"],"names":[],"mappings":"AAOA,MAAM,KAAK,GAAkC,EAAE,CAAC;AAEhD,MAAM,UAAU,yBAAyB,CACxC,OAAsC;IAEtC,IAAI,OAAO,EAAE,CAAC;QACb,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAoB;IAC1D,IAAI,SAAS,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACnE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE;YACX,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapsight/lib-ol",
|
|
3
3
|
"description": "Mapsight OpenLayers Library",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@types/lodash": "^4.17.24",
|
|
8
8
|
"lodash": "^4.18.1",
|
|
9
9
|
"ol": "^10.9.0",
|
|
10
|
-
"@mapsight/lib-js": "^3.0.
|
|
10
|
+
"@mapsight/lib-js": "^3.0.4"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"tsc-alias": "^1.8.17"
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"default": "./dist/*.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
21
24
|
"license": "UNLICENSED",
|
|
22
25
|
"main": "index.js",
|
|
23
26
|
"peerDependencies": {
|
package/src/js/coordinate/add.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type {Coordinate} from "ol/coordinate";
|
|
2
|
-
|
|
3
|
-
import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
|
|
4
|
-
|
|
5
|
-
export default function add(
|
|
6
|
-
[aX, aY]: Coordinate,
|
|
7
|
-
[bX, bY]: Coordinate,
|
|
8
|
-
): [number, number] {
|
|
9
|
-
return [
|
|
10
|
-
ensureNonNullable(aX) + ensureNonNullable(bX),
|
|
11
|
-
ensureNonNullable(aY) + ensureNonNullable(bY),
|
|
12
|
-
];
|
|
13
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {Coordinate} from "ol/coordinate";
|
|
2
|
-
|
|
3
|
-
import type {Padding} from "../index";
|
|
4
|
-
import add from "./add";
|
|
5
|
-
import fromPixel from "./fromPixel";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param resolution Resolution
|
|
9
|
-
* @param coordinate Coordinate
|
|
10
|
-
* @param padding Padding (in pixels) to be cleared inside the view. Values in the array are top, right, bottom and left padding. Default is [0, 0, 0, 0]. Required.
|
|
11
|
-
* @returns coordinate with added pixel padding
|
|
12
|
-
*/
|
|
13
|
-
export default function addPixelPadding(
|
|
14
|
-
resolution: number,
|
|
15
|
-
coordinate: Coordinate,
|
|
16
|
-
[top, right, bottom, left]: Padding = [0, 0, 0, 0],
|
|
17
|
-
): Coordinate {
|
|
18
|
-
const pixelDelta = [(right - left) / 2, (bottom - top) / 2];
|
|
19
|
-
|
|
20
|
-
return add(coordinate, fromPixel(pixelDelta, resolution));
|
|
21
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type {Pixel} from "ol/pixel";
|
|
2
|
-
|
|
3
|
-
import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
|
|
4
|
-
|
|
5
|
-
export default function fromPixel([x, y]: Pixel, resolution: number) {
|
|
6
|
-
return [
|
|
7
|
-
ensureNonNullable(x) * resolution,
|
|
8
|
-
ensureNonNullable(y) * -1 * resolution,
|
|
9
|
-
];
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type {Coordinate} from "ol/coordinate";
|
|
2
|
-
|
|
3
|
-
import {ensureNonNullable} from "@mapsight/lib-js/nonNullable";
|
|
4
|
-
|
|
5
|
-
export default function toPixel(
|
|
6
|
-
[x, y]: Coordinate,
|
|
7
|
-
resolution: number,
|
|
8
|
-
): [number, number] {
|
|
9
|
-
return [
|
|
10
|
-
ensureNonNullable(x) / resolution,
|
|
11
|
-
(ensureNonNullable(y) * -1) / resolution,
|
|
12
|
-
];
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type {MapBrowserEvent} from "ol";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* based on http://stackoverflow.com/questions/29396614/openlayers3-clicking-outside-feature-deselects-all-features
|
|
5
|
-
*
|
|
6
|
-
* @param e event
|
|
7
|
-
* @returns return
|
|
8
|
-
*/
|
|
9
|
-
export default function clickOnFeature(e: MapBrowserEvent<PointerEvent>) {
|
|
10
|
-
return (
|
|
11
|
-
e.type === "click" && !!e.map.forEachFeatureAtPixel(e.pixel, () => true)
|
|
12
|
-
);
|
|
13
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type {Extent} from "ol/extent";
|
|
2
|
-
|
|
3
|
-
import {assertNonNullable} from "@mapsight/lib-js/nonNullable";
|
|
4
|
-
|
|
5
|
-
export default function getCentroid([top, right, bottom, left]: Extent): [
|
|
6
|
-
number,
|
|
7
|
-
number,
|
|
8
|
-
] {
|
|
9
|
-
assertNonNullable(top);
|
|
10
|
-
assertNonNullable(bottom);
|
|
11
|
-
assertNonNullable(right);
|
|
12
|
-
assertNonNullable(left);
|
|
13
|
-
return [top + (bottom - top) / 2, right + (left - right) / 2];
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type {Extent} from "ol/extent";
|
|
2
|
-
import {createEmpty, extend} from "ol/extent";
|
|
3
|
-
|
|
4
|
-
export default function combineExtents(extents: Array<Extent>) {
|
|
5
|
-
const combinedExtent = createEmpty();
|
|
6
|
-
extents
|
|
7
|
-
.filter((extent) => !!extent)
|
|
8
|
-
.forEach((extent) => extend(combinedExtent, extent));
|
|
9
|
-
|
|
10
|
-
return combinedExtent;
|
|
11
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// EXAMPLE:
|
|
2
|
-
//
|
|
3
|
-
//var animator = FeatureAnimator(ol, map, function (feature, vectorContext, time) {
|
|
4
|
-
// switch (feature.getGeometry().getType()) {
|
|
5
|
-
// case 'Polygon':
|
|
6
|
-
// var strokeStyle = new ol.style.Stroke({
|
|
7
|
-
// color: 'red',
|
|
8
|
-
// width: 4 * ol.easing.easeOut(time)
|
|
9
|
-
// });
|
|
10
|
-
// var fillStyle = new ol.style.Fill({
|
|
11
|
-
// color: 'yellow'
|
|
12
|
-
// });
|
|
13
|
-
//
|
|
14
|
-
// vectorContext.setFillStrokeStyle(fillStyle, strokeStyle);
|
|
15
|
-
// vectorContext.drawPolygonGeometry(feature.getGeometry().clone(), null);
|
|
16
|
-
//
|
|
17
|
-
// break;
|
|
18
|
-
// default:
|
|
19
|
-
// }
|
|
20
|
-
//});
|
|
21
|
-
//
|
|
22
|
-
//if (!ol.has.TOUCH) {
|
|
23
|
-
// FeatureHitDetector(
|
|
24
|
-
// map,
|
|
25
|
-
// function (feature) {
|
|
26
|
-
// animator.start(feature);
|
|
27
|
-
// map.render();
|
|
28
|
-
// $map.addClass('feature-is-hit');
|
|
29
|
-
// },
|
|
30
|
-
// function (feature) {
|
|
31
|
-
// animator.stop();
|
|
32
|
-
// map.render();
|
|
33
|
-
// $map.removeClass('feature-is-hit');
|
|
34
|
-
// }
|
|
35
|
-
// );
|
|
36
|
-
//}
|
|
37
|
-
import type Feature from "ol/Feature";
|
|
38
|
-
import type OlMap from "ol/Map";
|
|
39
|
-
import {unByKey} from "ol/Observable";
|
|
40
|
-
import type {EventsKey} from "ol/events";
|
|
41
|
-
import {getVectorContext} from "ol/render";
|
|
42
|
-
import type RenderEvent from "ol/render/Event";
|
|
43
|
-
import type VectorContext from "ol/render/VectorContext";
|
|
44
|
-
|
|
45
|
-
export type AnimationFunction = (
|
|
46
|
-
feature: Feature,
|
|
47
|
-
vectorContext: VectorContext,
|
|
48
|
-
progress: number,
|
|
49
|
-
) => void;
|
|
50
|
-
|
|
51
|
-
export default function animator(
|
|
52
|
-
map: OlMap,
|
|
53
|
-
animationFunction: AnimationFunction,
|
|
54
|
-
duration = 2000,
|
|
55
|
-
) {
|
|
56
|
-
let listenerKey: EventsKey;
|
|
57
|
-
let isStopped = true;
|
|
58
|
-
|
|
59
|
-
function start(feature: Feature) {
|
|
60
|
-
const startTime = new Date().getTime();
|
|
61
|
-
|
|
62
|
-
function animate(event: RenderEvent) {
|
|
63
|
-
if (isStopped || !event.frameState) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const vectorContext = getVectorContext(event);
|
|
68
|
-
|
|
69
|
-
const elapsedTime = event.frameState.time - startTime;
|
|
70
|
-
animationFunction(feature, vectorContext, elapsedTime / duration);
|
|
71
|
-
|
|
72
|
-
if (elapsedTime > duration) {
|
|
73
|
-
stop();
|
|
74
|
-
} else {
|
|
75
|
-
event.frameState.animate = true; // tell OL3 to continue postcompose animation
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
isStopped = false;
|
|
80
|
-
listenerKey = map.on("postcompose", animate);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function stop() {
|
|
84
|
-
if (!isStopped) {
|
|
85
|
-
isStopped = true;
|
|
86
|
-
unByKey(listenerKey);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return {start: start, stop: stop};
|
|
91
|
-
}
|