Skip to content

Commit 865e5b6

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Drop Intl.NumberFormat support check in the ScaleControl
GitOrigin-RevId: f950badf241d8937390a3b6f9b5d24790c4df86f
1 parent a196b5f commit 865e5b6

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

src/ui/control/scale_control.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ class ScaleControl implements IControl {
4444
_map: Map;
4545
_container: HTMLElement;
4646
_language?: string | string[];
47-
_isNumberFormatSupported: boolean;
4847
options: ScaleControlOptions;
4948

5049
constructor(options: ScaleControlOptions = {}) {
5150
this.options = Object.assign({}, defaultOptions, options);
5251

53-
// Some old browsers (e.g., Safari < 14.1) don't support the "unit" style in NumberFormat.
54-
// This is a workaround to display the scale without proper internationalization support.
55-
this._isNumberFormatSupported = isNumberFormatSupported();
56-
5752
bindAll([
5853
'_update',
5954
'_setScale',
@@ -104,7 +99,7 @@ class ScaleControl implements IControl {
10499
const distance = getRoundNum(maxDistance);
105100
const ratio = distance / maxDistance;
106101

107-
if (this._isNumberFormatSupported && unit !== 'nautical-mile') {
102+
if (unit !== 'nautical-mile') {
108103
this._container.innerHTML = new Intl.NumberFormat(this._language, {style: 'unit', unitDisplay: 'short', unit}).format(distance);
109104
} else {
110105
this._container.innerHTML = `${distance}&nbsp;${unitAbbr[unit]}`;
@@ -150,15 +145,6 @@ class ScaleControl implements IControl {
150145

151146
export default ScaleControl;
152147

153-
function isNumberFormatSupported() {
154-
try {
155-
new Intl.NumberFormat('en', {style: 'unit', unitDisplay: 'short', unit: 'meter'});
156-
return true;
157-
} catch (_: unknown) {
158-
return false;
159-
}
160-
}
161-
162148
function getDecimalRoundNum(d: number) {
163149
const multiplier = Math.pow(10, Math.ceil(-Math.log(d) / Math.LN10));
164150
return Math.round(d * multiplier) / multiplier;

test/unit/ui/control/scale.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,3 @@ test('ScaleControl should support different projections', () => {
102102
expect(contents).not.toMatch(/NaN|undefined/);
103103
}
104104
});
105-
106-
test('ScaleControl should work in legacy safari', () => {
107-
const realNumberFormat = Intl.NumberFormat;
108-
Intl.NumberFormat = function (arg, options) {
109-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
110-
if (options && options.style === 'unit') {
111-
throw new Error('not supported');
112-
}
113-
return realNumberFormat.call(Intl, arg, options);
114-
};
115-
try {
116-
const map = createMap();
117-
const scale = new ScaleControl();
118-
const selector = '.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale';
119-
map.addControl(scale);
120-
map._domRenderTaskQueue.run();
121-
122-
const contents = map.getContainer().querySelector(selector).innerHTML;
123-
expect(contents).toMatch(/km/);
124-
} finally {
125-
Intl.NumberFormat = realNumberFormat;
126-
}
127-
});

0 commit comments

Comments
 (0)