• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / react-map-gl / 12898518679

22 Jan 2025 12:26AM UTC coverage: 85.315%. First build
12898518679

Pull #2467

github

web-flow
Merge 7508071ae into 3032b6964
Pull Request #2467: [v8] react-mapbox module

892 of 1107 branches covered (80.58%)

Branch coverage included in aggregate %.

1856 of 2152 new or added lines in 22 files covered. (86.25%)

5609 of 6513 relevant lines covered (86.12%)

23.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.27
/modules/react-mapbox/src/utils/transform.ts
1
import type {MapboxProps} from '../mapbox/mapbox';
1✔
2
import type {ViewState} from '../types/common';
1✔
3
import type {Transform} from '../types/internal';
1✔
4
import {deepEqual} from './deep-equal';
1✔
5

1✔
6
/**
1✔
7
 * Make a copy of a transform
1✔
8
 * @param tr
1✔
9
 */
1✔
10
export function cloneTransform(tr: Transform): Transform {
1✔
11
  const newTransform = tr.clone();
12✔
12
  // Work around mapbox bug - this value is not assigned in clone(), only in resize()
12✔
13
  newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;
12✔
14
  return newTransform;
12✔
15
}
12✔
16

1✔
17
/**
1✔
18
 * Copy projection from one transform to another. This only applies to mapbox-gl transforms
1✔
19
 * @param src the transform to copy projection settings from
1✔
20
 * @param dest to transform to copy projection settings to
1✔
21
 */
1✔
22
export function syncProjection(src: Transform, dest: Transform): void {
1✔
23
  if (!src.getProjection) {
81✔
24
    return;
81✔
25
  }
81!
NEW
26
  const srcProjection = src.getProjection();
×
NEW
27
  const destProjection = dest.getProjection();
×
NEW
28

×
NEW
29
  if (!deepEqual(srcProjection, destProjection)) {
×
NEW
30
    dest.setProjection(srcProjection);
×
NEW
31
  }
×
32
}
81✔
33

1✔
34
/**
1✔
35
 * Capture a transform's current state
1✔
36
 * @param transform
1✔
37
 * @returns descriptor of the view state
1✔
38
 */
1✔
39
export function transformToViewState(tr: Transform): ViewState {
1✔
40
  return {
176✔
41
    longitude: tr.center.lng,
176✔
42
    latitude: tr.center.lat,
176✔
43
    zoom: tr.zoom,
176✔
44
    pitch: tr.pitch,
176✔
45
    bearing: tr.bearing,
176✔
46
    padding: tr.padding
176✔
47
  };
176✔
48
}
176✔
49

1✔
50
/* eslint-disable complexity */
1✔
51
/**
1✔
52
 * Mutate a transform to match the given view state
1✔
53
 * @param transform
1✔
54
 * @param viewState
1✔
55
 * @returns true if the transform has changed
1✔
56
 */
1✔
57
export function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean {
1✔
58
  const v: Partial<ViewState> = props.viewState || props;
126✔
59
  let changed = false;
126✔
60

126✔
61
  if ('zoom' in v) {
126✔
62
    const zoom = tr.zoom;
86✔
63
    tr.zoom = v.zoom;
86✔
64
    changed = changed || zoom !== tr.zoom;
86✔
65
  }
86✔
66
  if ('bearing' in v) {
126✔
67
    const bearing = tr.bearing;
79✔
68
    tr.bearing = v.bearing;
79✔
69
    changed = changed || bearing !== tr.bearing;
79✔
70
  }
79✔
71
  if ('pitch' in v) {
126✔
72
    const pitch = tr.pitch;
80✔
73
    tr.pitch = v.pitch;
80✔
74
    changed = changed || pitch !== tr.pitch;
80✔
75
  }
80✔
76
  if (v.padding && !tr.isPaddingEqual(v.padding)) {
126✔
77
    changed = true;
1✔
78
    tr.padding = v.padding;
1✔
79
  }
1✔
80
  if ('longitude' in v && 'latitude' in v) {
126✔
81
    const center = tr.center;
85✔
82
    // @ts-ignore
85✔
83
    tr.center = new center.constructor(v.longitude, v.latitude);
85✔
84
    changed = changed || center !== tr.center;
85✔
85
  }
85✔
86
  return changed;
126✔
87
}
126✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc