Skip to content

Commit

Permalink
Avoid setting marker opacity twice (#5441)
Browse files Browse the repository at this point in the history
* avoid setting opacity twice

* updating CHANGELOG

* add PR number and link to CHANGELOG

* setOpacity handles being called from constructor
  • Loading branch information
erasta authored Feb 2, 2025
1 parent cc9f170 commit fcbe9e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### ✨ Features and improvements

- Avoid setting marker opacity twice. ([#5441](https://github.com/maplibre/maplibre-gl-js/pull/5441))
- Fix rendering Japanese symbols which are accidentally ignored. ([#5421](https://github.com/maplibre/maplibre-gl-js/pull/5421)
- _...Add new stuff here..._

Expand Down
6 changes: 4 additions & 2 deletions src/ui/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export class Marker extends Evented {
this._rotation = options && options.rotation || 0;
this._rotationAlignment = options && options.rotationAlignment || 'auto';
this._pitchAlignment = options && options.pitchAlignment && options.pitchAlignment !== 'auto' ? options.pitchAlignment : this._rotationAlignment;
this.setOpacity(); // set default opacity
this.setOpacity(options?.opacity, options?.opacityWhenCovered);

if (!options || !options.element) {
Expand Down Expand Up @@ -857,16 +856,19 @@ export class Marker extends Evented {
* @param opacityWhenCovered - Sets the `opacityWhenCovered` property of the marker.
*/
setOpacity(opacity?: string, opacityWhenCovered?: string): this {
if (opacity === undefined && opacityWhenCovered === undefined) {
// Reset opacity when called without params or from constructor
if (this._opacity === undefined || (opacity === undefined && opacityWhenCovered === undefined)) {
this._opacity = '1';
this._opacityWhenCovered = '0.2';
}

if (opacity !== undefined) {
this._opacity = opacity;
}
if (opacityWhenCovered !== undefined) {
this._opacityWhenCovered = opacityWhenCovered;
}

if (this._map) {
this._updateOpacity(true);
}
Expand Down

0 comments on commit fcbe9e5

Please sign in to comment.