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

debounce rounding position on Marker #11167

Merged
merged 15 commits into from
Dec 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class Marker extends Evented {
_rotationAlignment: string;
_originalTabIndex: ?string; // original tabindex of _element
_fadeTimer: ?TimeoutID;
_updateFrameId: number;

constructor(options?: Options, legacyOptions?: Options) {
super();
Expand Down Expand Up @@ -508,6 +509,7 @@ export default class Marker extends Evented {
}

_update(e?: {type: 'move' | 'moveend'}) {
window.cancelAnimationFrame(this._updateFrameId);
if (!this._map) return;

if (this._map.transform.renderWorldCopies) {
Expand All @@ -534,7 +536,12 @@ export default class Marker extends Evented {
// we only round them when _update is called with `moveend` or when its called with
// no arguments (when the Marker is initialized or Marker#setLngLat is invoked).
if (!e || e.type === "moveend") {
this._pos = this._pos.round();
this._updateFrameId = window.requestAnimationFrame(() => {
if (this._element && this._pos && this._anchor) {
this._pos = this._pos.round();
DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I wonder if we could deduplicate this long line of code that's duplicated below, but not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I don't have any idea, do you have?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe seperate that line into something like:

function _updateDOM(){   DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`);}

If you move the pitch and location calculating code into this function, then it can live in the marker's scope.

Copy link
Contributor Author

@malekeym malekeym Dec 15, 2021

Choose a reason for hiding this comment

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

I separate some methods, I appreciate reviewing changes and giving your feedback

}
});
SnailBones marked this conversation as resolved.
Show resolved Hide resolved
}

this._map._requestDomTask(() => {
Expand Down