Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid setting marker opacity twice #5441

Merged
merged 7 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be simplified even further:

this._opacity = opacity !== undefined ? opacity : '1';
this._opacityWhenCovered = opacityWhenCovered!== undefined ? opacityWhenCovered : '0.2';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of calling marker.setOpacity(something);:

  • the expected result is that this._opacityWhenCovered will not be changed
  • in the suggested code it will reset it to the default '0.2'

same goes for calling marker.setOpacity(undefined, something);

I agree that a oneliner shortening is possible, but it will be somewhat less-understandable.

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
Loading