mobility-toolbox-js 3.2.0 → 3.2.2

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.
@@ -8,7 +8,7 @@ export interface RoutingAPIOptions {
8
8
  * This class provides convenience methods to use to the [geOps Routing API](https://developer.geops.io/apis/routing).
9
9
  *
10
10
  * @example
11
- * import { RoutingAPI } from 'mobility-toolbox-js';
11
+ * import { RoutingAPI } from 'mobility-toolbox-js/api';
12
12
  *
13
13
  * const api = new RoutingAPI({
14
14
  * apiKey: [yourApiKey],
package/api/RoutingAPI.js CHANGED
@@ -3,7 +3,7 @@ import HttpAPI from './HttpAPI';
3
3
  * This class provides convenience methods to use to the [geOps Routing API](https://developer.geops.io/apis/routing).
4
4
  *
5
5
  * @example
6
- * import { RoutingAPI } from 'mobility-toolbox-js';
6
+ * import { RoutingAPI } from 'mobility-toolbox-js/api';
7
7
  *
8
8
  * const api = new RoutingAPI({
9
9
  * apiKey: [yourApiKey],
@@ -136,7 +136,29 @@ const cache = {};
136
136
  * @private
137
137
  */
138
138
  const realtimeDefaultStyle = (trajectory, viewState, options) => {
139
- const { delayDisplay = 300000, delayOutlineColor = '#000', getBgColor = () => '#000', getDelayColor = () => '#000', getDelayFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getDelayText = () => null, getMaxRadiusForStrokeAndDelay = () => 7, getMaxRadiusForText = () => 10, getRadius = () => 0, getText = (text) => text, getTextColor = () => '#000', getTextFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getTextSize = () => 14, hoverVehicleId, selectedVehicleId, useDelayStyle, } = options;
139
+ const { delayDisplay = 300000, delayOutlineColor = '#000', getBgColor = () => {
140
+ return '#000';
141
+ }, getDelayColor = () => {
142
+ return '#000';
143
+ }, getDelayFont = (fontSize) => {
144
+ return `bold ${fontSize}px arial, sans-serif`;
145
+ }, getDelayText = () => {
146
+ return null;
147
+ }, getMaxRadiusForStrokeAndDelay = () => {
148
+ return 7;
149
+ }, getMaxRadiusForText = () => {
150
+ return 10;
151
+ }, getRadius = () => {
152
+ return 0;
153
+ }, getText = (text) => {
154
+ return text;
155
+ }, getTextColor = () => {
156
+ return '#000';
157
+ }, getTextFont = (fontSize) => {
158
+ return `bold ${fontSize}px arial, sans-serif`;
159
+ }, getTextSize = () => {
160
+ return 14;
161
+ }, hoverVehicleId, selectedVehicleId, useDelayStyle, } = options;
140
162
  const { pixelRatio = 1, zoom } = viewState;
141
163
  let { type } = trajectory.properties;
142
164
  const { delay, line, operator_provides_realtime_journey: operatorProvidesRealtime, state, train_id: id, } = trajectory.properties;
@@ -173,10 +195,7 @@ const realtimeDefaultStyle = (trajectory, viewState, options) => {
173
195
  // Optimize the cache key, very important in high zoom level
174
196
  let key = `${radius}${hover || selected}`;
175
197
  if (useDelayStyle) {
176
- key += `${operatorProvidesRealtime}${delay}`;
177
- if (isDisplayStrokeAndDelay) {
178
- key += `${cancelled}`;
179
- }
198
+ key += `${operatorProvidesRealtime}${delay}${cancelled}`;
180
199
  }
181
200
  else {
182
201
  key += `${color || type}`;
@@ -1,10 +1,10 @@
1
+ import type { Coordinate } from 'ol/coordinate';
1
2
  import { FeatureCollection } from 'geojson';
2
3
  import GeoJSON from 'ol/format/GeoJSON';
3
4
  import { RealtimeAPI } from '../../api';
4
5
  import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
5
6
  import { AnyCanvas, LayerGetFeatureInfoOptions, RealtimeGeneralizationLevel, RealtimeMode, RealtimeMot, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTenant, RealtimeTrainId, RealtimeTrajectory, ViewState } from '../../types';
6
7
  import { FilterFunction, SortFunction } from '../typedefs';
7
- import type { Coordinate } from 'ol/coordinate';
8
8
  export interface RealtimeEngineOptions {
9
9
  api?: RealtimeAPI;
10
10
  apiKey?: string;
@@ -53,8 +53,12 @@ class RealtimeEngine {
53
53
  }
54
54
  constructor(options) {
55
55
  this.isIdle = false;
56
- this.getViewState = () => ({});
57
- this.shouldRender = () => true;
56
+ this.getViewState = () => {
57
+ return {};
58
+ };
59
+ this.shouldRender = () => {
60
+ return true;
61
+ };
58
62
  this._mode = options.mode || RealtimeModes.TOPOGRAPHIC;
59
63
  this._speed = options.speed || 1; // If live property is true. The speed is ignored.
60
64
  this._style = options.style || realtimeDefaultStyle;
@@ -86,8 +90,16 @@ class RealtimeEngine {
86
90
  this.useDebounce = options.useDebounce || false;
87
91
  this.useRequestAnimationFrame = options.useRequestAnimationFrame || false;
88
92
  this.useThrottle = options.useThrottle !== false; // the default behavior
89
- this.getViewState = options.getViewState || (() => ({}));
90
- this.shouldRender = options.shouldRender || (() => true);
93
+ this.getViewState =
94
+ options.getViewState ||
95
+ (() => {
96
+ return {};
97
+ });
98
+ this.shouldRender =
99
+ options.shouldRender ||
100
+ (() => {
101
+ return true;
102
+ });
91
103
  this.onRender = options.onRender;
92
104
  this.onIdle = options.onIdle;
93
105
  this.onStart = options.onStart;
@@ -481,7 +493,6 @@ class RealtimeEngine {
481
493
  /* @private */
482
494
  this.mots = this.getMotsByZoom(zoomFloor);
483
495
  if (this.mots) {
484
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
485
496
  bbox.push(`mots=${this.mots}`);
486
497
  }
487
498
  if (this.tenant) {
@@ -492,7 +503,6 @@ class RealtimeEngine {
492
503
  }
493
504
  if (this.bboxParameters) {
494
505
  Object.entries(this.bboxParameters).forEach(([key, value]) => {
495
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
496
506
  bbox.push(`${key}=${value}`);
497
507
  });
498
508
  }
@@ -100,7 +100,9 @@ export const textColors = [
100
100
  */
101
101
  export const getTypeIndex = (type) => {
102
102
  if (typeof type === 'string') {
103
- return types.findIndex((t) => t.test(type));
103
+ return types.findIndex((t) => {
104
+ return t.test(type);
105
+ });
104
106
  }
105
107
  return type;
106
108
  };
@@ -152,7 +154,6 @@ export const getTextSize = (ctx, markerSize, text, fontSize, getTextFont) => {
152
154
  const maxiter = 25;
153
155
  let i = 0;
154
156
  while (newText.width > markerSize - 6 && i < maxiter) {
155
- // eslint-disable-next-line no-param-reassign
156
157
  fontSize -= 0.5;
157
158
  ctx.font = getTextFont(fontSize, text);
158
159
  newText = ctx.measureText(text);