Skip to content

Commit f229beb

Browse files
underootmourner
authored andcommitted
Fix backward-compatibility for not-defined Marker options (internal-2374)
1 parent 87938fb commit f229beb

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

src/ui/marker.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export type MarkerOptions = {
3333
};
3434

3535
const defaultOptions: MarkerOptions = {
36-
anchor: 'center',
37-
color: '#3FB1CE',
38-
scale: 1,
39-
draggable: false,
40-
clickTolerance: 0,
4136
rotation: 0,
4237
rotationAlignment: 'auto',
4338
pitchAlignment: 'auto',
@@ -129,18 +124,29 @@ export default class Marker extends Evented<MarkerEvents> {
129124
'_clearFadeTimer'
130125
], this);
131126

132-
options = extend({}, defaultOptions, options);
133-
134-
this._anchor = options.anchor;
135-
this._color = options.color;
136-
this._scale = options.scale;
137-
this._draggable = options.draggable;
138-
this._clickTolerance = options.clickTolerance;
139-
this._rotation = options.rotation;
140-
this._rotationAlignment = options.rotationAlignment;
141-
this._pitchAlignment = options.pitchAlignment;
142-
this._occludedOpacity = options.occludedOpacity;
143-
this._altitude = options.altitude;
127+
const {
128+
anchor = 'center',
129+
color = '#3FB1CE',
130+
scale = 1,
131+
draggable = false,
132+
clickTolerance = 0,
133+
rotation = defaultOptions.rotation,
134+
rotationAlignment = defaultOptions.rotationAlignment,
135+
pitchAlignment = defaultOptions.pitchAlignment,
136+
occludedOpacity = defaultOptions.occludedOpacity,
137+
altitude = defaultOptions.altitude,
138+
} = options || {};
139+
140+
this._anchor = anchor;
141+
this._color = color;
142+
this._scale = scale;
143+
this._draggable = draggable;
144+
this._clickTolerance = clickTolerance;
145+
this._rotation = rotation;
146+
this._rotationAlignment = rotationAlignment;
147+
this._pitchAlignment = pitchAlignment;
148+
this._occludedOpacity = occludedOpacity;
149+
this._altitude = altitude;
144150

145151
this._state = 'inactive';
146152
this._isDragging = false;

test/unit/ui/marker.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ test('Marker uses a default marker element with an appropriate offset', () => {
2929
expect(marker.getOffset().equals(new Point(0, -14))).toBeTruthy();
3030
});
3131

32+
test('Marker retain default options for passed undefined', () => {
33+
const marker = new Marker({
34+
rotation: undefined,
35+
altitude: undefined,
36+
});
37+
38+
expect(marker.getRotation()).toEqual(0);
39+
expect(marker.getAltitude()).toEqual(0);
40+
});
41+
3242
test('Marker uses a default marker element with custom color', () => {
3343
const marker = new Marker({color: '#123456'});
3444
expect(marker.getElement().innerHTML.includes('#123456')).toBeTruthy();

0 commit comments

Comments
 (0)