mobility-toolbox-js 1.4.1-beta.2 → 1.4.4

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.
@@ -491,8 +491,15 @@ class TralisAPI {
491
491
  this.conn.get(
492
492
  params,
493
493
  (data) => {
494
- // Remove the delay from arrivalTime nnd departureTime
495
- resolve(cleanStopTime(data.content && data.content[0]));
494
+ if (data.content && data.content.length) {
495
+ const content = data.content.map((stopSequence) => {
496
+ return cleanStopTime(stopSequence);
497
+ });
498
+
499
+ // Remove the delay from arrivalTime and departureTime
500
+ resolve(content);
501
+ }
502
+ resolve([]);
496
503
  },
497
504
  (err) => {
498
505
  reject(err);
@@ -527,8 +534,14 @@ class TralisAPI {
527
534
  this.subscribe(
528
535
  `stopsequence_${id}`,
529
536
  (data) => {
530
- // Remove the delay from arrivalTime nad departureTime
531
- onMessage(cleanStopTime(data.content && data.content[0]));
537
+ if (data.content && data.content.length) {
538
+ const content = data.content.map((stopSequence) => {
539
+ return cleanStopTime(stopSequence);
540
+ });
541
+
542
+ // Remove the delay from arrivalTime and departureTime
543
+ onMessage(content);
544
+ }
532
545
  },
533
546
  (err) => {
534
547
  // eslint-disable-next-line no-console
@@ -422,20 +422,6 @@ const TrackerLayerMixin = (Base) =>
422
422
 
423
423
  const renderTime = this.live ? Date.now() : this.time;
424
424
 
425
- // Avoid useless render before the next tick.
426
- if (
427
- this.live &&
428
- resolution === this.lastRenderResolution &&
429
- rotation === this.lastRenderRotation &&
430
- renderTime - this.lastRenderTime < this.updateTimeDelay
431
- ) {
432
- return;
433
- }
434
-
435
- this.lastRenderTime = renderTime;
436
- this.lastRenderResolution = resolution;
437
- this.lastRenderRotation = rotation;
438
-
439
425
  this.tracker.renderTrajectories(
440
426
  renderTime,
441
427
  size,
@@ -432,22 +432,29 @@ const TrajservLayerMixin = (TrackerLayer) =>
432
432
  const z = Math.min(Math.floor(zoom || 1), 16);
433
433
  const hover = this.hoverVehicleId === id;
434
434
  const selected = this.selectedVehicleId === id;
435
- const key = `${z}${type}${name}${operatorProvidesRealtime}${delay}${hover}${selected}${cancelled}`;
435
+ let key = `${z}${type}${name}${operatorProvidesRealtime}${delay}${hover}${selected}${cancelled}`;
436
+
437
+ // Calcul the radius of the circle
438
+ let radius = getRadius(type, z) * this.pixelRatio;
439
+ const isDisplayStrokeAndDelay = radius >= 7 * this.pixelRatio;
440
+ if (hover || selected) {
441
+ radius = isDisplayStrokeAndDelay
442
+ ? radius + 5 * this.pixelRatio
443
+ : 14 * this.pixelRatio;
444
+ }
445
+ const mustDrawText = radius > 10 * this.pixelRatio;
436
446
 
437
- if (!this.styleCache[key]) {
438
- let radius = getRadius(type, z) * this.pixelRatio;
439
- const isDisplayStrokeAndDelay = radius >= 7 * this.pixelRatio;
447
+ // Optimize the cache key, very important in high zoom level
448
+ if (!mustDrawText) {
449
+ key = `${z}${type}${color}${operatorProvidesRealtime}${delay}${hover}${selected}${cancelled}`;
450
+ }
440
451
 
452
+ if (!this.styleCache[key]) {
441
453
  if (radius === 0) {
442
454
  this.styleCache[key] = null;
443
455
  return null;
444
456
  }
445
457
 
446
- if (hover || selected) {
447
- radius = isDisplayStrokeAndDelay
448
- ? radius + 5 * this.pixelRatio
449
- : 14 * this.pixelRatio;
450
- }
451
458
  const margin = 1 * this.pixelRatio;
452
459
  const radiusDelay = radius + 2;
453
460
  const markerSize = radius * 2;
@@ -525,8 +532,8 @@ const TrajservLayerMixin = (TrackerLayer) =>
525
532
  ctx.restore();
526
533
 
527
534
  // Draw text in the circle
528
- if (radius > 10) {
529
- const fontSize = Math.max(radius, 10);
535
+ if (mustDrawText) {
536
+ const fontSize = Math.max(radius, 10 * this.pixelRatio);
530
537
  const textSize = getTextSize(ctx, markerSize, name, fontSize);
531
538
 
532
539
  // Draw a stroke to the text only if a provider provides realtime but we don't use it.