incyclist-services 1.9.11 → 1.9.13

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 (48) hide show
  1. package/lib/cjs/apps/googleMaps/consts.js +10 -0
  2. package/lib/cjs/apps/googleMaps/index.js +1 -0
  3. package/lib/cjs/apps/googleMaps/service.js +46 -1
  4. package/lib/cjs/maps/MapArea/options.js +2 -3
  5. package/lib/cjs/ride/display/service.js +95 -0
  6. package/lib/cjs/ride/index.js +1 -0
  7. package/lib/cjs/ride/page/service.js +69 -1
  8. package/lib/cjs/ride/route/FreeRideDisplayService.js +36 -5
  9. package/lib/cjs/ride/route/GpxDisplayService.js +46 -1
  10. package/lib/cjs/ride/view-restriction/index.js +18 -0
  11. package/lib/cjs/ride/view-restriction/service.js +221 -0
  12. package/lib/cjs/ride/view-restriction/types.js +2 -0
  13. package/lib/cjs/routes/free-ride/option-labels.js +141 -0
  14. package/lib/cjs/routes/free-ride/service.js +217 -117
  15. package/lib/cjs/settings/display/ride/service.js +22 -4
  16. package/lib/esm/apps/googleMaps/consts.js +7 -0
  17. package/lib/esm/apps/googleMaps/index.js +1 -0
  18. package/lib/esm/apps/googleMaps/service.js +46 -1
  19. package/lib/esm/maps/MapArea/options.js +2 -3
  20. package/lib/esm/ride/display/service.js +95 -0
  21. package/lib/esm/ride/index.js +1 -0
  22. package/lib/esm/ride/page/service.js +69 -1
  23. package/lib/esm/ride/route/FreeRideDisplayService.js +36 -5
  24. package/lib/esm/ride/route/GpxDisplayService.js +46 -1
  25. package/lib/esm/ride/view-restriction/index.js +2 -0
  26. package/lib/esm/ride/view-restriction/service.js +217 -0
  27. package/lib/esm/ride/view-restriction/types.js +1 -0
  28. package/lib/esm/routes/free-ride/service.js +217 -117
  29. package/lib/esm/settings/display/ride/service.js +20 -2
  30. package/lib/types/apps/googleMaps/consts.d.ts +7 -0
  31. package/lib/types/apps/googleMaps/index.d.ts +1 -0
  32. package/lib/types/apps/googleMaps/service.d.ts +8 -0
  33. package/lib/types/maps/MapArea/types.d.ts +1 -0
  34. package/lib/types/ride/base/types.d.ts +5 -1
  35. package/lib/types/ride/display/service.d.ts +15 -0
  36. package/lib/types/ride/index.d.ts +1 -0
  37. package/lib/types/ride/page/service.d.ts +10 -0
  38. package/lib/types/ride/page/types.d.ts +10 -0
  39. package/lib/types/ride/route/FreeRideDisplayService.d.ts +4 -1
  40. package/lib/types/ride/route/GpxDisplayService.d.ts +5 -0
  41. package/lib/types/ride/view-restriction/index.d.ts +2 -0
  42. package/lib/types/ride/view-restriction/service.d.ts +30 -0
  43. package/lib/types/ride/view-restriction/types.d.ts +57 -0
  44. package/lib/types/routes/free-ride/service.d.ts +18 -2
  45. package/lib/types/routes/list/types.d.ts +11 -0
  46. package/lib/types/settings/display/ride/service.d.ts +1 -0
  47. package/lib/types/settings/display/ride/types.d.ts +4 -0
  48. package/package.json +3 -3
@@ -48,6 +48,7 @@ const settings_1 = require("../../settings");
48
48
  const geo_1 = require("../../utils/geo");
49
49
  const utils_2 = require("../../utils");
50
50
  const clone_1 = __importDefault(require("../../utils/clone"));
51
+ const option_labels_1 = require("./option-labels");
51
52
  const INIT_RETRY = 15 * 1000;
52
53
  const MAX_RETRIES = 1;
53
54
  let FreeRideService = (() => {
@@ -81,6 +82,9 @@ let FreeRideService = (() => {
81
82
  initialized = false;
82
83
  ivInit;
83
84
  cntInitRetry = 0;
85
+ rideSeq = 0;
86
+ selectedBy = 'auto';
87
+ startSource = 'default';
84
88
  constructor() {
85
89
  super('FreeRide');
86
90
  this.options = [];
@@ -93,6 +97,8 @@ let FreeRideService = (() => {
93
97
  })
94
98
  .finally(() => {
95
99
  this.logEvent({ message: 'init free ride service result', success: this.initialized });
100
+ if (this.initialized)
101
+ return;
96
102
  this.ivInit = setInterval(() => {
97
103
  if (this.cntInitRetry < MAX_RETRIES) {
98
104
  this.cntInitRetry++;
@@ -109,15 +115,29 @@ let FreeRideService = (() => {
109
115
  isInitialized() {
110
116
  return this.initialized;
111
117
  }
112
- async selectStartPosition(position) {
118
+ async selectStartPosition(position, opts) {
119
+ const rideSeq = this.rideSeq;
120
+ const keepSource = !position && (this.startSource === 'search' || this.startSource === 'map');
121
+ this.startSource = opts?.source ?? (keepSource ? this.startSource : this.getDefaultSource(position));
113
122
  this.setStartPosition(position);
114
123
  const map = await this.getMapArea().load(this.startPosition);
115
124
  if (!this.initialized && map) {
116
125
  this.setInitialized();
117
126
  }
118
- await this.getStartOptions(map);
127
+ if (rideSeq !== this.rideSeq) {
128
+ this.logEvent({ message: 'start position update ignored', reason: 'ride started' });
129
+ return this.getRouteDefinitionDisplayProps();
130
+ }
131
+ await this.getStartOptions(map, rideSeq);
119
132
  return this.getRouteDefinitionDisplayProps();
120
133
  }
134
+ getStartSource() {
135
+ return this.startSource;
136
+ }
137
+ getDefaultSource(position) {
138
+ const { lat, lng } = position ?? this.getDefaultStartPosition();
139
+ return lat === consts_1.DEFAULT_POSITION.lat && lng === consts_1.DEFAULT_POSITION.lng ? 'default' : 'last';
140
+ }
121
141
  getStartPosition() {
122
142
  return this.startPosition ?? this.getDefaultStartPosition();
123
143
  }
@@ -147,7 +167,7 @@ let FreeRideService = (() => {
147
167
  this.options = await this.loadNextOptions(from, forStart);
148
168
  }
149
169
  const message = forStart ? 'start options updated' : 'free ride options updated';
150
- this.logEvent({ message, prepared, options: optionsInfo(this.options), from: this.buildId(from) });
170
+ this.logEvent({ message, prepared, options: optionsInfo(this.options), from: this.buildId(from), ...this.getOptionsLogProps() });
151
171
  if (this.options?.length > 0) {
152
172
  this.selectOption(this.options[0]);
153
173
  }
@@ -330,94 +350,100 @@ let FreeRideService = (() => {
330
350
  }
331
351
  async getNextLevelOptions(opts) {
332
352
  let segmentUpdated = false;
333
- this.once('segment-update', () => { segmentUpdated = true; });
353
+ const onSegmentUpdate = () => { segmentUpdated = true; };
354
+ this.once('segment-update', onSegmentUpdate);
334
355
  const optionManager = (0, service_2.useMapArea)().getOptionManager();
335
- for (const o of opts ?? []) {
336
- if (segmentUpdated)
337
- return;
338
- let segment = o;
339
- let done = false;
340
- let isSingle = false;
341
- let lastHandlerWasNoOption = false;
342
- do {
343
- const nextOptsResult = await optionManager.getNextOptions(segment);
344
- const nextOpts = nextOptsResult.options;
345
- const isValid = nextOptsResult.isValid;
346
- const handleSingleOption = () => {
347
- if (segmentUpdated)
348
- return;
349
- isSingle = true;
350
- try {
351
- segment = nextOpts[0];
352
- (0, utils_1.concatPaths)(o.path, segment.path, 'after');
353
- const originatingPoint = segment.path[1];
354
- if (segment.options?.length > 0) {
355
- segment.options = segment.options.filter(o => o.path.at(-1).id !== originatingPoint.id);
356
+ try {
357
+ for (const o of opts ?? []) {
358
+ if (segmentUpdated)
359
+ return;
360
+ let segment = o;
361
+ let done = false;
362
+ let isSingle = false;
363
+ let lastHandlerWasNoOption = false;
364
+ do {
365
+ const nextOptsResult = await optionManager.getNextOptions(segment);
366
+ const nextOpts = nextOptsResult.options;
367
+ const isValid = nextOptsResult.isValid;
368
+ const handleSingleOption = () => {
369
+ if (segmentUpdated)
370
+ return;
371
+ isSingle = true;
372
+ try {
373
+ segment = nextOpts[0];
374
+ (0, utils_1.concatPaths)(o.path, segment.path, 'after');
375
+ const originatingPoint = segment.path[1];
376
+ if (segment.options?.length > 0) {
377
+ segment.options = segment.options.filter(o => o.path.at(-1).id !== originatingPoint.id);
378
+ }
356
379
  }
357
- }
358
- catch (err) {
359
- this.logError(err, 'getNextLevelOptions#handleSingleOption');
360
- }
361
- };
362
- const handleNoOption = () => {
363
- if (segmentUpdated)
364
- return;
365
- if (isSingle) {
366
- o.options = [segment];
367
- done = true;
368
- return;
369
- }
370
- if (lastHandlerWasNoOption) {
371
- o.options = [];
372
- done = true;
373
- return;
374
- }
375
- try {
376
- const map = segment.map ?? this.getMapArea().getMap(segment.path[0]);
377
- const newPath = [];
378
- segment.path.forEach(p => {
379
- newPath.push((0, clone_1.default)(p));
380
- });
381
- newPath.reverse();
382
- const way = map?.getWay(segment.id);
383
- if (!(0, utils_1.isOneWay)(way) || (0, utils_1.isAllowed)(way, newPath[0], newPath.at(-1))) {
384
- segment = {
385
- id: o.id,
386
- map: o.map,
387
- direction: 180,
388
- path: newPath
389
- };
390
- (0, utils_1.concatPaths)(o.path, newPath, 'after');
380
+ catch (err) {
381
+ this.logError(err, 'getNextLevelOptions#handleSingleOption');
382
+ }
383
+ };
384
+ const handleNoOption = () => {
385
+ if (segmentUpdated)
386
+ return;
387
+ if (isSingle) {
388
+ o.options = [segment];
389
+ done = true;
390
+ return;
391
391
  }
392
- else {
392
+ if (lastHandlerWasNoOption) {
393
393
  o.options = [];
394
394
  done = true;
395
+ return;
396
+ }
397
+ try {
398
+ const map = segment.map ?? this.getMapArea().getMap(segment.path[0]);
399
+ const newPath = [];
400
+ segment.path.forEach(p => {
401
+ newPath.push((0, clone_1.default)(p));
402
+ });
403
+ newPath.reverse();
404
+ const way = map?.getWay(segment.id);
405
+ if (!(0, utils_1.isOneWay)(way) || (0, utils_1.isAllowed)(way, newPath[0], newPath.at(-1))) {
406
+ segment = {
407
+ id: o.id,
408
+ map: o.map,
409
+ direction: 180,
410
+ path: newPath
411
+ };
412
+ (0, utils_1.concatPaths)(o.path, newPath, 'after');
413
+ }
414
+ else {
415
+ o.options = [];
416
+ done = true;
417
+ }
395
418
  }
419
+ catch (err) {
420
+ this.logError(err, 'getNextLevelOptions#handleNoOption');
421
+ }
422
+ };
423
+ if (nextOpts?.length === 1) {
424
+ handleSingleOption();
425
+ lastHandlerWasNoOption = false;
396
426
  }
397
- catch (err) {
398
- this.logError(err, 'getNextLevelOptions#handleNoOption');
427
+ else if (!nextOpts?.length && isValid) {
428
+ handleNoOption();
429
+ lastHandlerWasNoOption = true;
399
430
  }
400
- };
401
- if (nextOpts?.length === 1) {
402
- handleSingleOption();
403
- lastHandlerWasNoOption = false;
404
- }
405
- else if (!nextOpts?.length && isValid) {
406
- handleNoOption();
407
- lastHandlerWasNoOption = true;
408
- }
409
- else if (!nextOpts?.length && !isValid) {
410
- o.options = [];
411
- done = true;
412
- lastHandlerWasNoOption = false;
413
- }
414
- else {
415
- o.options = nextOpts;
416
- done = true;
417
- lastHandlerWasNoOption = false;
418
- }
419
- await (0, utils_2.waitNextTick)();
420
- } while (!done);
431
+ else if (!nextOpts?.length && !isValid) {
432
+ o.options = [];
433
+ done = true;
434
+ lastHandlerWasNoOption = false;
435
+ }
436
+ else {
437
+ o.options = nextOpts;
438
+ done = true;
439
+ lastHandlerWasNoOption = false;
440
+ }
441
+ await (0, utils_2.waitNextTick)();
442
+ } while (!done);
443
+ }
444
+ }
445
+ finally {
446
+ this.off('segment-update', onSegmentUpdate);
421
447
  }
422
448
  }
423
449
  buildId(opt) {
@@ -432,6 +458,12 @@ let FreeRideService = (() => {
432
458
  isLastQueryValid() {
433
459
  return this.lastOptionsQueryValid;
434
460
  }
461
+ selectOptionByUser(option) {
462
+ const options = this.selectOption(option);
463
+ if (this.selectedOption)
464
+ this.selectedBy = 'user';
465
+ return options;
466
+ }
435
467
  selectOption(option) {
436
468
  const current = this.selectedOption;
437
469
  const options = this.options ?? [];
@@ -454,18 +486,26 @@ let FreeRideService = (() => {
454
486
  opt = option;
455
487
  }
456
488
  this.selectedOption = options?.find(o => this.buildId(o) === this.buildId(opt));
489
+ this.selectedBy = 'auto';
457
490
  if (!this.selectedOption) {
458
- this.logEvent({ message: 'free ride option selection failed', requested: option, type: typeof option, options: options ?? 'none', optionKeys: options.map(o => this.buildId(o)) });
491
+ const requested = typeof option === 'object' ? this.buildId(option) : option;
492
+ this.logEvent({ message: 'free ride option selection failed', requested, type: typeof option, count: options.length, optionKeys: options.map(o => this.buildId(o)).join('|') });
459
493
  }
460
494
  return this.options;
461
495
  }
462
496
  applyOption(option) {
463
- if (option)
497
+ if (option) {
498
+ const by = this.selectedBy;
499
+ const sameAsSelected = this.buildId(option) === this.buildId(this.selectedOption);
464
500
  this.selectOption(option);
465
- this.logEvent({ message: 'free ride option applied', option: this.buildId(this.selectedOption) });
501
+ if (sameAsSelected)
502
+ this.selectedBy = by;
503
+ }
504
+ this.logEvent({ message: 'free ride option applied', option: this.buildId(this.selectedOption), ...this.getSelectionLogProps() });
466
505
  this.currentSegment = this.selectedOption;
467
506
  }
468
507
  applyStartOption(startOption) {
508
+ this.rideSeq++;
469
509
  const option = this.options.find(o => this.buildId(o) === startOption?.id);
470
510
  this.applyOption(option);
471
511
  }
@@ -487,37 +527,98 @@ let FreeRideService = (() => {
487
527
  return path;
488
528
  }
489
529
  buildUIOptions(opts = this.options ?? []) {
490
- return opts.map((option, idx) => {
491
- const id = this.buildId(option);
492
- const selected = id === this.buildId(this.selectedOption);
493
- const text = this.getOptionText(option);
494
- const color = this.getOptionColor(idx, { isStartPos: false, selected });
495
- const uiOptions = { id, color, text, path: this.getPath(option), selected, direction: option.direction };
496
- option.ui = uiOptions;
497
- return uiOptions;
530
+ const seen = new Set();
531
+ const unique = opts.filter(o => {
532
+ const id = this.buildId(o);
533
+ if (seen.has(id))
534
+ return false;
535
+ seen.add(id);
536
+ return true;
537
+ });
538
+ const selectedId = this.buildId(this.selectedOption);
539
+ const infos = unique.map(option => ({
540
+ option,
541
+ id: this.buildId(option),
542
+ tags: this.getWayTags(option),
543
+ compass: this.getOptionText(option),
544
+ heading: this.getOptionHeading(option),
545
+ roundabout: !!option.roundabout
546
+ }));
547
+ const order = (0, option_labels_1.getLayoutOrder)(infos.map(i => ({ direction: i.option.direction, roundabout: i.roundabout })));
548
+ const ordered = order.map(idx => ({ ...infos[idx], defaultIdx: idx }));
549
+ const labels = (0, option_labels_1.buildOptionLabels)(ordered.map(i => ({ id: i.id, direction: i.option.direction, roundabout: i.roundabout, compass: i.compass, tags: i.tags })));
550
+ const result = ordered.map((info, pos) => {
551
+ const { option, id, compass, heading, defaultIdx } = info;
552
+ const selected = id === selectedId;
553
+ const color = this.getOptionColor(defaultIdx, { isStartPos: false, selected });
554
+ const label = labels[pos];
555
+ const uiOption = {
556
+ id, color, text: compass, path: this.getPath(option), selected, direction: option.direction,
557
+ index: pos + 1, maneuver: label.maneuver, maneuverText: label.maneuverText,
558
+ compass, heading, roadName: label.roadName, roadLabel: label.roadLabel,
559
+ isDefault: defaultIdx === 0, degraded: label.degraded
560
+ };
561
+ if (selected)
562
+ uiOption.selectedBy = this.selectedBy;
563
+ option.ui = uiOption;
564
+ return uiOption;
498
565
  });
566
+ return result;
499
567
  }
500
568
  buildStartOptions() {
501
569
  const opts = this.startOptions ?? [];
502
570
  if (opts.length < 1)
503
571
  return [];
504
- if (opts.length < 2) {
505
- const option = opts[0];
506
- const id = this.buildId(option);
507
- const uiOption = { id, color: 'blue', text: 'OK', path: this.getPath(option) };
508
- option.ui = uiOption;
509
- return [uiOption];
510
- }
511
- return opts.map((option, idx) => {
512
- const text = this.getOptionText(option);
513
- const color = this.getOptionColor(idx, { isStartPos: true });
572
+ const build = (option, color, text) => {
514
573
  const id = this.buildId(option);
515
- const uiOption = { id, color, text, path: this.getPath(option) };
574
+ const { roadName, roadLabel } = (0, option_labels_1.getRoadLabel)(this.getWayTags(option));
575
+ const compass = this.getOptionText(option);
576
+ const uiOption = { id, color, text, path: this.getPath(option), compass, heading: this.getOptionHeading(option), roadName, roadLabel };
516
577
  option.ui = uiOption;
517
578
  return uiOption;
518
- });
579
+ };
580
+ if (opts.length < 2) {
581
+ return [build(opts[0], 'blue', 'OK')];
582
+ }
583
+ return opts.map((option, idx) => build(option, this.getOptionColor(idx, { isStartPos: true }), this.getOptionText(option)));
584
+ }
585
+ getWayTags(option) {
586
+ try {
587
+ const map = option?.map ?? (option?.path?.length ? this.getMapArea().getMap(option.path[0]) : undefined);
588
+ return map?.getWay(option?.id)?.tags;
589
+ }
590
+ catch {
591
+ return undefined;
592
+ }
593
+ }
594
+ getOptionHeading(option) {
595
+ const path = option?.path ?? [];
596
+ if (path.length < 2)
597
+ return undefined;
598
+ const heading = (0, geo_1.calculateHeaderFromPoints)(path[0], path[1]);
599
+ return Number.isFinite(heading) ? ((heading % 360) + 360) % 360 : undefined;
600
+ }
601
+ getOptionsLogProps() {
602
+ const options = this.options ?? [];
603
+ const named = options.filter(o => { const t = this.getWayTags(o); return !!(t?.name || t?.ref); }).length;
604
+ const degraded = options.filter(o => !Number.isFinite(o.direction)).length;
605
+ return { count: options.length, named, degraded };
519
606
  }
520
- async getStartOptions(map) {
607
+ getSelectionLogProps() {
608
+ const options = this.options ?? [];
609
+ const selected = this.selectedOption;
610
+ const idx = selected ? options.findIndex(o => this.buildId(o) === this.buildId(selected)) : -1;
611
+ const tags = this.getWayTags(selected);
612
+ const props = { by: this.selectedBy, count: options.length };
613
+ if (idx >= 0) {
614
+ props.index = idx + 1;
615
+ props.named = !!(tags?.name || tags?.ref);
616
+ if (Number.isFinite(selected.direction))
617
+ props.direction = Math.round(selected.direction);
618
+ }
619
+ return props;
620
+ }
621
+ async getStartOptions(map, rideSeq = this.rideSeq) {
521
622
  this.startOptions = [];
522
623
  if (!map)
523
624
  return;
@@ -538,6 +639,10 @@ let FreeRideService = (() => {
538
639
  optionManager.setMap(map);
539
640
  const options = await optionManager.getStartOptions(way, crossing);
540
641
  this.startOptions.push(...options);
642
+ if (rideSeq !== this.rideSeq) {
643
+ this.logEvent({ message: 'start options update ignored', reason: 'ride started' });
644
+ return;
645
+ }
541
646
  this.options = this.startOptions;
542
647
  }
543
648
  setStartPosition(position) {
@@ -563,22 +668,17 @@ let FreeRideService = (() => {
563
668
  }
564
669
  }
565
670
  getOptionText(option) {
566
- const path = option?.path ?? [];
567
- if (path.length < 2)
568
- return;
569
- const heading = (0, geo_1.calculateHeaderFromPoints)(path[0], path[1]) % 360;
570
- const idx = Number(heading / 45).toFixed(0);
571
- const texts = ['North', 'Northeast', 'East', 'Southeast', 'South', 'Southwest', 'West', 'Northwest', 'North'];
572
- return texts[idx];
671
+ const heading = this.getOptionHeading(option);
672
+ return heading === undefined ? undefined : (0, option_labels_1.getCompassWord)(heading);
573
673
  }
574
674
  getOptionColor(idx, props) {
575
675
  if (props?.isStartPos) {
576
- const colors = ['red', 'green', 'blue', 'yellow', 'orange', 'gray', 'pink', 'brown'];
676
+ const colors = ['#e5484d', '#3e8ef7', '#d23fa0', '#14a3b8', '#8b5cf6', '#a0643c'];
577
677
  return colors[idx % colors.length];
578
678
  }
579
679
  if (props?.selected)
580
- return 'green';
581
- const colors = ['red', 'purple', 'black', 'magenta', 'orange', 'brown', 'royalblue', 'silver'];
680
+ return '#8dc100';
681
+ const colors = ['red', 'purple', 'magenta', 'orange', 'brown', 'royalblue', 'teal', 'deeppink'];
582
682
  return colors[idx % colors.length];
583
683
  }
584
684
  getMapArea() {
@@ -39,11 +39,13 @@ const api_1 = require("../../../api");
39
39
  const decorators_1 = require("../../../base/decorators");
40
40
  const service_1 = require("../../../base/service");
41
41
  const types_1 = require("../../../base/types");
42
- const service_2 = require("../../service");
42
+ const service_2 = require("../../../ride/view-restriction/service");
43
+ const service_3 = require("../../service");
43
44
  const UNAVAILABLE_MESSAGES = {
44
45
  'need.playservices': 'Install Google Play Services to use this view',
45
46
  };
46
47
  const DEFAULT_UNAVAILABLE_MESSAGE = 'This view is currently unavailable on your device';
48
+ const SIMULATION_MESSAGE = 'Not available in simulated rides';
47
49
  let RideSettingsDisplayService = (() => {
48
50
  let _classDecorators = [decorators_1.Singleton];
49
51
  let _classDescriptor;
@@ -51,14 +53,17 @@ let RideSettingsDisplayService = (() => {
51
53
  let _classThis;
52
54
  let _classSuper = service_1.IncyclistService;
53
55
  let _instanceExtraInitializers = [];
56
+ let _getRideViewRestriction_decorators;
54
57
  let _getUserSettings_decorators;
55
58
  let _getBindings_decorators;
56
59
  var RideSettingsDisplayService = class extends _classSuper {
57
60
  static { _classThis = this; }
58
61
  static {
59
62
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
63
+ _getRideViewRestriction_decorators = [decorators_1.Injectable];
60
64
  _getUserSettings_decorators = [decorators_1.Injectable];
61
65
  _getBindings_decorators = [decorators_1.Injectable];
66
+ __esDecorate(this, null, _getRideViewRestriction_decorators, { kind: "method", name: "getRideViewRestriction", static: false, private: false, access: { has: obj => "getRideViewRestriction" in obj, get: obj => obj.getRideViewRestriction }, metadata: _metadata }, null, _instanceExtraInitializers);
62
67
  __esDecorate(this, 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);
63
68
  __esDecorate(this, null, _getBindings_decorators, { kind: "method", name: "getBindings", static: false, private: false, access: { has: obj => "getBindings" in obj, get: obj => obj.getBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
64
69
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
@@ -84,11 +89,17 @@ let RideSettingsDisplayService = (() => {
84
89
  delete this.observer;
85
90
  }
86
91
  getDisplayProps() {
87
- return {
88
- rideView: this.getRideView(),
92
+ const restriction = this.getRideViewRestriction().getActiveRestriction();
93
+ const props = {
94
+ rideView: restriction ? 'map' : this.getRideView(),
89
95
  rideViewOptions: this.getRideViewOptions(),
90
96
  ...this.getVideoOptions()
91
97
  };
98
+ if (restriction) {
99
+ const view = restriction.preferredView === 'sat' ? 'Satellite View' : 'Street View';
100
+ props.rideViewHelp = { label: `How to get ${view}` };
101
+ }
102
+ return props;
92
103
  }
93
104
  setRideView(rideView) {
94
105
  try {
@@ -137,6 +148,10 @@ let RideSettingsDisplayService = (() => {
137
148
  map.set(key, { label, disabled: true, message });
138
149
  return;
139
150
  }
151
+ if (this.getRideViewRestriction().getActiveRestriction()) {
152
+ map.set(key, { label, disabled: true, message: SIMULATION_MESSAGE, reason: 'simulation' });
153
+ return;
154
+ }
140
155
  map.set(key, { label });
141
156
  }
142
157
  isMobile() {
@@ -148,8 +163,11 @@ let RideSettingsDisplayService = (() => {
148
163
  isIOS() {
149
164
  return this.getBindings().appInfo?.getOS()?.platform === 'ios';
150
165
  }
166
+ getRideViewRestriction() {
167
+ return (0, service_2.useRideViewRestriction)();
168
+ }
151
169
  getUserSettings() {
152
- return (0, service_2.useUserSettings)();
170
+ return (0, service_3.useUserSettings)();
153
171
  }
154
172
  getBindings() {
155
173
  return (0, api_1.getBindings)();
@@ -0,0 +1,7 @@
1
+ export const MAPS_KEY_HELP_URL = 'https://incyclist.com/maps-api-key/';
2
+ export const MAPS_KEY_TEXTS = {
3
+ ownKey: 'your own Google Maps API key',
4
+ billing: 'Google then bills each ride that uses them to your own Google account.',
5
+ pendingRestart: 'Saved. Restart Incyclist to use it.',
6
+ helpLabel: 'How to create a key',
7
+ };
@@ -1 +1,2 @@
1
1
  export * from './service';
2
+ export * from './consts';
@@ -47,20 +47,24 @@ let GoogleMapsService = (() => {
47
47
  let _instanceExtraInitializers = [];
48
48
  let _getSecretBindings_decorators;
49
49
  let _getUserSettings_decorators;
50
+ let _getBindings_decorators;
50
51
  var GoogleMapsService = class extends _classSuper {
51
52
  static { _classThis = this; }
52
53
  static {
53
54
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
54
55
  _getSecretBindings_decorators = [Injectable];
55
56
  _getUserSettings_decorators = [Injectable];
57
+ _getBindings_decorators = [Injectable];
56
58
  __esDecorate(this, null, _getSecretBindings_decorators, { kind: "method", name: "getSecretBindings", static: false, private: false, access: { has: obj => "getSecretBindings" in obj, get: obj => obj.getSecretBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
57
59
  __esDecorate(this, 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);
60
+ __esDecorate(this, null, _getBindings_decorators, { kind: "method", name: "getBindings", static: false, private: false, access: { has: obj => "getBindings" in obj, get: obj => obj.getBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
58
61
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
62
  GoogleMapsService = _classThis = _classDescriptor.value;
60
63
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
64
  __runInitializers(_classThis, _classExtraInitializers);
62
65
  }
63
66
  api = __runInitializers(this, _instanceExtraInitializers);
67
+ latchedKey;
64
68
  constructor() {
65
69
  super('GoogleMaps');
66
70
  const observer = this.getUserSettings().requestNotifyOnChange?.('maps', 'GOOGLE_MAPS_API_KEY');
@@ -81,6 +85,7 @@ let GoogleMapsService = (() => {
81
85
  const settings = this.getUserSettings();
82
86
  const personalKey = settings.getValue('GOOGLE_MAPS_API_KEY', undefined);
83
87
  const developmentMode = settings.get('mode', 'production') === 'development';
88
+ this.latchPersonalKey(personalKey);
84
89
  if (developmentMode)
85
90
  return personalKey ?? 'development';
86
91
  return personalKey;
@@ -90,8 +95,33 @@ let GoogleMapsService = (() => {
90
95
  const personalKey = settings.get('GOOGLE_MAPS_API_KEY', undefined);
91
96
  return personalKey !== undefined;
92
97
  }
98
+ hasActivePersonalApiKey() {
99
+ try {
100
+ if (this.isMobile())
101
+ return false;
102
+ this.latchPersonalKey(this.readPersonalKey());
103
+ return this.latchedKey !== '';
104
+ }
105
+ catch (err) {
106
+ this.logError(err, 'hasActivePersonalApiKey');
107
+ return false;
108
+ }
109
+ }
110
+ isPersonalApiKeyPendingRestart() {
111
+ try {
112
+ if (this.isMobile())
113
+ return false;
114
+ this.latchPersonalKey(this.readPersonalKey());
115
+ const current = this.normalizeKey(this.readPersonalKey());
116
+ return current !== '' && current !== this.latchedKey;
117
+ }
118
+ catch (err) {
119
+ this.logError(err, 'isPersonalApiKeyPendingRestart');
120
+ return false;
121
+ }
122
+ }
93
123
  onPersonalApiKeySet() {
94
- this.emit('reload');
124
+ this.reload();
95
125
  }
96
126
  hasDevelopmentApiKey() {
97
127
  const settings = this.getUserSettings();
@@ -107,6 +137,18 @@ let GoogleMapsService = (() => {
107
137
  this.emit('reload');
108
138
  }
109
139
  }
140
+ readPersonalKey() {
141
+ return this.getUserSettings().getValue('GOOGLE_MAPS_API_KEY', undefined);
142
+ }
143
+ normalizeKey(key) {
144
+ return typeof key === 'string' ? key.trim() : '';
145
+ }
146
+ latchPersonalKey(key) {
147
+ this.latchedKey ??= this.normalizeKey(key);
148
+ }
149
+ isMobile() {
150
+ return this.getBindings()?.appInfo?.getChannel() === 'mobile';
151
+ }
110
152
  getSecret(key) {
111
153
  return this.getSecretBindings()?.getSecret(key);
112
154
  }
@@ -116,6 +158,9 @@ let GoogleMapsService = (() => {
116
158
  getUserSettings() {
117
159
  return useUserSettings();
118
160
  }
161
+ getBindings() {
162
+ return getBindings();
163
+ }
119
164
  };
120
165
  return GoogleMapsService = _classThis;
121
166
  })();
@@ -3,6 +3,7 @@ import clone from "../../utils/clone";
3
3
  import { concatPaths, isAllowed, isOneWay, isRoundabout, pointEquals, removeDuplicatePaths, removeDuplicates, splitAtIndex, splitAtPoint } from "./utils";
4
4
  import { calculateDistance } from "../../utils/geo";
5
5
  import { waitNextTick } from "../../utils";
6
+ import { normalizeAngle } from "../../routes/free-ride/option-labels";
6
7
  export class OptionManager {
7
8
  service;
8
9
  map;
@@ -102,9 +103,7 @@ export class OptionManager {
102
103
  const currentDirection = this.map?.getHeading(way, 'end') ?? 0;
103
104
  options.forEach((option) => {
104
105
  const direction = this.map?.getHeading(option, 'start') ?? 0;
105
- option.direction = direction - currentDirection;
106
- if (option.direction > 180)
107
- option.direction = option.direction - 360;
106
+ option.direction = normalizeAngle(direction - currentDirection);
108
107
  });
109
108
  if (props?.minDistance) {
110
109
  await this.checkMinDistance(options, props.minDistance);