Route.res.mjs
1// Generated by ReScript, PLEASE EDIT WITH CARE
2
3import * as Core__JSON from "@rescript/core/lib/es6/src/Core__JSON.res.mjs";
4import * as Core__Array from "@rescript/core/lib/es6/src/Core__Array.res.mjs";
5import * as Core__Option from "@rescript/core/lib/es6/src/Core__Option.res.mjs";
6
7function extractRouteHashes(waypoints) {
8 return waypoints.map(waypoint => {
9 let routeDict = waypoint.from;
10 if (routeDict !== undefined) {
11 return Core__Array.filterMap(Object.entries(routeDict), param => {
12 let id = param[1].id;
13 if (id !== undefined) {
14 return id;
15 }
16 });
17 } else {
18 return [];
19 }
20 }).flat().filter(hash => hash !== "");
21}
22
23function decodeProperties(json) {
24 if (typeof json !== "object" || json === null || Array.isArray(json)) {
25 return;
26 }
27 let id = Core__Option.flatMap(json["id"], Core__JSON.Decode.string);
28 let distance = Core__Option.flatMap(json["distance"], Core__JSON.Decode.float);
29 let time = Core__Option.flatMap(json["time"], Core__JSON.Decode.float);
30 let bbox = Core__Option.map(Core__Option.flatMap(json["bbox"], Core__JSON.Decode.array), arr => Core__Array.filterMap(arr, Core__JSON.Decode.float));
31 if (id !== undefined && distance !== undefined && time !== undefined && bbox !== undefined) {
32 return {
33 id: id,
34 distance: distance,
35 time: time,
36 bbox: bbox
37 };
38 }
39}
40
41function extractFromEvent(event) {
42 let features = event.features;
43 if (features !== undefined) {
44 return Core__Array.filterMap(features, feature => decodeProperties(feature.properties));
45 } else {
46 return [];
47 }
48}
49
50function extractFirst(event) {
51 let features = event.features;
52 if (features !== undefined) {
53 return Core__Option.flatMap(features[0], feature => decodeProperties(feature.properties));
54 }
55}
56
57function getGeoJSONUrl(hash) {
58 return `/route/` + hash + `.geojson`;
59}
60
61export {
62 extractRouteHashes,
63 decodeProperties,
64 extractFromEvent,
65 extractFirst,
66 getGeoJSONUrl,
67}
68/* No side effect */