openskidata-format 0.15.0 → 2.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/SkiArea.d.ts CHANGED
@@ -1,39 +1,76 @@
1
- import { Activity } from './Activity';
2
1
  import { FeatureType } from './FeatureType';
3
2
  import { LiftType } from './Lift';
4
3
  import { Location } from './Location';
5
- import { RunConvention, RunDifficulty } from './Run';
6
- import Source from './Source';
4
+ import { RunDifficulty, RunDifficultyConvention } from './Run';
5
+ import { Source } from './Source';
7
6
  import { Status } from './Status';
7
+ /**
8
+ * A ski area feature is derived from several sources:
9
+ * - OpenStreetMap site=piste relations
10
+ * - OpenStreetMap landuse=winter_sports areas that contains ski runs
11
+ * - Skimap.org ski areas
12
+ *
13
+ * The processor attempts to merge the data of all sources to create a single ski area feature.
14
+ *
15
+ * In some cases merging may fail and duplicate ski areas will be produced. This is likely due to ambiguous data.
16
+ * Check:
17
+ * - that a site=piste relation contains all the lifts/runs. If many lifts/runs are missing, merging will fail.
18
+ * - that if there are multiple landuse=winter_sports areas representing a single ski area. In this case a multipolygon relation should be used.
19
+ * - that if there are multiple Skimap.org ski areas representing a single ski area.
20
+ *
21
+ * General recommendation for ski area tagging in OpenStreetMap:
22
+ * - start with a landuse=winter_sports area as it's easy to set up and maintain.
23
+ * - if that's not explicit enough, add a site=piste relation as well.
24
+ *
25
+ * Note: if runs are present but there is no associated ski area source, a ski area feature is generated with no name and no source.
26
+ */
8
27
  export type SkiAreaFeature = GeoJSON.Feature<SkiAreaGeometry, SkiAreaProperties>;
9
28
  export type SkiAreaGeometry = GeoJSON.Point | GeoJSON.Polygon | GeoJSON.MultiPolygon;
