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

Stop marker from flashing on initial load if it's occluded by the globe #13344

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 2 additions & 17 deletions src/ui/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export default class Marker extends Evented<MarkerEvents> {
_pitchAlignment: string;
_rotationAlignment: string;
_originalTabIndex: string | null | undefined; // original tabindex of _element
_fadeTimer: number | null | undefined;
_updateFrameId: number;
_updateMoving: () => void;
_occludedOpacity: number;
Expand All @@ -110,7 +109,6 @@ export default class Marker extends Evented<MarkerEvents> {
'_addDragHandler',
'_onMapClick',
'_onKeyPress',
'_clearFadeTimer'
], this);

this._anchor = (options && options.anchor) || 'center';
Expand Down Expand Up @@ -217,7 +215,6 @@ export default class Marker extends Evented<MarkerEvents> {
map.getCanvasContainer().appendChild(this._element);
map.on('move', this._updateMoving);
map.on('moveend', this._update);
map.on('remove', this._clearFadeTimer);
map._addMarker(this);
this.setDraggable(this._draggable);
this._update();
Expand Down Expand Up @@ -250,11 +247,9 @@ export default class Marker extends Evented<MarkerEvents> {
map.off('touchend', this._onUp);
map.off('mousemove', this._onMove);
map.off('touchmove', this._onMove);
map.off('remove', this._clearFadeTimer);
map._removeMarker(this);
this._map = undefined;
}
this._clearFadeTimer();
this._element.remove();
if (this._popup) this._popup.remove();
return this;
Expand Down Expand Up @@ -453,7 +448,6 @@ export default class Marker extends Evented<MarkerEvents> {
const pos = this._pos;

if (!pos || pos.x < 0 || pos.x > map.transform.width || pos.y < 0 || pos.y > map.transform.height) {
this._clearFadeTimer();
return;
}
const mapLocation = map.unproject(pos);
Expand All @@ -472,15 +466,6 @@ export default class Marker extends Evented<MarkerEvents> {
if (this._popup) {
this._popup._setOpacity(opacity);
}

this._fadeTimer = null;
}

_clearFadeTimer() {
if (this._fadeTimer) {
clearTimeout(this._fadeTimer);
this._fadeTimer = null;
}
}

_updateDOM() {
Expand Down Expand Up @@ -594,8 +579,8 @@ export default class Marker extends Evented<MarkerEvents> {
this._updateDOM();
}

if ((map._showingGlobe() || map.getTerrain() || map.getFog()) && !this._fadeTimer) {
this._fadeTimer = window.setTimeout(this._evaluateOpacity.bind(this), 60);
if (map._showingGlobe() || map.getTerrain() || map.getFog()) {
this._evaluateOpacity();
}
});
}
Expand Down
3 changes: 0 additions & 3 deletions test/unit/terrain/terrain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,6 @@ describe('Marker interaction and raycast', () => {
});

test('Occluded', async () => {
marker._fadeTimer = null;
// Occlusion is happening with Timers API. Advance them
vi.spyOn(window, 'setTimeout').mockImplementation((cb) => cb());
marker.setLngLat(terrainTopLngLat);
const bottomLngLat = tr.pointLocation3D(new Point(terrainTop.x, tr.height));
// Raycast returns distance to closer point evaluates to occluded marker.
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ui/marker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,8 @@ describe('Marker and fog', () => {
map.setBearing(90);
map.setPitch(70);
marker.setLngLat([4, 0]);

expect(marker.getElement().style.opacity).toEqual('0');

await new Promise(resolve => {
setTimeout(() => {
Expand Down