mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Fix Data Library share restore, dense tile layers and EPC partition reads
- Share links: the compact /share/<code> format carries the switched-on library entries (field 29), so Copy Link keeps them; a share opened in the same tab restores them; any share decides what is on, so one with every library entry off no longer switches on the recipient's stored entries. - A tile entry too dense at its minimum zoom (Norway cadastre z14, depth z11) is hidden below that scale via minimumTerrainLevel instead of allocating millions of tiles when zoomed out. - EPC partitions keep the full extent for exclusion and the 98 % extent for ranking only; the old trimmed-only extents are retired. - Partition index footers that fail transiently are retried; an incomplete index is never cached as complete, a complete prior index is kept, and it is rebuilt after five minutes. - Views that leave touching partitions unread are partial; listing and footer bodies are capped and ranges validated. - The Browse dialog relabels after a language switch.
This commit is contained in:
1 parent
871b7f0fcc
commit
24ccdd4dc3
20 files changed
+1220
-162
No files matched your search
@@ -48,6 +48,7 @@ export const LEGACY_SHARE_STATE_KEYS = Object.freeze([
|
||||
'layerState',
|
||||
'layerStateInvalid',
|
||||
'panelState',
|
||||
'library',
|
||||
'sharedAtMs',
|
||||
]);
|
||||
|
||||
|
||||
@@ -390,6 +390,9 @@ export const SHARE_VIEW_FIELDS = freezeAll([
|
||||
{ number: 26, key: 'scopeTerminusPct', type: 'uint', default: null },
|
||||
{ number: 27, key: 'styleParams', type: 'bytes', default: BY_STYLE },
|
||||
{ number: 28, key: 'worldTime', type: 'epoch', default: null },
|
||||
// Data Library entries switched on, as their two-character ledger tokens
|
||||
// concatenated (src/library/ledger.json). Absent means none.
|
||||
{ number: 29, key: 'library', type: 'bytes', default: null },
|
||||
]);
|
||||
const FIELD_BY_KEY = new Map(SHARE_VIEW_FIELDS.map((f) => [f.key, f]));
|
||||
const fieldNumber = (key) => FIELD_BY_KEY.get(key).number;
|
||||
@@ -450,6 +453,33 @@ export function createDefaultShareViewState(requested = 'normal') {
|
||||
/* Normalization: the one canonical state both directions agree on. */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/** The most Data Library tokens a share carries (the library's own cap). */
|
||||
export const SHARE_LIBRARY_MAX_TOKENS = 64;
|
||||
const LIBRARY_TOKEN = /^[0-9a-z]{2}$/;
|
||||
|
||||
/**
|
||||
* Data Library share tokens from a `lib=` value (`ab.cd`) or a token list:
|
||||
* unique, two base-36 characters each, at most SHARE_LIBRARY_MAX_TOKENS.
|
||||
* Malformed tokens are skipped. Null or undefined stays null (no field).
|
||||
* @param {string|string[]|null|undefined} value
|
||||
* @returns {string[]|null}
|
||||
*/
|
||||
export function normalizeLibraryTokens(value) {
|
||||
if (value === null || value === undefined) return null;
|
||||
const list = Array.isArray(value)
|
||||
? value
|
||||
: typeof value === 'string' && value.length <= 3 * SHARE_LIBRARY_MAX_TOKENS
|
||||
? value.split('.')
|
||||
: [];
|
||||
const tokens = [];
|
||||
for (const token of list) {
|
||||
if (typeof token !== 'string' || !LIBRARY_TOKEN.test(token)) continue;
|
||||
if (!tokens.includes(token)) tokens.push(token);
|
||||
if (tokens.length === SHARE_LIBRARY_MAX_TOKENS) break;
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
const finite = (value) =>
|
||||
typeof value === 'number'
|
||||
? Number.isFinite(value)
|
||||
@@ -761,6 +791,7 @@ export function normalizeShareViewState(input = {}) {
|
||||
? normalizeLayerState(source.layerState)
|
||||
: null;
|
||||
state.panelState = normalizePanelState(source.panelState);
|
||||
state.library = normalizeLibraryTokens(source.library);
|
||||
state.sharedAtMs = epochMsOr(source.sharedAtMs);
|
||||
state.worldTime = isWorldTime(source.worldTime)
|
||||
? Math.floor(source.worldTime / 1000) * 1000
|
||||
@@ -1030,6 +1061,10 @@ export function encodeShareView(input) {
|
||||
case 'panelState':
|
||||
if (state.panelState) encodePanels(writer, state.panelState);
|
||||
break;
|
||||
case 'library':
|
||||
if (state.library?.length)
|
||||
writer.textField(field.number, state.library.join(''));
|
||||
break;
|
||||
case 'thing':
|
||||
if (thing) encodeThing(writer, thing, state);
|
||||
break;
|
||||
@@ -1438,6 +1473,13 @@ export function decodeShareView(code, { nowMs = Date.now() } = {}) {
|
||||
unknown.code('layer-option', 'without-layers');
|
||||
if (get('panelState'))
|
||||
raw.panelState = decodePanels(get('panelState').len, unknown);
|
||||
if (get('library')) {
|
||||
const text = asciiText(get('library').len.rest());
|
||||
const tokens = text.match(/.{1,2}/g) || [];
|
||||
for (const token of tokens)
|
||||
if (!LIBRARY_TOKEN.test(token)) unknown.code('library', token);
|
||||
raw.library = normalizeLibraryTokens(tokens);
|
||||
}
|
||||
if (get('styleParams') && !retiredStyle)
|
||||
raw.styleParams = decodeStyleParams(
|
||||
get('styleParams').len,
|
||||
|
||||
@@ -58,6 +58,7 @@ import {
|
||||
followOffsetToEnu,
|
||||
layerTokenFromNumber,
|
||||
layerTokenNumber,
|
||||
normalizeLibraryTokens,
|
||||
normalizeShareViewState,
|
||||
} from './viewCodec.js';
|
||||
|
||||
@@ -507,6 +508,7 @@ test('the field registry is well formed and permanent', () => {
|
||||
[26, 'scopeTerminusPct', null],
|
||||
[27, 'styleParams', BY_STYLE],
|
||||
[28, 'worldTime', null],
|
||||
[29, 'library', null],
|
||||
],
|
||||
);
|
||||
assert.deepEqual(
|
||||
@@ -1571,3 +1573,16 @@ test('the follow offset for a camera is the inverse of followCameraFor', () => {
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
test('Data Library tokens round-trip and malformed ones are skipped', () => {
|
||||
const state = { lat: 1, lon: 2, library: ['00', '1z', '0a'] };
|
||||
const decoded = decodeShareView(encodeShareView(state));
|
||||
assert.equal(decoded.ok, true);
|
||||
assert.deepEqual(decoded.state.library, ['00', '1z', '0a']);
|
||||
// None on: no field, and the decoder reads no tokens.
|
||||
const none = decodeShareView(encodeShareView({ lat: 1, lon: 2 }));
|
||||
assert.equal(none.state.library, null);
|
||||
assert.deepEqual(normalizeLibraryTokens('01.!!.01.zz'), ['01', 'zz']);
|
||||
assert.equal(normalizeLibraryTokens(null), null);
|
||||
assert.deepEqual(normalizeLibraryTokens('x'.repeat(500)), []);
|
||||
});
|
||||
Reference in new issue
Block a user