10
- export interface SkiAreaProperties {
11
- type: FeatureType.SkiArea;
12
- id: string;
13
- name: string | null;
29
+ export type SkiAreaSummaryFeature = GeoJSON.Feature<SkiAreaGeometry, SkiAreaSummaryProperties>;
30
+ /**
31
+ * @property {string} id - Unique identifier for the ski area. The ID is just a hash of the feature, so will change if the feature changes in any way. If a stable identifier is needed, use the wikidata_id property, or a source id.
32
+ * @property {string | null} name - Name of the ski area.
33
+ * @property {Source[]} sources - Data sources.
34
+ * @property {SkiAreaActivity[]} activities - Activities available at this ski area, derived from presence of ski runs and Skimap.org data.
35
+ * @property {SkiAreaStatistics} statistics - Statistics generated from associated runs / lifts.
36
+ * @property {Status | null} status - Operational status. Derived from OpenStreetMap lifecycle tags and Skimap.org data.
37
+ * @property {RunColorConvention} runConvention - Color convention used for runs at this ski area.
38
+ * @property {string[]} websites - Official website(s) of the ski area. Derived from the OpenStreetMap website tag and Skimap.org data.
39
+ * @property {string | null} wikidata_id - Wikidata identifier. Derived from the OpenStreetMap wikidata tag.
40
+ * @property {Location | null} location - Reverse geocoded country / region information.
41
+ */
42
+ export type SkiAreaProperties = SkiAreaSummaryProperties & {
14
43
  sources: Source[];
15
- activities: Activity[];
16
- generated: boolean;
17
44
  statistics?: SkiAreaStatistics;
18
- status: Status | null;
19
- runConvention: RunConvention;
45
+ runConvention: RunDifficultyConvention;
20
46
  websites: string[];
21
47
  wikidata_id: string | null;
48
+ };
49
+ export type SkiAreaSummaryProperties = {
50
+ type: FeatureType.SkiArea;
51
+ id: string;
52
+ name: string | null;
53
+ activities: SkiAreaActivity[];
54
+ status: Status | null;
22
55
  location: Location | null;
56
+ };
57
+ export declare enum SkiAreaActivity {
58
+ Downhill = "downhill",
59
+ Nordic = "nordic"
23
60
  }
24
- export interface SkiAreaStatistics {
61
+ export type SkiAreaStatistics = {
25
62
  runs: RunStatistics;
26
63
  lifts: LiftStatistics;
27
64
  minElevation?: number;
28
65
  maxElevation?: number;
29
- }
30
- export interface RunStatistics {
66
+ };
67
+ export type RunStatistics = {
31
68
  minElevation?: number;
32
69
  maxElevation?: number;
33
70
  byActivity: RunStatisticsByActivityAndDifficulty;
34
- }
71
+ };
35
72
  export type RunStatisticsByActivityAndDifficulty = {
36
- [key in Activity | 'other']?: {
73
+ [key in SkiAreaActivity | 'other']?: {
37
74
  byDifficulty: RunStatisticsByDifficulty;
38
75
  };
39
76
  };
@@ -43,11 +80,11 @@ export type RunStatisticsByDifficulty = {
43
80
  lengthInKm: number;
44
81
  };
45
82
  };
46
- export interface LiftStatistics {
83
+ export type LiftStatistics = {
47
84
  minElevation?: number;
48
85
  maxElevation?: number;
49
86
  byType: LiftStatisticsByType;
50
- }
87
+ };
51
88
  export type LiftStatisticsByTypeKey = LiftType | 'other';
52
89
  export type LiftStatisticsByType = {
53
90
  [key in LiftStatisticsByTypeKey]?: {
@@ -55,10 +92,3 @@ export type LiftStatisticsByType = {
55
92
  lengthInKm: number;
56
93
  };
57
94
  };
58
- export interface MapObjectStatistics {
59
- count: number;
60
- lengthInKm: number;
61
- minElevation?: number;
62
- maxElevation?: number;
63
- combinedElevationChange?: number;
64
- }
package/dist/SkiArea.js CHANGED
@@ -1,3 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkiAreaActivity = void 0;
4
+ var SkiAreaActivity;
5
+ (function (SkiAreaActivity) {
6
+ SkiAreaActivity["Downhill"] = "downhill";
7
+ SkiAreaActivity["Nordic"] = "nordic";
8
+ })(SkiAreaActivity || (exports.SkiAreaActivity = SkiAreaActivity = {}));
3
9
  //# sourceMappingURL=SkiArea.js.map
@@ -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":";;;AAoEA,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,wCAAqB,CAAA;IACrB,oCAAiB,CAAA;AACnB,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B"}
package/dist/Source.d.ts CHANGED
@@ -2,7 +2,7 @@ export declare enum SourceType {
2
2
  SKIMAP_ORG = "skimap.org",
3
3
  OPENSTREETMAP = "openstreetmap"
4
4
  }
5
- export default interface Source {
5
+ export type Source = {
6
6
  type: SourceType;
7
7
  id: string;
8
- }
8
+ };
package/dist/Status.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Status of a feature.
3
+ *
4
+ * Note that this is not real-time status but indicates whether a feature is in operation when conditions permit or is abandoned, etc.
5
+ *
6
+ * Primarily derived from OpenStreetMap tags.
7
+ * Additionally, Skimap.org data provides status information for ski area features only.
8
+ *
9
+ * Tagging schemes supported are:
10
+ * - lifecycle prefixes (preferred) https://wiki.openstreetmap.org/wiki/Lifecycle_prefix
11
+ * - separate lifecycle tags ("proposed=yes", etc)
12
+ */
1
13
  export declare enum Status {
2
14
  Operating = "operating",
3
15
  Disused = "disused",
package/dist/Status.js CHANGED
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Status = void 0;
4
+ /**
5
+ * Status of a feature.
6
+ *
7
+ * Note that this is not real-time status but indicates whether a feature is in operation when conditions permit or is abandoned, etc.
8
+ *
9
+ * Primarily derived from OpenStreetMap tags.
10
+ * Additionally, Skimap.org data provides status information for ski area features only.
11
+ *
12
+ * Tagging schemes supported are:
13
+ * - lifecycle prefixes (preferred) https://wiki.openstreetmap.org/wiki/Lifecycle_prefix
14
+ * - separate lifecycle tags ("proposed=yes", etc)
15
+ */
4
16
  var Status;
5
17
  (function (Status) {
6
18
  Status["Operating"] = "operating";
@@ -1 +1 @@
1
- {"version":3,"file":"Status.js","sourceRoot":"","sources":["../src/Status.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAOX;AAPD,WAAY,MAAM;IAChB,iCAAuB,CAAA;IACvB,6BAAmB,CAAA;IACnB,iCAAuB,CAAA;IACvB,+BAAqB,CAAA;IACrB,6BAAmB,CAAA;IACnB,uCAA6B,CAAA;AAC/B,CAAC,EAPW,MAAM,sBAAN,MAAM,QAOjB"}
1
+ {"version":3,"file":"Status.js","sourceRoot":"","sources":["../src/Status.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,IAAY,MAOX;AAPD,WAAY,MAAM;IAChB,iCAAuB,CAAA;IACvB,6BAAmB,CAAA;IACnB,iCAAuB,CAAA;IACvB,+BAAqB,CAAA;IACrB,6BAAmB,CAAA;IACnB,uCAA6B,CAAA;AAC/B,CAAC,EAPW,MAAM,sBAAN,MAAM,QAOjB"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './Activity';
2
1
  export * from './ElevationProfile';
3
2
  export * from './FeatureType';
4
3
  export * from './Lift';
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./Activity"), exports);
5
4
  tslib_1.__exportStar(require("./ElevationProfile"), exports);
6
5
  tslib_1.__exportStar(require("./FeatureType"), exports);
7
6
  tslib_1.__exportStar(require("./Lift"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,6DAAkC;AAClC,wDAA6B;AAC7B,iDAAsB;AACtB,8DAAmC;AACnC,qDAA0B;AAC1B,gDAAqB;AACrB,oDAAyB;AACzB,mDAAwB;AACxB,mDAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,wDAA6B;AAC7B,iDAAsB;AACtB,8DAAmC;AACnC,qDAA0B;AAC1B,gDAAqB;AACrB,oDAAyB;AACzB,mDAAwB;AACxB,mDAAwB"}
@@ -0,0 +1 @@
1
+ export declare const exhaustiveMatchingGuard: (value: never) => never;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exhaustiveMatchingGuard = void 0;
4
+ const exhaustiveMatchingGuard = (value) => {
5
+ throw new Error(`Unhandled case: ${value}`);
6
+ };
7
+ exports.exhaustiveMatchingGuard = exhaustiveMatchingGuard;
8
+ //# sourceMappingURL=exhaustiveMatchingGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exhaustiveMatchingGuard.js","sourceRoot":"","sources":["../../src/util/exhaustiveMatchingGuard.ts"],"names":[],"mappings":";;;AAAO,MAAM,uBAAuB,GAAG,CAAC,KAAY,EAAS,EAAE;IAC7D,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,EAAE,CAAC,CAAA;AAC7C,CAAC,CAAA;AAFY,QAAA,uBAAuB,2BAEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openskidata-format",
3
- "version": "0.15.0",
3
+ "version": "2.0.0",
4
4
  "description": "Data format for OpenSkiMap.org",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,8 +1,12 @@
1
- export interface ElevationProfile {
2
- // Heights are evenly distributed along the LineString with a frequency based on the resolution below.
3
- // The final height corresponds to the end of the LineString and will not be the same space between the previous point as the rest.
4
- // The corresponding coordinates can be computed from the original geometry using Turf.js: `turf.lineChunk(geometry, resolution, {units: 'meters'});`
1
+ /**
2
+ * Represents an elevation profile with evenly distributed height measurements along a LineString.
3
+ *
4
+ * @property {number[]} heights - Array of height measurements in meters. These heights are sampled at regular intervals along the LineString,
5
+ * except for the final height which corresponds to the LineString endpoint and may have a different spacing.
6
+ * Height values can be mapped to geographical coordinates using Turf.js: `turf.lineChunk(geometry, resolution, {units: 'meters'})`.
7
+ * @property {number} resolution - The horizontal sampling distance in meters between consecutive height measurements.
8
+ */
9
+ export type ElevationProfile = {
5
10
  heights: number[]
6
- // Horizontal resolution in meters of the profile
7
11
  resolution: number
8
12
  }
package/src/Lift.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Location, SkiAreaFeature } from '.'
2
1
  import { FeatureType } from './FeatureType'
3
- import Source from './Source'
2
+ import { SkiAreaSummaryFeature } from './SkiArea'
3
+ import { Source } from './Source'
4
4
  import { Status } from './Status'
5
+ import { exhaustiveMatchingGuard } from './util/exhaustiveMatchingGuard'
5
6
 
6
7
  export type LiftFeature = GeoJSON.Feature<LiftGeometry, LiftProperties>
7
8
 
@@ -13,12 +14,41 @@ export type LiftGeometry =
13
14
  | GeoJSON.Polygon
14
15
  | GeoJSON.MultiPolygon
15
16
 
17
+ /**
18
+ * A feature representing a ski lift.
19
+ *
20
+ * Lifts are derived from OpenStreetMap aerialway/railway features that are commonly used for winter sports.
21
+ *
22
+ * Note:
23
+ * - Private lifts are not included in this dataset.
24
+ * - Rack railways are included only if they are part of a site=piste relation.
25
+ * - Some lifts included in the dataset may be for other purposes (amusement parks, etc).
26
+ *
27
+ * Properties:
28
+ * @property {FeatureType.Lift} type - The feature type, which is always 'Lift'.
29
+ * @property {string} id - Unique identifier for the lift. The ID is just a hash of the feature, so will change if the feature changes in any way.
30
+ * @property {LiftType} liftType - Type of lift (e.g. chair_lift, gondola). Derived from OpenStreetMap aerialway/railway tags.
31
+ * @property {Status} status - Operational status of the lift. Derived from OpenStreetMap lifecycle tags.
32
+ * @property {string | null} name - Name of the lift. Derived from the OpenStreetMap name tag.
33
+ * @property {string | null} ref - Reference code/number for the lift. Derived from the OpenStreetMap ref tag.
34
+ * @property {string | null} description - Description of the lift. Derived from the OpenStreetMap description tag.
35
+ * @property {boolean | null} oneway - Whether the lift allows riding only in one direction. Derived from the OpenStreetMap oneway tag.
36
+ * @property {number | null} occupancy - Number of people each carrier can transport. Derived from the OpenStreetMap aerialway:occupancy tag.
37
+ * @property {number | null} capacity - Transport capacity in persons/hour. Derived from the OpenStreetMap aerialway:capacity tag.
38
+ * @property {number | null} duration - Duration of lift ride in seconds. Derived from the OpenStreetMap aerialway:duration tag.
39
+ * @property {boolean | null} detachable - Whether the lift has detachable grips. Derived from the OpenStreetMap aerialway:detachable tag.
40
+ * @property {boolean | null} bubble - Whether the lift has bubbles/covers to protect from weather. Derived from the OpenStreetMap aerialway:bubble tag.
41
+ * @property {boolean | null} heating - Whether the lift has heated carriers/seats. Derived from the OpenStreetMap aerialway:heating tag.
42
+ * @property {SkiAreaSummaryFeature[]} skiAreas - Ski areas this lift is a part of.
43
+ * @property {Source[]} sources - Data sources for the feature.
44
+ * @property {string[]} websites - Websites associated with this lift. Derived from the OpenStreetMap website tag.
45
+ * @property {string | null} wikidata_id - Wikidata identifier. Derived from the OpenStreetMap wikidata tag.
46
+ */
16
47
  export type LiftProperties = {
17
48
  type: FeatureType.Lift
18
49
  id: string
19
50
  liftType: LiftType
20
51
  status: Status
21
- color: string
22
52
  name: string | null
23
53
  ref: string | null
24
54
  description: string | null
@@ -26,11 +56,11 @@ export type LiftProperties = {
26
56
  occupancy: number | null
27
57
  capacity: number | null
28
58
  duration: number | null
59
+ detachable: boolean | null
29
60
  bubble: boolean | null
30
61
  heating: boolean | null
31
- skiAreas: SkiAreaFeature[]
62
+ skiAreas: SkiAreaSummaryFeature[]
32
63
  sources: Source[]
33
- location: Location | null
34
64
  websites: string[]
35
65
  wikidata_id: string | null
36
66
  }
@@ -76,5 +106,25 @@ export function getFormattedLiftType(liftType: LiftType): string {
76
106
  return 'Funicular'
77
107
  case LiftType.RackRailway:
78
108
  return 'Rack Railway'
109
+ default:
110
+ return exhaustiveMatchingGuard(liftType)
111
+ }
112
+ }
113
+
114
+ export function getLiftColor(status: Status): string {
115
+ const BRIGHT_RED_COLOR = 'hsl(0, 82%, 42%)'
116
+ const DIM_RED_COLOR = 'hsl(0, 53%, 42%)'
117
+
118
+ switch (status) {
119
+ case Status.Disused:
120
+ case Status.Abandoned:
121
+ return DIM_RED_COLOR
122
+ case Status.Proposed:
123
+ case Status.Planned:
124
+ case Status.Construction:
125
+ case Status.Operating:
126
+ return BRIGHT_RED_COLOR
127
+ default:
128
+ return exhaustiveMatchingGuard(status)
79
129
  }
80
130
  }
@@ -1,5 +1,4 @@
1
- import { LiftProperties, LiftType } from '.'
2
- import { getFormattedLiftType } from './Lift'
1
+ import { LiftProperties, LiftType, getFormattedLiftType } from './Lift'
3
2
 
4
3
  export function getLiftNameAndType(properties: LiftProperties) {
5
4
  const name = properties.name
@@ -7,7 +6,7 @@ export function getLiftNameAndType(properties: LiftProperties) {
7
6
  const liftType = getAugmentedLiftType(properties)
8
7
 
9
8
  if (name && liftType) {
10
- return name + ' (' + liftType + ')'
9
+ return `${name} (${liftType})`
11
10
  } else if (name) {
12
11
  return name
13
12
  } else {
@@ -54,15 +53,11 @@ function getAugmentedLiftType(properties: LiftProperties): string | null {
54
53
  }
55
54
 
56
55
  function formattedDuration(duration: number): string {
57
- let minutes: string | number = Math.floor(duration / 60)
58
- let seconds: string | number = duration - minutes * 60
59
- if (minutes < 10) {
60
- minutes = '0' + minutes
61
- }
62
- if (seconds < 10) {
63
- seconds = '0' + seconds
64
- }
65
- return minutes + ':' + seconds
56
+ const minutes = Math.floor(duration / 60)
57
+ .toString()
58
+ .padStart(2, '0')
59
+ const seconds = (duration % 60).toString().padStart(2, '0')
60
+ return `${minutes}:${seconds}`
66
61
  }
67
62
 
68
63
  function implicitOccupancyLiftType(properties: LiftProperties): string | null {
@@ -130,9 +125,7 @@ function containsAny(input: string | null, lowerCaseSearchList: string[]) {
130
125
  }
131
126
 
132
127
  const lowerCaseInput = input.toLowerCase()
133
- return (
134
- lowerCaseSearchList.findIndex((searchItem) => {
135
- return lowerCaseInput.includes(searchItem)
136
- }) !== -1
137
- )
128
+ return lowerCaseSearchList.some((searchItem) => {
129
+ return lowerCaseInput.includes(searchItem)
130
+ })
138
131
  }
package/src/Run.ts CHANGED
@@ -1,15 +1,55 @@
1
1
  import * as GeoJSON from 'geojson'
2
2
  import { ElevationProfile } from './ElevationProfile'
3
3
  import { FeatureType } from './FeatureType'
4
- import { Location } from './Location'
5
- import { SkiAreaFeature } from './SkiArea'
6
- import Source from './Source'
4
+ import { SkiAreaSummaryFeature } from './SkiArea'
5
+ import { Source } from './Source'
7
6
  import { Status } from './Status'
7
+ import { exhaustiveMatchingGuard } from './util/exhaustiveMatchingGuard'
8
8
 
9
9
  export type RunGeometry = GeoJSON.LineString | GeoJSON.Polygon
10
10
 
11
+ /**
12
+ * Represents a segment of a ski run/trail.
13
+ *
14
+ * Runs are derived from OpenStreetMap pistes, which are defined as all ways/areas/relations containing a "piste:type" tag.
15
+ * Piste relations support is limited, it is only used to enhance the data of its member ways. There is no way to access the relation itself in the output data.
16
+ *
17
+ * A single run as marked on the mountain may be broken up into several run features, especially if the run has branches, or changes in tags (e.g. difficulty, use).
18
+ *
19
+ * In the future, there might be a "Route" entity introduced to represent a whole run, which would be composed of multiple run features.
20
+ *
21
+ * Note: winter hiking trails and trails of other winter sports disciplines are also included in this dataset.
22
+ *
23
+ * In postprocessing:
24
+ * - overlapping ways are merged into a single run feature with multiple uses.
25
+ * - connected run segments with the same properties are merged into a single run feature.
26
+ */
11
27
  export type RunFeature = GeoJSON.Feature<RunGeometry, RunProperties>
12
28
 
29
+ /**
30
+ * Represents the properties of a ski run.
31
+ *
32
+ * Properties:
33
+ * @property {FeatureType.Run} type - The feature type, which is always 'Run'.
34
+ * @property {RunUse[]} uses - Use types for the run (e.g. downhill, nordic), derived from OpenStreetMap "piste:type" tags.
35
+ * @property {string} id - Unique identifier for the run. The ID is just a hash of the feature, so will change if the feature changes in any way.
36
+ * @property {string | null} name - Name of the run, if available
37
+ * @property {string | null} ref - Reference code/number for the run. Derived from the OpenStreetMap piste:ref and ref tags.
38
+ * @property {Status} status - Operational status. Note: as only operational runs are included in this dataset, this will always be 'operating'.
39
+ * @property {string | null} description - Description of the run, derived from the OpenStreetMap "piste:description" or "description" tag.
40
+ * @property {RunDifficulty | null} difficulty - Difficulty rating of the run, derived from the OpenStreetMap "piste:difficulty" tag
41
+ * @property {RunDifficultyConvention} difficultyConvention - Regional convention used for representing run difficulty. Derived from location.
42
+ * @property {boolean | null} oneway - Whether the run is one-way only, derived from the OpenStreetMap "piste:oneway" or "oneway" tag, in addition to defaults based on run use.
43
+ * @property {boolean | null} lit - Whether the run has lighting for night skiing, derived from the OpenStreetMap "piste:lit" or "lit" tag.
44
+ * @property {boolean | null} gladed - Whether the run is through gladed/tree terrain, derived from the OpenStreetMap "piste:gladed" or "gladed" tag.
45
+ * @property {boolean | null} patrolled - Whether the run is patrolled by ski patrol, derived from the OpenStreetMap "piste:patrolled" or "patrolled" tag.
46
+ * @property {RunGrooming | null} grooming - Grooming status/type of the run, derived from the OpenStreetMap "piste:grooming" tag. If not specified explicitly, for difficulties "expert", "freeride", and "extreme", grooming is assumed to be "backcountry".
47
+ * @property {SkiAreaSummaryFeature[]} skiAreas - Ski areas this run belongs to. Derived from the OpenStreetMap site=piste relation or landuse=winter_sports area and proximity to ski area features. Runs with "backcountry" grooming are not associated with ski areas unless they have a "piste:patrolled=yes" or "patrolled=yes" OpenStreetMap tag, or are part of a "site=piste" ski area relation.
48
+ * @property {ElevationProfile | null} elevationProfile - Elevation profile of the run, only available for runs with LineString geometry.
49
+ * @property {Source[]} sources - Data sources for this run's information
50
+ * @property {string[]} websites - Websites associated with this run, derived from the OpenStreetMap website tag
51
+ * @property {string | null} wikidata_id - Wikidata identifier, if available, derived from the OpenStreetMap wikidata tag
52
+ */
13
53
  export type RunProperties = {
14
54
  type: FeatureType.Run
15
55
  uses: RunUse[]
@@ -19,18 +59,15 @@ export type RunProperties = {
19
59
  status: Status
20
60
  description: string | null
21
61
  difficulty: RunDifficulty | null
22
- convention: RunConvention
62
+ difficultyConvention: RunDifficultyConvention
23
63
  oneway: boolean | null
24
64
  lit: boolean | null
25
65
  gladed: boolean | null
26
66
  patrolled: boolean | null
27
- color: string
28
- colorName: ColorName
29
67
  grooming: RunGrooming | null
30
- skiAreas: SkiAreaFeature[]
68
+ skiAreas: SkiAreaSummaryFeature[]
31
69
  elevationProfile: ElevationProfile | null
32
70
  sources: Source[]
33
- location: Location | null
34
71
  websites: string[]
35
72
  wikidata_id: string | null
36
73
  }
@@ -68,7 +105,7 @@ export enum RunDifficulty {
68
105
  EXTREME = 'extreme',
69
106
  }
70
107
 
71
- export enum ColorName {
108
+ export enum RunColorName {
72
109
  GREEN = 'green',
73
110
  BLUE = 'blue',
74
111
  RED = 'red',
@@ -77,92 +114,130 @@ export enum ColorName {
77
114
  GREY = 'grey',
78
115
  }
79
116
 
80
- export enum RunConvention {
117
+ export enum RunColorValue {
118
+ GREEN = 'hsl(125, 100%, 33%)',
119
+ BLUE = 'hsl(208, 100%, 33%)',
120
+ RED = 'hsl(359, 94%, 53%)',
121
+ BLACK = 'hsl(0, 0%, 0%)',
122
+ ORANGE = 'hsl(34, 100%, 50%)',
123
+ GREY = 'hsl(0, 0%, 35%)',
124
+ }
125
+
126
+ /**
127
+ * Run difficulty colors vary by region. This enum defines the color convention used for runs at a ski area.
128
+ * @enum {string}
129
+ */
130
+ export enum RunDifficultyConvention {
131
+ /**
132
+ * European color convention:
133
+ * - Green: Novice
134
+ * - Blue: Easy
135
+ * - Red: Intermediate
136
+ * - Black: Advanced/Expert
137
+ * - Orange: Freeride/Extreme
138
+ */
81
139
  EUROPE = 'europe',
140
+
141
+ /**
142
+ * Japanese color convention:
143
+ * - Green: Novice/Easy
144
+ * - Red: Intermediate
145
+ * - Black: Advanced/Expert
146
+ * - Orange: Freeride/Extreme
147
+ */
82
148
  JAPAN = 'japan',
149
+
150
+ /**
151
+ * North American color convention:
152
+ * - Green: Novice/Easy
153
+ * - Blue: Intermediate
154
+ * - Black: Advanced/Expert
155
+ * - Orange: Freeride/Extreme
156
+ */
83
157
  NORTH_AMERICA = 'north_america',
84
158
  }
85
159
 
86
- // When adding a new color, add a supplemental oneway icon on the map style
87
- const GREEN_COLOR = 'hsl(125, 100%, 33%)'
88
- const BLUE_COLOR = 'hsl(208, 100%, 33%)'
89
- const RED_COLOR = 'hsl(359, 94%, 53%)'
90
- const BLACK_COLOR = 'hsl(0, 0%, 0%)'
91
- const ORANGE_COLOR = 'hsl(34, 100%, 50%)'
92
- const GREY_COLOR = 'hsl(0, 0%, 35%)'
160
+ export function getRunColor(
161
+ convention: RunDifficultyConvention,
162
+ difficulty: RunDifficulty | null,
163
+ ): RunColorValue {
164
+ return runColorNameToValue(getRunColorName(convention, difficulty))
165
+ }
93
166
 
94
- export function getColorName(color: string): ColorName {
167
+ export function runColorNameToValue(color: RunColorName): RunColorValue {
95
168
  switch (color) {
96
- case GREEN_COLOR:
97
- return ColorName.GREEN
98
- case BLUE_COLOR:
99
- return ColorName.BLUE
100
- case RED_COLOR:
101
- return ColorName.RED
102
- case BLACK_COLOR:
103
- return ColorName.BLACK
104
- case ORANGE_COLOR:
105
- return ColorName.ORANGE
106
- case GREY_COLOR:
107
- return ColorName.GREY
169
+ case RunColorName.GREEN:
170
+ return RunColorValue.GREEN
171
+ case RunColorName.BLUE:
172
+ return RunColorValue.BLUE
173
+ case RunColorName.RED:
174
+ return RunColorValue.RED
175
+ case RunColorName.BLACK:
176
+ return RunColorValue.BLACK
177
+ case RunColorName.ORANGE:
178
+ return RunColorValue.ORANGE
179
+ case RunColorName.GREY:
180
+ return RunColorValue.GREY
108
181
  default:
109
- throw 'missing color'
182
+ throw 'invalid color'
110
183
  }
111
184
  }
112
185
 
113
- export function getRunColor(
114
- convention: RunConvention,
186
+ export function getRunColorName(
187
+ convention: RunDifficultyConvention,
115
188
  difficulty: RunDifficulty | null,
116
- ): string {
189
+ ): RunColorName {
117
190
  switch (convention) {
118
- case RunConvention.EUROPE:
191
+ case RunDifficultyConvention.EUROPE:
119
192
  switch (difficulty) {
120
193
  case RunDifficulty.NOVICE:
121
- return GREEN_COLOR
194
+ return RunColorName.GREEN
122
195
  case RunDifficulty.EASY:
123
- return BLUE_COLOR
196
+ return RunColorName.BLUE
124
197
  case RunDifficulty.INTERMEDIATE:
125
- return RED_COLOR
198
+ return RunColorName.RED
126
199
  case RunDifficulty.ADVANCED:
127
200
  case RunDifficulty.EXPERT:
128
- return BLACK_COLOR
201
+ return RunColorName.BLACK
129
202
  case RunDifficulty.FREERIDE:
130
203
  case RunDifficulty.EXTREME:
131
- return ORANGE_COLOR
204
+ return RunColorName.ORANGE
132
205
  default:
133
- return GREY_COLOR
206
+ return RunColorName.GREY
134
207
  }
135
- case RunConvention.JAPAN:
208
+ case RunDifficultyConvention.JAPAN:
136
209
  switch (difficulty) {
137
210
  case RunDifficulty.NOVICE:
138
211
  case RunDifficulty.EASY:
139
- return GREEN_COLOR
212
+ return RunColorName.GREEN
140
213
  case RunDifficulty.INTERMEDIATE:
141
- return RED_COLOR
214
+ return RunColorName.RED
142
215
  case RunDifficulty.ADVANCED:
143
216
  case RunDifficulty.EXPERT:
144
- return BLACK_COLOR
217
+ return RunColorName.BLACK
145
218
  case RunDifficulty.FREERIDE:
146
219
  case RunDifficulty.EXTREME:
147
- return ORANGE_COLOR
220
+ return RunColorName.ORANGE
148
221
  default:
149
- return GREY_COLOR
222
+ return RunColorName.GREY
150
223
  }
151
- case RunConvention.NORTH_AMERICA:
224
+ case RunDifficultyConvention.NORTH_AMERICA:
152
225
  switch (difficulty) {
153
226
  case RunDifficulty.NOVICE:
154
227
  case RunDifficulty.EASY:
155
- return GREEN_COLOR
228
+ return RunColorName.GREEN
156
229
  case RunDifficulty.INTERMEDIATE:
157
- return BLUE_COLOR
230
+ return RunColorName.BLUE
158
231
  case RunDifficulty.ADVANCED:
159
232
  case RunDifficulty.EXPERT:
160
- return BLACK_COLOR
233
+ return RunColorName.BLACK
161
234
  case RunDifficulty.FREERIDE:
162
235
  case RunDifficulty.EXTREME:
163
- return ORANGE_COLOR
236
+ return RunColorName.ORANGE
164
237
  default:
165
- return GREY_COLOR
238
+ return RunColorName.GREY
166
239
  }
240
+ default:
241
+ return exhaustiveMatchingGuard(convention)
167
242
  }
168
243
  }