Skip to content

Commit

Permalink
Reset opacity when setOpacity is called without args
Browse files Browse the repository at this point in the history
  • Loading branch information
sbachinin committed Jan 28, 2024
1 parent b04b2b1 commit 2da1f26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/ui/marker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,16 @@ describe('marker', () => {
map.remove();
});

test('Resets opacity to default when setOpacity is called without arguments', () => {
const map = createMap();
const marker = new Marker({opacity: 0.7})
.setLngLat([0, 0])
.addTo(map);
marker.setOpacity();
expect(marker.getElement().style.opacity).toBe('1');
map.remove();
});

test('Marker changes opacity behind terrain and when terrain is removed', () => {
const map = createMap();
map.transform.lngLatToCameraDepth = () => .95; // Mocking distance to marker
Expand Down
7 changes: 6 additions & 1 deletion src/ui/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,16 @@ export class Marker extends Evented {
}

/**
* Sets the `opacity` property of the marker.
* Sets the `opacity` and `opacityWhenCovered` properties of the marker.
* @param opacity - Sets the `opacity` property of the marker.
* @param opacityWhenCovered - Sets the `opacityWhenCovered` property of the marker.
* @returns `this`
*/
setOpacity(opacity?: number, opacityWhenCovered?: number): this {
if (opacity === undefined && opacityWhenCovered === undefined) {
this._opacity = 1;
this._opacityWhenCovered = 0.2;
}
if (opacity !== undefined) {
this._opacity = opacity;
}
Expand Down

0 comments on commit 2da1f26

Please sign in to comment.