mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(map): draw points of interest on the world copy the view is on
POIs fetched for a view west of the trip frame's seam were drawn one world away, off screen.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { frameLine, frameLng, tripLngFrame } from './lngFrame';
|
||||
import { frameLine, frameLng, tripLngFrame, viewLngFrame } from './lngFrame';
|
||||
|
||||
const LA = -118.4;
|
||||
const AUCKLAND = 174.8;
|
||||
@@ -83,3 +83,32 @@ describe('frameLine', () => {
|
||||
expect(drawn.map(([, lng]) => lng)).toEqual([30, 20]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('viewLngFrame', () => {
|
||||
it('keeps the plain world while the view looks at the real world', () => {
|
||||
expect(viewLngFrame(null, 0)).toBeNull();
|
||||
expect(viewLngFrame(null, 10)).toBeNull();
|
||||
expect(viewLngFrame(null, -90)).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps the frame in use while the view stays near its middle, so a pan redraws nothing', () => {
|
||||
const frame = { seam: 28.4 };
|
||||
expect(viewLngFrame(frame, 208.4)).toBe(frame);
|
||||
expect(viewLngFrame(frame, 130)).toBe(frame);
|
||||
});
|
||||
|
||||
it('centres the frame on a view outside the trip frame, so places found there are drawn there', () => {
|
||||
// A trip from Los Angeles to Auckland, seamed at 28.4, with the user looking at Europe.
|
||||
const frame = viewLngFrame({ seam: 28.4 }, 10);
|
||||
expect(frame).toEqual({ seam: -170 });
|
||||
expect(frameLng(frame, 12)).toBeCloseTo(12, 6);
|
||||
expect(frameLng(frame, 23.7)).toBeCloseTo(23.7, 6);
|
||||
expect(frameLng(frame, -5)).toBeCloseTo(-5, 6);
|
||||
});
|
||||
|
||||
it('centres the frame on a view of a world copy', () => {
|
||||
const frame = viewLngFrame(null, 495);
|
||||
expect(frame).toEqual({ seam: 315 });
|
||||
expect(frameLng(frame, 139.7)).toBeCloseTo(499.7, 6);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,3 +106,19 @@ export function frameLine<T extends readonly [number, number]>(
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* A frame for layers fetched for the visible area rather than drawn with the trip,
|
||||
* such as the POIs the explore pill finds: those come back at their real longitudes
|
||||
* and belong on the copy the user is looking at, even outside the trip's frame.
|
||||
*
|
||||
* The frame in use is kept while the view's centre stays within a quarter world of
|
||||
* its middle, so a pan does not redraw every marker; past that it is centred on the
|
||||
* view. Either way a view up to half a world wide lies inside it. `null` is the
|
||||
* plain world, whose middle is 0, and is kept as null while it fits.
|
||||
*/
|
||||
export function viewLngFrame(current: LngFrame | null, centerLng: number): LngFrame | null {
|
||||
const middle = current ? current.seam + 180 : 0;
|
||||
if (Math.abs(centerLng - middle) <= 90) return current;
|
||||
return { seam: centerLng - 180 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user