openskidata-format 11.1.0 → 12.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/dist/Lift.d.ts +2 -0
- package/dist/Lift.js.map +1 -1
- package/dist/Run.d.ts +2 -0
- package/dist/Run.js.map +1 -1
- package/dist/SkiArea.d.ts +2 -0
- package/dist/SkiArea.js.map +1 -1
- package/dist/Spot.d.ts +2 -0
- package/dist/Spot.js.map +1 -1
- package/dist/ViewportHint.d.ts +33 -0
- package/dist/ViewportHint.js +150 -0
- package/dist/ViewportHint.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Lift.ts +2 -0
- package/src/Run.ts +2 -0
- package/src/SkiArea.ts +2 -0
- package/src/Spot.ts +2 -0
- package/src/ViewportHint.ts +205 -0
- package/src/index.ts +1 -0
package/dist/Lift.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { SkiAreaSummaryFeature } from './SkiArea';
|
|
|
5
5
|
import { Source } from './Source';
|
|
6
6
|
import { LiftStationSpotFeature } from './Spot';
|
|
7
7
|
import { Status } from './Status';
|
|
8
|
+
import { ViewportHint } from './ViewportHint';
|
|
8
9
|
export type LiftFeature = GeoJSON.Feature<LiftGeometry, LiftProperties>;
|
|
9
10
|
export type LiftGeometry = GeoJSON.LineString | GeoJSON.MultiLineString;
|
|
10
11
|
/**
|
|
@@ -72,6 +73,7 @@ export type LiftProperties = {
|
|
|
72
73
|
websites: string[];
|
|
73
74
|
wikidataID: string | null;
|
|
74
75
|
places: Place[];
|
|
76
|
+
viewportHint: ViewportHint;
|
|
75
77
|
};
|
|
76
78
|
export declare enum LiftType {
|
|
77
79
|
CableCar = "cable_car",
|
package/dist/Lift.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lift.js","sourceRoot":"","sources":["../src/Lift.ts"],"names":[],"mappings":";;;
|
|
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AC;QACpB,KAAK,eAAM,CAAC,YAAY,CAAC;QACzB,KAAK,eAAM,CAAC,SAAS;YACnB,OAAO,gBAAgB,CAAA;QACzB;YACE,OAAO,IAAA,iDAAuB,EAAC,MAAM,CAAC,CAAA;IAC1C,CAAC;AACH,CAAC"}
|
package/dist/Run.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { SkiAreaSummaryFeature } from './SkiArea';
|
|
|
7
7
|
import { SnowCoverHistory } from './SnowCoverHistory';
|
|
8
8
|
import { Source } from './Source';
|
|
9
9
|
import { Status } from './Status';
|
|
10
|
+
import { ViewportHint } from './ViewportHint';
|
|
10
11
|
export type RunGeometry = GeoJSON.LineString | GeoJSON.Polygon;
|
|
11
12
|
/**
|
|
12
13
|
* Represents a segment of a ski run/trail.
|
|
@@ -79,6 +80,7 @@ export type RunProperties = {
|
|
|
79
80
|
wikidataID: string | null;
|
|
80
81
|
places: Place[];
|
|
81
82
|
snowCoverHistory?: SnowCoverHistory;
|
|
83
|
+
viewportHint: ViewportHint;
|
|
82
84
|
};
|
|
83
85
|
export declare enum RunUse {
|
|
84
86
|
Downhill = "downhill",
|
package/dist/Run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Run.js","sourceRoot":"","sources":["../src/Run.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Run.js","sourceRoot":"","sources":["../src/Run.ts"],"names":[],"mappings":";;;AAkJA,kDAUC;AAED,kCAKC;AAED,kDAiBC;AAED,0CAyDC;AAhPD,yDAK2B;AAG3B,uEAAmE;AAKnE,4EAAwE;AAgFxE,IAAY,MAYX;AAZD,WAAY,MAAM;IAChB,+BAAqB,CAAA;IACrB,2BAAiB,CAAA;IACjB,6BAAmB,CAAA;IACnB,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,2BAAiB,CAAA;IACjB,gCAAsB,CAAA;IACtB,gCAAsB,CAAA;IACtB,mCAAyB,CAAA;IACzB,mCAAyB,CAAA;IAC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H,CAAC"}
|
package/dist/SkiArea.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { RunDifficultyConvention } from './RunDifficultyConvention';
|
|
|
6
6
|
import { SnowCoverHistory } from './SnowCoverHistory';
|
|
7
7
|
import { Source } from './Source';
|
|
8
8
|
import { Status } from './Status';
|
|
9
|
+
import { ViewportHint } from './ViewportHint';
|
|
9
10
|
/**
|
|
10
11
|
* A ski area feature is derived from several sources:
|
|
11
12
|
* - OpenStreetMap site=piste relations (must contain at least one lift or run of any kind)
|
|
@@ -48,6 +49,7 @@ export type SkiAreaProperties = SkiAreaSummaryProperties & {
|
|
|
48
49
|
websites: string[];
|
|
49
50
|
wikidataID: string | null;
|
|
50
51
|
places: Place[];
|
|
52
|
+
viewportHint: ViewportHint;
|
|
51
53
|
};
|
|
52
54
|
export type SkiAreaSummaryProperties = {
|
|
53
55
|
type: FeatureType.SkiArea;
|
package/dist/SkiArea.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkiArea.js","sourceRoot":"","sources":["../src/SkiArea.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SkiArea.js","sourceRoot":"","sources":["../src/SkiArea.ts"],"names":[],"mappings":";;;AAwEA,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,wCAAqB,CAAA;IACrB,oCAAiB,CAAA;AACnB,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B"}
|
package/dist/Spot.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FeatureType } from './FeatureType';
|
|
|
3
3
|
import { Place } from './Place';
|
|
4
4
|
import { SkiAreaSummaryFeature } from './SkiArea';
|
|
5
5
|
import { Source } from './Source';
|
|
6
|
+
import { ViewportHint } from './ViewportHint';
|
|
6
7
|
/**
|
|
7
8
|
* A GeoJSON feature representing a spot (point of interest) in or around a ski area.
|
|
8
9
|
*
|
|
@@ -30,6 +31,7 @@ export type SpotBaseProperties = {
|
|
|
30
31
|
skiAreas: SkiAreaSummaryFeature[];
|
|
31
32
|
sources: Source[];
|
|
32
33
|
places: Place[];
|
|
34
|
+
viewportHint: ViewportHint;
|
|
33
35
|
};
|
|
34
36
|
/**
|
|
35
37
|
* Types of spots that can be found in or around ski areas.
|
package/dist/Spot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spot.js","sourceRoot":"","sources":["../src/Spot.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Spot.js","sourceRoot":"","sources":["../src/Spot.ts"],"names":[],"mappings":";;;AAiDA;;GAEG;AACH,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,iCAAqB,CAAA;IACrB,wCAA4B,CAAA;IAC5B,2EAA+D,CAAA;IAC/D,+EAAmE,CAAA;IACnE,iCAAqB,CAAA;AACvB,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB;AAaD;;GAEG;AACH,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,kCAAW,CAAA;IACX,gCAAS,CAAA;IACT,8CAAuB,CAAA;AACzB,CAAC,EAJW,mBAAmB,mCAAnB,mBAAmB,QAI9B;AAuBD;;GAEG;AACH,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,kCAAW,CAAA;IACX,kCAAW,CAAA;IACX,wCAAiB,CAAA;AACnB,CAAC,EAJW,mBAAmB,mCAAnB,mBAAmB,QAI9B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as GeoJSON from 'geojson';
|
|
2
|
+
/**
|
|
3
|
+
* Pre-computed viewport positioning data stored on every feature's properties.
|
|
4
|
+
* Camera space: Y axis points uphill (along bearing), X axis points screen-right.
|
|
5
|
+
* Metric values are in that rotated frame with elevation-adjusted Y positions
|
|
6
|
+
* (at 45° pitch, Δe metres above mean elevation shifts Y by Δe metres).
|
|
7
|
+
*/
|
|
8
|
+
export type ViewportHint = {
|
|
9
|
+
/** Geographic centre of the rotated bounding box as [lng, lat]. */
|
|
10
|
+
center: [number, number];
|
|
11
|
+
/**
|
|
12
|
+
* Uphill bearing in degrees clockwise from north. null when elevation variation is
|
|
13
|
+
* insufficient to determine orientation — client should use top-down view (pitch 0, bearing 0).
|
|
14
|
+
*/
|
|
15
|
+
bearing: number | null;
|
|
16
|
+
/** Bounding box width along the camera X axis, in metres. */
|
|
17
|
+
rotatedWidthMeters: number;
|
|
18
|
+
/** Bounding box height along the camera Y axis, in metres (elevation-adjusted). */
|
|
19
|
+
rotatedHeightMeters: number;
|
|
20
|
+
/**
|
|
21
|
+
* Most-downhill edge of the elevation-adjusted bounding box in camera-Y metres, relative
|
|
22
|
+
* to mean feature elevation. Used to compute the perspective centre shift at 45° pitch:
|
|
23
|
+
* look-at point = minCameraY + nearFraction * rotatedHeightMeters, where
|
|
24
|
+
* nearFraction = nearGround / (nearGround + farGround) from camera pitch and vFOV.
|
|
25
|
+
*/
|
|
26
|
+
minCameraY: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Computes a ViewportHint from one or more GeoJSON geometries.
|
|
30
|
+
* All geometry types are accepted; elevation is read from the Z coordinate (defaults to 0).
|
|
31
|
+
* Throws if no coordinates are found.
|
|
32
|
+
*/
|
|
33
|
+
export declare function computeViewportHint(geometries: GeoJSON.Geometry[]): ViewportHint;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeViewportHint = computeViewportHint;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
6
|
+
/**
|
|
7
|
+
* Computes a ViewportHint from one or more GeoJSON geometries.
|
|
8
|
+
* All geometry types are accepted; elevation is read from the Z coordinate (defaults to 0).
|
|
9
|
+
* Throws if no coordinates are found.
|
|
10
|
+
*/
|
|
11
|
+
function computeViewportHint(geometries) {
|
|
12
|
+
// Collect all coordinates (for bbox + elevation stats) and consecutive segment pairs
|
|
13
|
+
// (for the downhill bearing calculation).
|
|
14
|
+
const allCoords = [];
|
|
15
|
+
const bearingSegments = [];
|
|
16
|
+
for (const geom of geometries) {
|
|
17
|
+
collectGeometry(geom, allCoords, bearingSegments);
|
|
18
|
+
}
|
|
19
|
+
if (allCoords.length === 0)
|
|
20
|
+
throw new Error('computeViewportHint: no coordinates found in provided geometries');
|
|
21
|
+
let minLng = Infinity, maxLng = -Infinity;
|
|
22
|
+
let minLat = Infinity, maxLat = -Infinity;
|
|
23
|
+
for (const [lng, lat] of allCoords) {
|
|
24
|
+
if (lng < minLng)
|
|
25
|
+
minLng = lng;
|
|
26
|
+
if (lng > maxLng)
|
|
27
|
+
maxLng = lng;
|
|
28
|
+
if (lat < minLat)
|
|
29
|
+
minLat = lat;
|
|
30
|
+
if (lat > maxLat)
|
|
31
|
+
maxLat = lat;
|
|
32
|
+
}
|
|
33
|
+
const centerLng = (minLng + maxLng) / 2;
|
|
34
|
+
const centerLat = (minLat + maxLat) / 2;
|
|
35
|
+
// Weight each segment's downhill direction by length to find dominant bearing.
|
|
36
|
+
let sumSin = 0, sumCos = 0;
|
|
37
|
+
for (const [[lng0, lat0, elev0], [lng1, lat1, elev1]] of bearingSegments) {
|
|
38
|
+
if (elev0 === elev1)
|
|
39
|
+
continue;
|
|
40
|
+
const [fromLng, fromLat, toLng, toLat] = elev0 > elev1
|
|
41
|
+
? [lng0, lat0, lng1, lat1]
|
|
42
|
+
: [lng1, lat1, lng0, lat0];
|
|
43
|
+
const bear = greatCircleBearing(fromLat, fromLng, toLat, toLng);
|
|
44
|
+
const len = (0, distance_1.default)([lng0, lat0], [lng1, lat1], { units: 'meters' });
|
|
45
|
+
const bearingRad = (bear * Math.PI) / 180;
|
|
46
|
+
sumSin += Math.sin(bearingRad) * len;
|
|
47
|
+
sumCos += Math.cos(bearingRad) * len;
|
|
48
|
+
}
|
|
49
|
+
// Uphill bearing = downhill + 180°; null if no elevation variation found.
|
|
50
|
+
let mapBearing = null;
|
|
51
|
+
if (sumSin !== 0 || sumCos !== 0) {
|
|
52
|
+
const dominantDownhill = (Math.atan2(sumSin, sumCos) * 180) / Math.PI;
|
|
53
|
+
const normalizedDownhill = ((dominantDownhill % 360) + 360) % 360;
|
|
54
|
+
mapBearing = (normalizedDownhill + 180) % 360;
|
|
55
|
+
}
|
|
56
|
+
const metersPerDeg = 111320;
|
|
57
|
+
const cosLat = Math.cos(centerLat * (Math.PI / 180));
|
|
58
|
+
const bearingRad = ((mapBearing ?? 0) * Math.PI) / 180;
|
|
59
|
+
let elevationSum = 0;
|
|
60
|
+
for (const [, , elev] of allCoords)
|
|
61
|
+
elevationSum += elev;
|
|
62
|
+
const meanElevation = elevationSum / allCoords.length;
|
|
63
|
+
let minCameraX = Infinity, maxCameraX = -Infinity;
|
|
64
|
+
let minCameraY = Infinity, maxCameraY = -Infinity;
|
|
65
|
+
for (const [lng, lat, elev] of allCoords) {
|
|
66
|
+
const dx = (lng - centerLng) * cosLat * metersPerDeg;
|
|
67
|
+
const dy = (lat - centerLat) * metersPerDeg;
|
|
68
|
+
const cx = dx * Math.cos(bearingRad) - dy * Math.sin(bearingRad);
|
|
69
|
+
const cy = dx * Math.sin(bearingRad) + dy * Math.cos(bearingRad);
|
|
70
|
+
// At 45° pitch, elevation above mean shifts apparent Y by the same amount (tan 45° = 1).
|
|
71
|
+
const cyEffective = cy + (elev - meanElevation);
|
|
72
|
+
if (cx < minCameraX)
|
|
73
|
+
minCameraX = cx;
|
|
74
|
+
if (cx > maxCameraX)
|
|
75
|
+
maxCameraX = cx;
|
|
76
|
+
if (cyEffective < minCameraY)
|
|
77
|
+
minCameraY = cyEffective;
|
|
78
|
+
if (cyEffective > maxCameraY)
|
|
79
|
+
maxCameraY = cyEffective;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
center: [centerLng, centerLat],
|
|
83
|
+
bearing: mapBearing,
|
|
84
|
+
rotatedWidthMeters: maxCameraX - minCameraX,
|
|
85
|
+
rotatedHeightMeters: maxCameraY - minCameraY,
|
|
86
|
+
minCameraY,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Recursively extracts coordinates and segment pairs from a geometry. */
|
|
90
|
+
function collectGeometry(geom, allCoords, bearingSegments) {
|
|
91
|
+
switch (geom.type) {
|
|
92
|
+
case 'Point': {
|
|
93
|
+
const [lng, lat, elev = 0] = geom.coordinates;
|
|
94
|
+
allCoords.push([lng, lat, elev]);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'MultiPoint': {
|
|
98
|
+
for (const pos of geom.coordinates) {
|
|
99
|
+
const [lng, lat, elev = 0] = pos;
|
|
100
|
+
allCoords.push([lng, lat, elev]);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 'LineString':
|
|
105
|
+
collectPositions(geom.coordinates, allCoords, bearingSegments);
|
|
106
|
+
break;
|
|
107
|
+
case 'MultiLineString':
|
|
108
|
+
for (const line of geom.coordinates) {
|
|
109
|
+
collectPositions(line, allCoords, bearingSegments);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case 'Polygon':
|
|
113
|
+
for (const ring of geom.coordinates) {
|
|
114
|
+
collectPositions(ring, allCoords, bearingSegments);
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case 'MultiPolygon':
|
|
118
|
+
for (const polygon of geom.coordinates) {
|
|
119
|
+
for (const ring of polygon) {
|
|
120
|
+
collectPositions(ring, allCoords, bearingSegments);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'GeometryCollection':
|
|
125
|
+
for (const g of geom.geometries) {
|
|
126
|
+
collectGeometry(g, allCoords, bearingSegments);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Adds positions to allCoords and consecutive pairs to bearingSegments. Z defaults to 0. */
|
|
132
|
+
function collectPositions(positions, allCoords, bearingSegments) {
|
|
133
|
+
const elevated = positions.map(([lng, lat, elev = 0]) => [lng, lat, elev]);
|
|
134
|
+
for (const coord of elevated)
|
|
135
|
+
allCoords.push(coord);
|
|
136
|
+
for (let i = 0; i < elevated.length - 1; i++) {
|
|
137
|
+
bearingSegments.push([elevated[i], elevated[i + 1]]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Great-circle bearing from (lat1, lng1) to (lat2, lng2), in degrees 0–360. */
|
|
141
|
+
function greatCircleBearing(lat1, lng1, lat2, lng2) {
|
|
142
|
+
const toRad = (d) => (d * Math.PI) / 180;
|
|
143
|
+
const φ1 = toRad(lat1);
|
|
144
|
+
const φ2 = toRad(lat2);
|
|
145
|
+
const Δλ = toRad(lng2 - lng1);
|
|
146
|
+
const y = Math.sin(Δλ) * Math.cos(φ2);
|
|
147
|
+
const x = Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ);
|
|
148
|
+
return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=ViewportHint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewportHint.js","sourceRoot":"","sources":["../src/ViewportHint.ts"],"names":[],"mappings":";;AAuCA,kDAsFC;;AA5HD,sEAAqC;AAiCrC;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,UAA8B;IAE9B,qFAAqF;IACrF,0CAA0C;IAC1C,MAAM,SAAS,GAA+B,EAAE,CAAA;IAChD,MAAM,eAAe,GACnB,EAAE,CAAA;IAEJ,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IAE/G,IAAI,MAAM,GAAG,QAAQ,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AAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACrC,MAAM,CAAC,GACL,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC1E,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AACzD,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,4 +14,5 @@ tslib_1.__exportStar(require("./SnowCoverHistory"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./Source"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./Spot"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./Status"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./ViewportHint"), exports);
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,wDAA6B;AAC7B,iDAAsB;AACtB,8DAAmC;AACnC,kDAAuB;AACvB,gDAAqB;AACrB,oEAAyC;AACzC,8DAAmC;AACnC,oDAAyB;AACzB,6DAAkC;AAClC,mDAAwB;AACxB,iDAAsB;AACtB,mDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,wDAA6B;AAC7B,iDAAsB;AACtB,8DAAmC;AACnC,kDAAuB;AACvB,gDAAqB;AACrB,oEAAyC;AACzC,8DAAmC;AACnC,oDAAyB;AACzB,6DAAkC;AAClC,mDAAwB;AACxB,iDAAsB;AACtB,mDAAwB;AACxB,yDAA8B"}
|
package/package.json
CHANGED
package/src/Lift.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Source } from './Source'
|
|
|
7
7
|
import { LiftStationPosition, LiftStationSpotFeature } from './Spot'
|
|
8
8
|
import { Status } from './Status'
|
|
9
9
|
import { exhaustiveMatchingGuard } from './util/exhaustiveMatchingGuard'
|
|
10
|
+
import { ViewportHint } from './ViewportHint'
|
|
10
11
|
|
|
11
12
|
export type LiftFeature = GeoJSON.Feature<LiftGeometry, LiftProperties>
|
|
12
13
|
|
|
@@ -78,6 +79,7 @@ export type LiftProperties = {
|
|
|
78
79
|
websites: string[]
|
|
79
80
|
wikidataID: string | null
|
|
80
81
|
places: Place[]
|
|
82
|
+
viewportHint: ViewportHint
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
export enum LiftType {
|
package/src/Run.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { SnowCoverHistory } from './SnowCoverHistory'
|
|
|
13
13
|
import { Source } from './Source'
|
|
14
14
|
import { Status } from './Status'
|
|
15
15
|
import { exhaustiveMatchingGuard } from './util/exhaustiveMatchingGuard'
|
|
16
|
+
import { ViewportHint } from './ViewportHint'
|
|
16
17
|
|
|
17
18
|
export type RunGeometry = GeoJSON.LineString | GeoJSON.Polygon
|
|
18
19
|
|
|
@@ -88,6 +89,7 @@ export type RunProperties = {
|
|
|
88
89
|
wikidataID: string | null
|
|
89
90
|
places: Place[]
|
|
90
91
|
snowCoverHistory?: SnowCoverHistory
|
|
92
|
+
viewportHint: ViewportHint
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
export enum RunUse {
|
package/src/SkiArea.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { RunDifficultyConvention } from './RunDifficultyConvention'
|
|
|
6
6
|
import { SnowCoverHistory } from './SnowCoverHistory'
|
|
7
7
|
import { Source } from './Source'
|
|
8
8
|
import { Status } from './Status'
|
|
9
|
+
import { ViewportHint } from './ViewportHint'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* A ski area feature is derived from several sources:
|
|
@@ -58,6 +59,7 @@ export type SkiAreaProperties = SkiAreaSummaryProperties & {
|
|
|
58
59
|
websites: string[]
|
|
59
60
|
wikidataID: string | null
|
|
60
61
|
places: Place[]
|
|
62
|
+
viewportHint: ViewportHint
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export type SkiAreaSummaryProperties = {
|
package/src/Spot.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FeatureType } from './FeatureType'
|
|
|
3
3
|
import { Place } from './Place'
|
|
4
4
|
import { SkiAreaSummaryFeature } from './SkiArea'
|
|
5
5
|
import { Source } from './Source'
|
|
6
|
+
import { ViewportHint } from './ViewportHint'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A GeoJSON feature representing a spot (point of interest) in or around a ski area.
|
|
@@ -43,6 +44,7 @@ export type SpotBaseProperties = {
|
|
|
43
44
|
skiAreas: SkiAreaSummaryFeature[]
|
|
44
45
|
sources: Source[]
|
|
45
46
|
places: Place[]
|
|
47
|
+
viewportHint: ViewportHint
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
/**
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import * as GeoJSON from 'geojson'
|
|
2
|
+
import distance from '@turf/distance'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pre-computed viewport positioning data stored on every feature's properties.
|
|
6
|
+
* Camera space: Y axis points uphill (along bearing), X axis points screen-right.
|
|
7
|
+
* Metric values are in that rotated frame with elevation-adjusted Y positions
|
|
8
|
+
* (at 45° pitch, Δe metres above mean elevation shifts Y by Δe metres).
|
|
9
|
+
*/
|
|
10
|
+
export type ViewportHint = {
|
|
11
|
+
/** Geographic centre of the rotated bounding box as [lng, lat]. */
|
|
12
|
+
center: [number, number]
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Uphill bearing in degrees clockwise from north. null when elevation variation is
|
|
16
|
+
* insufficient to determine orientation — client should use top-down view (pitch 0, bearing 0).
|
|
17
|
+
*/
|
|
18
|
+
bearing: number | null
|
|
19
|
+
|
|
20
|
+
/** Bounding box width along the camera X axis, in metres. */
|
|
21
|
+
rotatedWidthMeters: number
|
|
22
|
+
|
|
23
|
+
/** Bounding box height along the camera Y axis, in metres (elevation-adjusted). */
|
|
24
|
+
rotatedHeightMeters: number
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Most-downhill edge of the elevation-adjusted bounding box in camera-Y metres, relative
|
|
28
|
+
* to mean feature elevation. Used to compute the perspective centre shift at 45° pitch:
|
|
29
|
+
* look-at point = minCameraY + nearFraction * rotatedHeightMeters, where
|
|
30
|
+
* nearFraction = nearGround / (nearGround + farGround) from camera pitch and vFOV.
|
|
31
|
+
*/
|
|
32
|
+
minCameraY: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Computes a ViewportHint from one or more GeoJSON geometries.
|
|
37
|
+
* All geometry types are accepted; elevation is read from the Z coordinate (defaults to 0).
|
|
38
|
+
* Throws if no coordinates are found.
|
|
39
|
+
*/
|
|
40
|
+
export function computeViewportHint(
|
|
41
|
+
geometries: GeoJSON.Geometry[],
|
|
42
|
+
): ViewportHint {
|
|
43
|
+
// Collect all coordinates (for bbox + elevation stats) and consecutive segment pairs
|
|
44
|
+
// (for the downhill bearing calculation).
|
|
45
|
+
const allCoords: [number, number, number][] = []
|
|
46
|
+
const bearingSegments: [[number, number, number], [number, number, number]][] =
|
|
47
|
+
[]
|
|
48
|
+
|
|
49
|
+
for (const geom of geometries) {
|
|
50
|
+
collectGeometry(geom, allCoords, bearingSegments)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (allCoords.length === 0) throw new Error('computeViewportHint: no coordinates found in provided geometries')
|
|
54
|
+
|
|
55
|
+
let minLng = Infinity,
|
|
56
|
+
maxLng = -Infinity
|
|
57
|
+
let minLat = Infinity,
|
|
58
|
+
maxLat = -Infinity
|
|
59
|
+
for (const [lng, lat] of allCoords) {
|
|
60
|
+
if (lng < minLng) minLng = lng
|
|
61
|
+
if (lng > maxLng) maxLng = lng
|
|
62
|
+
if (lat < minLat) minLat = lat
|
|
63
|
+
if (lat > maxLat) maxLat = lat
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const centerLng = (minLng + maxLng) / 2
|
|
67
|
+
const centerLat = (minLat + maxLat) / 2
|
|
68
|
+
|
|
69
|
+
// Weight each segment's downhill direction by length to find dominant bearing.
|
|
70
|
+
let sumSin = 0,
|
|
71
|
+
sumCos = 0
|
|
72
|
+
for (const [[lng0, lat0, elev0], [lng1, lat1, elev1]] of bearingSegments) {
|
|
73
|
+
if (elev0 === elev1) continue
|
|
74
|
+
const [fromLng, fromLat, toLng, toLat] =
|
|
75
|
+
elev0 > elev1
|
|
76
|
+
? [lng0, lat0, lng1, lat1]
|
|
77
|
+
: [lng1, lat1, lng0, lat0]
|
|
78
|
+
const bear = greatCircleBearing(fromLat, fromLng, toLat, toLng)
|
|
79
|
+
const len = distance([lng0, lat0], [lng1, lat1], { units: 'meters' })
|
|
80
|
+
const bearingRad = (bear * Math.PI) / 180
|
|
81
|
+
sumSin += Math.sin(bearingRad) * len
|
|
82
|
+
sumCos += Math.cos(bearingRad) * len
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Uphill bearing = downhill + 180°; null if no elevation variation found.
|
|
86
|
+
let mapBearing: number | null = null
|
|
87
|
+
if (sumSin !== 0 || sumCos !== 0) {
|
|
88
|
+
const dominantDownhill = (Math.atan2(sumSin, sumCos) * 180) / Math.PI
|
|
89
|
+
const normalizedDownhill = ((dominantDownhill % 360) + 360) % 360
|
|
90
|
+
mapBearing = (normalizedDownhill + 180) % 360
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const metersPerDeg = 111320
|
|
94
|
+
const cosLat = Math.cos(centerLat * (Math.PI / 180))
|
|
95
|
+
const bearingRad = ((mapBearing ?? 0) * Math.PI) / 180
|
|
96
|
+
|
|
97
|
+
let elevationSum = 0
|
|
98
|
+
for (const [, , elev] of allCoords) elevationSum += elev
|
|
99
|
+
const meanElevation = elevationSum / allCoords.length
|
|
100
|
+
|
|
101
|
+
let minCameraX = Infinity,
|
|
102
|
+
maxCameraX = -Infinity
|
|
103
|
+
let minCameraY = Infinity,
|
|
104
|
+
maxCameraY = -Infinity
|
|
105
|
+
|
|
106
|
+
for (const [lng, lat, elev] of allCoords) {
|
|
107
|
+
const dx = (lng - centerLng) * cosLat * metersPerDeg
|
|
108
|
+
const dy = (lat - centerLat) * metersPerDeg
|
|
109
|
+
const cx = dx * Math.cos(bearingRad) - dy * Math.sin(bearingRad)
|
|
110
|
+
const cy = dx * Math.sin(bearingRad) + dy * Math.cos(bearingRad)
|
|
111
|
+
// At 45° pitch, elevation above mean shifts apparent Y by the same amount (tan 45° = 1).
|
|
112
|
+
const cyEffective = cy + (elev - meanElevation)
|
|
113
|
+
if (cx < minCameraX) minCameraX = cx
|
|
114
|
+
if (cx > maxCameraX) maxCameraX = cx
|
|
115
|
+
if (cyEffective < minCameraY) minCameraY = cyEffective
|
|
116
|
+
if (cyEffective > maxCameraY) maxCameraY = cyEffective
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
center: [centerLng, centerLat],
|
|
121
|
+
bearing: mapBearing,
|
|
122
|
+
rotatedWidthMeters: maxCameraX - minCameraX,
|
|
123
|
+
rotatedHeightMeters: maxCameraY - minCameraY,
|
|
124
|
+
minCameraY,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Recursively extracts coordinates and segment pairs from a geometry. */
|
|
129
|
+
function collectGeometry(
|
|
130
|
+
geom: GeoJSON.Geometry,
|
|
131
|
+
allCoords: [number, number, number][],
|
|
132
|
+
bearingSegments: [[number, number, number], [number, number, number]][],
|
|
133
|
+
): void {
|
|
134
|
+
switch (geom.type) {
|
|
135
|
+
case 'Point': {
|
|
136
|
+
const [lng, lat, elev = 0] = geom.coordinates
|
|
137
|
+
allCoords.push([lng, lat, elev])
|
|
138
|
+
break
|
|
139
|
+
}
|
|
140
|
+
case 'MultiPoint': {
|
|
141
|
+
for (const pos of geom.coordinates) {
|
|
142
|
+
const [lng, lat, elev = 0] = pos
|
|
143
|
+
allCoords.push([lng, lat, elev])
|
|
144
|
+
}
|
|
145
|
+
break
|
|
146
|
+
}
|
|
147
|
+
case 'LineString':
|
|
148
|
+
collectPositions(geom.coordinates, allCoords, bearingSegments)
|
|
149
|
+
break
|
|
150
|
+
case 'MultiLineString':
|
|
151
|
+
for (const line of geom.coordinates) {
|
|
152
|
+
collectPositions(line, allCoords, bearingSegments)
|
|
153
|
+
}
|
|
154
|
+
break
|
|
155
|
+
case 'Polygon':
|
|
156
|
+
for (const ring of geom.coordinates) {
|
|
157
|
+
collectPositions(ring, allCoords, bearingSegments)
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
case 'MultiPolygon':
|
|
161
|
+
for (const polygon of geom.coordinates) {
|
|
162
|
+
for (const ring of polygon) {
|
|
163
|
+
collectPositions(ring, allCoords, bearingSegments)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
break
|
|
167
|
+
case 'GeometryCollection':
|
|
168
|
+
for (const g of geom.geometries) {
|
|
169
|
+
collectGeometry(g, allCoords, bearingSegments)
|
|
170
|
+
}
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Adds positions to allCoords and consecutive pairs to bearingSegments. Z defaults to 0. */
|
|
176
|
+
function collectPositions(
|
|
177
|
+
positions: GeoJSON.Position[],
|
|
178
|
+
allCoords: [number, number, number][],
|
|
179
|
+
bearingSegments: [[number, number, number], [number, number, number]][],
|
|
180
|
+
): void {
|
|
181
|
+
const elevated: [number, number, number][] = positions.map(
|
|
182
|
+
([lng, lat, elev = 0]) => [lng, lat, elev],
|
|
183
|
+
)
|
|
184
|
+
for (const coord of elevated) allCoords.push(coord)
|
|
185
|
+
for (let i = 0; i < elevated.length - 1; i++) {
|
|
186
|
+
bearingSegments.push([elevated[i], elevated[i + 1]])
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Great-circle bearing from (lat1, lng1) to (lat2, lng2), in degrees 0–360. */
|
|
191
|
+
function greatCircleBearing(
|
|
192
|
+
lat1: number,
|
|
193
|
+
lng1: number,
|
|
194
|
+
lat2: number,
|
|
195
|
+
lng2: number,
|
|
196
|
+
): number {
|
|
197
|
+
const toRad = (d: number) => (d * Math.PI) / 180
|
|
198
|
+
const φ1 = toRad(lat1)
|
|
199
|
+
const φ2 = toRad(lat2)
|
|
200
|
+
const Δλ = toRad(lng2 - lng1)
|
|
201
|
+
const y = Math.sin(Δλ) * Math.cos(φ2)
|
|
202
|
+
const x =
|
|
203
|
+
Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ)
|
|
204
|
+
return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360
|
|
205
|
+
}
|
package/src/index.ts
CHANGED