incyclist-services 1.5.7 → 1.5.8

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.
Files changed (35) hide show
  1. package/lib/free-ride/service.d.ts +25 -0
  2. package/lib/free-ride/service.js +163 -0
  3. package/lib/maps/MapArea/MapArea.d.ts +31 -0
  4. package/lib/maps/MapArea/MapArea.js +338 -0
  5. package/lib/maps/MapArea/consts.d.ts +11 -0
  6. package/lib/maps/MapArea/consts.js +11 -0
  7. package/lib/maps/MapArea/options.d.ts +21 -0
  8. package/lib/maps/MapArea/options.js +328 -0
  9. package/lib/maps/MapArea/service.d.ts +51 -0
  10. package/lib/maps/MapArea/service.js +242 -0
  11. package/lib/maps/MapArea/types.d.ts +121 -0
  12. package/lib/maps/MapArea/types.js +2 -0
  13. package/lib/maps/MapArea/utils.d.ts +42 -0
  14. package/lib/maps/MapArea/utils.js +581 -0
  15. package/lib/maps/ways/consts.d.ts +11 -0
  16. package/lib/maps/ways/consts.js +11 -0
  17. package/lib/maps/ways/options.d.ts +20 -0
  18. package/lib/maps/ways/options.js +294 -0
  19. package/lib/maps/ways/service.d.ts +43 -0
  20. package/lib/maps/ways/service.js +328 -0
  21. package/lib/maps/ways/types.d.ts +102 -0
  22. package/lib/maps/ways/types.js +2 -0
  23. package/lib/maps/ways/utils.d.ts +62 -0
  24. package/lib/maps/ways/utils.js +725 -0
  25. package/lib/ride/base/base.d.ts +2 -0
  26. package/lib/ride/base/base.js +3 -0
  27. package/lib/ride/base/types.d.ts +1 -0
  28. package/lib/ride/display/service.js +10 -1
  29. package/lib/ride/route/FreeRideDisplayService.d.ts +10 -0
  30. package/lib/ride/route/FreeRideDisplayService.js +66 -0
  31. package/lib/ride/route/GpxDisplayService.d.ts +2 -2
  32. package/lib/ride/route/GpxDisplayService.js +3 -4
  33. package/lib/ride/route/RouteDisplayService.d.ts +4 -0
  34. package/lib/ride/route/RouteDisplayService.js +9 -0
  35. package/package.json +2 -2
@@ -0,0 +1,25 @@
1
+ import { IncyclistService } from "../base/service";
2
+ import { Observer } from "../base/types";
3
+ import { FreeRideContinuation, IMapArea, IncyclistNode } from "../maps/MapArea/types";
4
+ import { FreeRideOption } from "../routes/list/types";
5
+ import { LatLng } from "../utils/geo";
6
+ export declare class FreeRideService extends IncyclistService {
7
+ protected observer: Observer;
8
+ protected startPosition: IncyclistNode;
9
+ protected startOptions: FreeRideContinuation[];
10
+ protected selectedOption: FreeRideOption;
11
+ constructor();
12
+ startRouteDefinition(initialPosition?: LatLng): Observer;
13
+ changeStartPosition(position: LatLng, initial?: boolean): Promise<void>;
14
+ select(option: FreeRideOption): void;
15
+ getRouteDefinitionDisplayProps(): {
16
+ position: IncyclistNode;
17
+ options: FreeRideOption[];
18
+ };
19
+ protected buildFreeRideOptions(): FreeRideOption[];
20
+ protected getStartOptions(map: IMapArea, initial?: boolean): Promise<void>;
21
+ protected setStartPosition(position?: LatLng): void;
22
+ protected getDefaultStartPosition(): IncyclistNode;
23
+ protected getMapArea(): import("../maps/MapArea/service").MapAreaService;
24
+ protected getUserSettings(): import("../settings").UserSettingsService;
25
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
46
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
47
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.FreeRideService = void 0;
51
+ const decorators_1 = require("../base/decorators");
52
+ const service_1 = require("../base/service");
53
+ const types_1 = require("../base/types");
54
+ const consts_1 = require("../maps/MapArea/consts");
55
+ const service_2 = require("../maps/MapArea/service");
56
+ const utils_1 = require("../maps/MapArea/utils");
57
+ const settings_1 = require("../settings");
58
+ let FreeRideService = (() => {
59
+ let _classDecorators = [types_1.Singleton];
60
+ let _classDescriptor;
61
+ let _classExtraInitializers = [];
62
+ let _classThis;
63
+ let _classSuper = service_1.IncyclistService;
64
+ let _instanceExtraInitializers = [];
65
+ let _getMapArea_decorators;
66
+ let _getUserSettings_decorators;
67
+ var FreeRideService = _classThis = class extends _classSuper {
68
+ constructor() {
69
+ super('FreeRide');
70
+ this.observer = __runInitializers(this, _instanceExtraInitializers);
71
+ }
72
+ startRouteDefinition(initialPosition) {
73
+ if (this.observer)
74
+ this.observer.stop();
75
+ this.observer = new types_1.Observer();
76
+ this.changeStartPosition(initialPosition, true);
77
+ return this.observer;
78
+ }
79
+ changeStartPosition(position_1) {
80
+ return __awaiter(this, arguments, void 0, function* (position, initial = false) {
81
+ this.setStartPosition(position);
82
+ const map = yield this.getMapArea().load(this.startPosition);
83
+ yield this.getStartOptions(map, true);
84
+ this.observer.emit(initial ? 'loaded' : 'updated');
85
+ });
86
+ }
87
+ select(option) {
88
+ this.selectedOption = option;
89
+ }
90
+ getRouteDefinitionDisplayProps() {
91
+ const options = this.buildFreeRideOptions();
92
+ return { position: this.startPosition, options };
93
+ }
94
+ buildFreeRideOptions() {
95
+ var _a;
96
+ const opts = (_a = this.startOptions) !== null && _a !== void 0 ? _a : [];
97
+ return opts.map(o => (Object.assign({}, o)));
98
+ }
99
+ getStartOptions(map_1) {
100
+ return __awaiter(this, arguments, void 0, function* (map, initial = false) {
101
+ var _a;
102
+ this.startOptions = [];
103
+ if (!map)
104
+ return;
105
+ const { way } = (_a = map.getNearestPath(this.startPosition)) !== null && _a !== void 0 ? _a : {};
106
+ if (!way) {
107
+ const { lat, lng } = this.startPosition;
108
+ this.logEvent({ message: 'no options found for', lat, lng, reason: 'off track' });
109
+ return;
110
+ }
111
+ const crossing = (0, utils_1.getPointCrossingPath)(this.startPosition, way.path, true);
112
+ if (!crossing) {
113
+ if (way.path.length > 1)
114
+ this.startOptions = [{ path: way.path }];
115
+ return;
116
+ }
117
+ this.setStartPosition(crossing.point);
118
+ const optionManager = (0, service_2.useMapArea)().getOptionManager();
119
+ optionManager.setMap(map);
120
+ const options = yield optionManager.getStartOptions(way, crossing);
121
+ this.startOptions.push(...options);
122
+ });
123
+ }
124
+ setStartPosition(position) {
125
+ try {
126
+ this.startPosition = position !== null && position !== void 0 ? position : this.getDefaultStartPosition();
127
+ this.getUserSettings().set('preferences.routeSelection.freeRide.position', this.startPosition);
128
+ }
129
+ catch (err) {
130
+ this.logError(err, 'setStartPosition');
131
+ }
132
+ }
133
+ getDefaultStartPosition() {
134
+ try {
135
+ return this.getUserSettings().get('preferences.routeSelection.freeRide.position', consts_1.DEFAULT_POSITION);
136
+ }
137
+ catch (_a) {
138
+ return consts_1.DEFAULT_POSITION;
139
+ }
140
+ }
141
+ getMapArea() {
142
+ return (0, service_2.useMapArea)();
143
+ }
144
+ getUserSettings() {
145
+ return (0, settings_1.useUserSettings)();
146
+ }
147
+ };
148
+ __setFunctionName(_classThis, "FreeRideService");
149
+ (() => {
150
+ var _a;
151
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
152
+ _getMapArea_decorators = [decorators_1.Injectable];
153
+ _getUserSettings_decorators = [decorators_1.Injectable];
154
+ __esDecorate(_classThis, null, _getMapArea_decorators, { kind: "method", name: "getMapArea", static: false, private: false, access: { has: obj => "getMapArea" in obj, get: obj => obj.getMapArea }, metadata: _metadata }, null, _instanceExtraInitializers);
155
+ __esDecorate(_classThis, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
156
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
157
+ FreeRideService = _classThis = _classDescriptor.value;
158
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
159
+ __runInitializers(_classThis, _classExtraInitializers);
160
+ })();
161
+ return FreeRideService = _classThis;
162
+ })();
163
+ exports.FreeRideService = FreeRideService;
@@ -0,0 +1,31 @@
1
+ import { EventLogger } from "gd-eventlog";
2
+ import { LatLng } from "../../utils/geo";
3
+ import { Boundary, FreeRideDataSet, IMapArea, IncyclistNode, IncyclistWay, IncyclistWaySplit, NearestPathInfo, PathCrossingInfo, SegmentInfo, SplitPointInfo, WayInfo } from "./types";
4
+ export declare class MapArea implements IMapArea {
5
+ protected data: FreeRideDataSet;
6
+ protected queryLocation: IncyclistNode;
7
+ protected bounds: Boundary;
8
+ protected logger: EventLogger;
9
+ constructor(data: FreeRideDataSet, queryLocation: IncyclistNode, bounds: Boundary);
10
+ getQueryLocation(): IncyclistNode;
11
+ getBoundary(): Boundary;
12
+ getWays(): IncyclistWay[];
13
+ getWay(id: string): IncyclistWay;
14
+ getNode(id: string): IncyclistNode;
15
+ getStats(): Record<string, number>;
16
+ isWithinBoundary(location: LatLng): boolean;
17
+ getNearestPath(point: IncyclistNode): NearestPathInfo;
18
+ getFirstBranch(way: WayInfo, ignore?: string): SplitPointInfo;
19
+ splitAtFirstBranch(way: WayInfo): IncyclistWaySplit;
20
+ splitAtCrossingPoint(way: IncyclistWay, crossing: PathCrossingInfo): Array<IncyclistWaySplit>;
21
+ buildSegmentInfo(from: IncyclistWay, parts: Array<IncyclistWaySplit>): SegmentInfo;
22
+ protected correctRoundabouts(): void;
23
+ protected collectRoundaboutWays(way: IncyclistWay): Array<string>;
24
+ protected getBranch(crossing: SplitPointInfo, wayId: string, targetId: string): IncyclistWay;
25
+ protected replaceWayID(way: IncyclistWay, newId: string, replaceLookup?: boolean): IncyclistWay;
26
+ protected getUntilFirstBranch(w: WayInfo, props?: {
27
+ reverse?: boolean;
28
+ ignore?: string;
29
+ }): IncyclistWay;
30
+ protected logError(err: Error, fn: string, args?: any): void;
31
+ }
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MapArea = void 0;
7
+ const gd_eventlog_1 = require("gd-eventlog");
8
+ const utils_1 = require("./utils");
9
+ const clone_1 = __importDefault(require("../../utils/clone"));
10
+ class MapArea {
11
+ constructor(data, queryLocation, bounds) {
12
+ this.data = data;
13
+ this.queryLocation = queryLocation;
14
+ this.bounds = bounds;
15
+ this.logger = new gd_eventlog_1.EventLogger('MapArea');
16
+ this.correctRoundabouts();
17
+ }
18
+ getQueryLocation() {
19
+ return this.queryLocation;
20
+ }
21
+ getBoundary() {
22
+ return this.bounds;
23
+ }
24
+ getWays() {
25
+ return this.data.ways;
26
+ }
27
+ getWay(id) {
28
+ return this.data.waysLookup[id];
29
+ }
30
+ getNode(id) {
31
+ return this.data.nodesLookup[id];
32
+ }
33
+ getStats() {
34
+ return this.data.typeStats;
35
+ }
36
+ isWithinBoundary(location) {
37
+ return (0, utils_1.isWithinBoundary)(location, this.bounds);
38
+ }
39
+ getNearestPath(point) {
40
+ var _a, _b;
41
+ const ways = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.ways) !== null && _b !== void 0 ? _b : [];
42
+ if (!(ways === null || ways === void 0 ? void 0 : ways.length))
43
+ return;
44
+ let w;
45
+ let min = { path: undefined, distance: undefined, way: undefined };
46
+ for (w of ways) {
47
+ let distance = (0, utils_1.distanceToPath)(point, w);
48
+ if (distance !== undefined && (min.distance === undefined || distance < min.distance)) {
49
+ min.distance = distance;
50
+ min.path = w.path;
51
+ min.way = w;
52
+ }
53
+ }
54
+ return min;
55
+ }
56
+ getFirstBranch(way, ignore) {
57
+ if ((way === null || way === void 0 ? void 0 : way.path) === undefined)
58
+ return;
59
+ let pFound = undefined;
60
+ way.path.forEach((node, idx) => {
61
+ var _a, _b;
62
+ if (idx === 0 || ((_a = node === null || node === void 0 ? void 0 : node.ways) === null || _a === void 0 ? void 0 : _a.length) < 2 || pFound)
63
+ return;
64
+ const branches = [];
65
+ (_b = node.ways) === null || _b === void 0 ? void 0 : _b.forEach((wid) => {
66
+ if (wid === way.id)
67
+ return;
68
+ const branch = this.getWay(wid);
69
+ if ((0, utils_1.isOneWay)(branch) && branch.path[branch.path.length - 1].id === node.id)
70
+ return;
71
+ if (ignore && wid === ignore)
72
+ return;
73
+ branches.push(wid);
74
+ });
75
+ pFound = branches.length > 0 ? { point: node, idx, branches } : undefined;
76
+ });
77
+ return pFound;
78
+ }
79
+ splitAtFirstBranch(way) {
80
+ if ((way === null || way === void 0 ? void 0 : way.path) === undefined)
81
+ return;
82
+ const path = [...way.path];
83
+ const original = (0, clone_1.default)(way);
84
+ const crossing = this.getFirstBranch(way);
85
+ if (!crossing) {
86
+ return {
87
+ wayId: original.id,
88
+ path,
89
+ branches: []
90
+ };
91
+ }
92
+ let result = {
93
+ wayId: way.id,
94
+ branches: []
95
+ };
96
+ const [before, after] = (0, utils_1.splitAtPointInfo)(way, crossing);
97
+ result.path = before;
98
+ const prefered = { id: way.id, path: after };
99
+ if (prefered.path.length > 1)
100
+ result.branches.push(prefered);
101
+ crossing.point.ways.forEach((wid) => {
102
+ const option = this.getBranch(crossing, way.id, wid);
103
+ if (option)
104
+ result.branches.push(option);
105
+ });
106
+ return result;
107
+ }
108
+ splitAtCrossingPoint(way, crossing) {
109
+ if ((way === null || way === void 0 ? void 0 : way.path) === undefined || (crossing === null || crossing === void 0 ? void 0 : crossing.idx) === undefined || (crossing === null || crossing === void 0 ? void 0 : crossing.point) === undefined)
110
+ return;
111
+ const { point, idx: crossingIdx } = crossing;
112
+ const addWaysCrossing = (res) => {
113
+ let optWay = way;
114
+ point.ways.forEach(optId => {
115
+ var _a;
116
+ if (optId === way.id)
117
+ return;
118
+ optWay = this.getWay(optId);
119
+ if (!((_a = optWay === null || optWay === void 0 ? void 0 : optWay.path) === null || _a === void 0 ? void 0 : _a.length))
120
+ return;
121
+ if (optWay.path[optWay.path.length - 1].id === point.id)
122
+ optWay.path.reverse();
123
+ else if (optWay.path[0].id !== point.id) {
124
+ const parts = (0, utils_1.splitAtPoint)(optWay, point).filter(p => p.path.length > 1 && !p.onewayReverse);
125
+ parts.forEach(p => res.push({ wayId: p.id, path: p.path }));
126
+ return;
127
+ }
128
+ if (optWay.path.length > 1)
129
+ res.push({ wayId: optWay.id, path: optWay.path });
130
+ });
131
+ };
132
+ const addOption = (newPath, res, reverse) => {
133
+ let optWay = way;
134
+ let path = [];
135
+ if (newPath.length === 1) {
136
+ addWaysCrossing(res);
137
+ }
138
+ else if (newPath.length > 1) {
139
+ path = newPath;
140
+ if (reverse)
141
+ path.reverse();
142
+ res.push({ wayId: optWay.id, path });
143
+ }
144
+ };
145
+ const res = [];
146
+ let newPath = [];
147
+ if (!point.ways)
148
+ point.ways = [way.id];
149
+ way.path.forEach((p, i) => {
150
+ if (i < crossingIdx || i > crossingIdx) {
151
+ newPath.push(p);
152
+ }
153
+ else {
154
+ if ((newPath === null || newPath === void 0 ? void 0 : newPath.length) > 0 && point.id !== newPath[newPath.length - 1].id)
155
+ newPath.push(point);
156
+ if (!(0, utils_1.isOneWay)(way)) {
157
+ addOption(newPath, res, true);
158
+ }
159
+ newPath = [];
160
+ newPath.push(point);
161
+ if (point.id !== p.id)
162
+ newPath.push(p);
163
+ }
164
+ });
165
+ addOption(newPath, res, false);
166
+ return res;
167
+ }
168
+ buildSegmentInfo(from, parts) {
169
+ const segments = [];
170
+ const points = [];
171
+ parts.forEach((option, i) => {
172
+ const { wayId, path } = option;
173
+ const wayOriginal = this.getWay(wayId !== null && wayId !== void 0 ? wayId : from.id);
174
+ if (path) {
175
+ const wayOption = Object.assign(Object.assign({}, wayOriginal), { path });
176
+ let res = this.splitAtFirstBranch(wayOption);
177
+ segments.push({ id: res.wayId, path: res.path });
178
+ points.push(...res.path);
179
+ }
180
+ });
181
+ return { segments, points };
182
+ }
183
+ correctRoundabouts() {
184
+ var _a;
185
+ let multiWayRoundabouts = [];
186
+ let roundaboutsImplicit = [];
187
+ try {
188
+ (_a = this.data) === null || _a === void 0 ? void 0 : _a.ways.forEach(way => {
189
+ if ((0, utils_1.isRoundabout)(way, true)) {
190
+ let ways = this.collectRoundaboutWays(way);
191
+ let id = (0, utils_1.generateID)(ways);
192
+ let found = multiWayRoundabouts.find(e => e.id === id);
193
+ if (!found) {
194
+ found = (way.path[0].id === way.path[way.path.length - 1].id);
195
+ if (found) {
196
+ roundaboutsImplicit.push(way);
197
+ }
198
+ }
199
+ if (!found)
200
+ multiWayRoundabouts.push({ id, ways });
201
+ }
202
+ else if ((0, utils_1.isRoundabout)(way, false)) {
203
+ roundaboutsImplicit.push(way);
204
+ }
205
+ });
206
+ multiWayRoundabouts.forEach(ri => {
207
+ let originalNodes = [];
208
+ ri.ways.forEach((wid, i) => {
209
+ let way = this.getWay(wid);
210
+ let path = way.path;
211
+ path.forEach(n => {
212
+ if (originalNodes.length === 0 ||
213
+ originalNodes[originalNodes.length - 1] !== n.id)
214
+ originalNodes.push(n.id);
215
+ });
216
+ });
217
+ ri.ways.forEach((wid, i) => {
218
+ let way = this.getWay(wid);
219
+ this.replaceWayID(way, ri.id, i === 0);
220
+ });
221
+ let roundabout = this.getWay(ri.id);
222
+ roundabout.path = [];
223
+ originalNodes.forEach(nid => {
224
+ let node = this.getNode(nid);
225
+ roundabout.path.push(node);
226
+ });
227
+ roundabout.tags.roundabout = 'yes';
228
+ });
229
+ roundaboutsImplicit.forEach(roundabout => {
230
+ if (roundabout.tags === undefined)
231
+ roundabout.tags = {};
232
+ roundabout.tags.roundabout = 'yes';
233
+ });
234
+ }
235
+ catch (err) {
236
+ this.logError(err, 'correctRoundabouts');
237
+ }
238
+ }
239
+ collectRoundaboutWays(way) {
240
+ if (!(0, utils_1.isRoundabout)(way, true))
241
+ return undefined;
242
+ const contains = (ways, wid) => {
243
+ let found = ways.find(id => id === wid);
244
+ return found !== undefined;
245
+ };
246
+ const addNodes = (ways, way) => {
247
+ const crossings = way.path.filter((n, idx) => { var _a; return idx !== 0 && ((_a = n.ways) === null || _a === void 0 ? void 0 : _a.length) > 1; });
248
+ crossings.forEach(n => {
249
+ n.ways.forEach(wid => {
250
+ let w = this.getWay(wid);
251
+ if ((0, utils_1.isRoundabout)(w, true) && wid !== way.id && !contains(ways, wid)) {
252
+ ways.push(wid);
253
+ addNodes(ways, w);
254
+ }
255
+ });
256
+ });
257
+ };
258
+ let ways = [way.id];
259
+ addNodes(ways, way);
260
+ return ways;
261
+ }
262
+ ;
263
+ getBranch(crossing, wayId, targetId) {
264
+ let w = (0, clone_1.default)(this.getWay(targetId));
265
+ if ((w === null || w === void 0 ? void 0 : w.id) === wayId)
266
+ return;
267
+ if (w.path[0].id === crossing.point.id) {
268
+ const res = this.getUntilFirstBranch(w, { ignore: wayId });
269
+ if (res.path.length > 1)
270
+ return res;
271
+ }
272
+ else if (w.path[w.path.length - 1].id === crossing.point.id) {
273
+ w.path.reverse();
274
+ const res = this.getUntilFirstBranch(w, { ignore: wayId });
275
+ if (res.path.length > 1)
276
+ return res;
277
+ }
278
+ else {
279
+ let branches = (0, utils_1.splitAtPoint)(w, crossing.point);
280
+ let res = this.getUntilFirstBranch(branches[0], { ignore: wayId });
281
+ if (res.path.length > 1)
282
+ return res;
283
+ res = this.getUntilFirstBranch(branches[1], { ignore: wayId });
284
+ if (res.path.length > 1)
285
+ return res;
286
+ }
287
+ }
288
+ replaceWayID(way, newId, replaceLookup = true) {
289
+ if (way === undefined || newId === undefined || way.id === undefined || way.path === undefined || !this.data)
290
+ return;
291
+ let oldId = way.id;
292
+ let w = this.getWay(oldId);
293
+ w.originalId = w.id;
294
+ w.id = newId;
295
+ w.path.forEach((nx, j) => {
296
+ w.path[j] = this.getNode(nx.id);
297
+ let n = w.path[j];
298
+ n.ways.forEach((wid, i) => { if (wid === oldId)
299
+ n.ways[i] = newId; });
300
+ n.ways = [...new Set(n.ways)];
301
+ });
302
+ if (replaceLookup)
303
+ this.data.waysLookup[newId] = w;
304
+ delete this.data.waysLookup[oldId];
305
+ return w;
306
+ }
307
+ ;
308
+ getUntilFirstBranch(w, props) {
309
+ if (!w)
310
+ return;
311
+ const reverse = (props !== undefined) ? props.reverse : false;
312
+ const ignore = (props !== undefined) ? props.ignore : undefined;
313
+ let branch;
314
+ let path = w.path;
315
+ if (reverse) {
316
+ w.path = [...path];
317
+ w.path.reverse();
318
+ path = w.path;
319
+ }
320
+ let piBranch = this.getFirstBranch(w, ignore);
321
+ if (piBranch !== undefined) {
322
+ branch = { id: w.id, path: [] };
323
+ path.forEach((p, idx) => {
324
+ if (idx <= piBranch.idx)
325
+ branch.path.push(p);
326
+ });
327
+ }
328
+ else {
329
+ branch = { id: w.id, path: w.path };
330
+ }
331
+ return branch;
332
+ }
333
+ logError(err, fn, args) {
334
+ const logInfo = args !== null && args !== void 0 ? args : {};
335
+ this.logger.logEvent(Object.assign(Object.assign({ message: 'Error', fn }, logInfo), { error: err.message, stack: err.stack }));
336
+ }
337
+ }
338
+ exports.MapArea = MapArea;
@@ -0,0 +1,11 @@
1
+ export declare const RADIUS_EARTH = 6378.1;
2
+ export declare const DEFAULT_RADIUS = 1000;
3
+ export declare const DEFAULT_MIN_WAYS = 70;
4
+ export declare const DEFAULT_MAX_WAYS = 300;
5
+ export declare const MAX_DISTANCE_FROM_PATH = 5;
6
+ export declare const GET_WAYS_IN_AREA = "[out:json];way[highway](__boundary__);(._;>;);out geom;";
7
+ export declare const DEFAULT_FILTER: string[];
8
+ export declare const DEFAULT_POSITION: {
9
+ lat: number;
10
+ lng: number;
11
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_POSITION = exports.DEFAULT_FILTER = exports.GET_WAYS_IN_AREA = exports.MAX_DISTANCE_FROM_PATH = exports.DEFAULT_MAX_WAYS = exports.DEFAULT_MIN_WAYS = exports.DEFAULT_RADIUS = exports.RADIUS_EARTH = void 0;
4
+ exports.RADIUS_EARTH = 6378.1;
5
+ exports.DEFAULT_RADIUS = 1000;
6
+ exports.DEFAULT_MIN_WAYS = 70;
7
+ exports.DEFAULT_MAX_WAYS = 300;
8
+ exports.MAX_DISTANCE_FROM_PATH = 5;
9
+ exports.GET_WAYS_IN_AREA = '[out:json];way[highway](__boundary__);(._;>;);out geom;';
10
+ exports.DEFAULT_FILTER = ['construction', 'footway', 'service', 'pedestrian', 'path', 'cycleway', 'elevator', 'steps', 'track', 'escape', 'bus_guideway', 'busway', 'bridleway', 'corridor', 'via_ferrata'];
11
+ exports.DEFAULT_POSITION = { lat: 26.68537966608196, lng: -80.03481961660725 };
@@ -0,0 +1,21 @@
1
+ import { EventLogger } from "gd-eventlog";
2
+ import { FreeRideContinuation, IMapArea, IMapAreaService, IncyclistNode, IncyclistWay, PathCrossingInfo, WayInfo } from "./types";
3
+ export declare class OptionManager {
4
+ protected service: IMapAreaService;
5
+ protected map?: IMapArea;
6
+ protected logger: EventLogger;
7
+ constructor(service: IMapAreaService, map?: IMapArea);
8
+ setMap(map: IMapArea): void;
9
+ getStartOptions(way: IncyclistWay, crossing: PathCrossingInfo): Promise<Array<FreeRideContinuation>>;
10
+ getNextOptions(from?: WayInfo | FreeRideContinuation): Promise<Array<FreeRideContinuation>>;
11
+ protected checkOptionsOnDifferentWay(location: IncyclistNode, w: IncyclistWay, options: FreeRideContinuation[]): FreeRideContinuation[];
12
+ protected getOptionsFirstPoint(location: IncyclistNode, w: IncyclistWay, options: FreeRideContinuation[]): void;
13
+ protected getOptionsLastPoint(location: IncyclistNode, w: IncyclistWay, options: FreeRideContinuation[]): void;
14
+ protected getOptionsMiddle(location: IncyclistNode, w: IncyclistWay, options: FreeRideContinuation[]): void;
15
+ protected getOptionsRoundabout(location: IncyclistNode, w: IncyclistWay, options: FreeRideContinuation[]): any;
16
+ protected getWay(props: string | IncyclistWay): IncyclistWay;
17
+ protected getNode(props?: string | IncyclistNode): IncyclistNode;
18
+ getRemaining(partial: IncyclistWay): IncyclistWay;
19
+ getOptionsOnCurrentWay(location: IncyclistNode, way: IncyclistWay, options: Array<FreeRideContinuation>): Array<FreeRideContinuation>;
20
+ protected logError(err: Error, fn: string, args?: any): void;
21
+ }