Good changes
This commit is contained in:
parent
d39d1b15fd
commit
1f68ca0512
23 changed files with 670 additions and 289 deletions
|
|
@ -17,39 +17,37 @@ export class ScreenshotCache {
|
|||
|
||||
/**
|
||||
* Build a cache key by quantizing view params and hashing.
|
||||
* - lat/lng quantized to 2 decimal places
|
||||
* - lat/lon quantized to 2 decimal places
|
||||
* - zoom quantized to integer
|
||||
* - filters sorted alphabetically
|
||||
* - filters and POI categories sorted alphabetically
|
||||
*/
|
||||
buildKey(params: Record<string, string>): string {
|
||||
buildKey(params: URLSearchParams): string {
|
||||
const normalized: Record<string, string> = {};
|
||||
|
||||
// Parse and quantize the view param (lat,lng,zoom)
|
||||
if (params.v) {
|
||||
const parts = params.v.split(',');
|
||||
if (parts.length === 3) {
|
||||
const lat = parseFloat(parts[0]).toFixed(2);
|
||||
const lng = parseFloat(parts[1]).toFixed(2);
|
||||
const zoom = Math.round(parseFloat(parts[2])).toString();
|
||||
normalized.v = `${lat},${lng},${zoom}`;
|
||||
} else {
|
||||
normalized.v = params.v;
|
||||
}
|
||||
// Quantize lat/lon/zoom
|
||||
const lat = params.get('lat');
|
||||
const lon = params.get('lon');
|
||||
const zoom = params.get('zoom');
|
||||
if (lat && lon && zoom) {
|
||||
normalized.lat = parseFloat(lat).toFixed(2);
|
||||
normalized.lon = parseFloat(lon).toFixed(2);
|
||||
normalized.zoom = Math.round(parseFloat(zoom)).toString();
|
||||
}
|
||||
|
||||
// Sort filters
|
||||
if (params.f) {
|
||||
const segments = params.f.split(',').sort();
|
||||
normalized.f = segments.join(',');
|
||||
const filters = params.getAll('filter').sort();
|
||||
if (filters.length > 0) {
|
||||
normalized.filters = filters.join(',');
|
||||
}
|
||||
|
||||
if (params.poi) {
|
||||
const cats = params.poi.split(',').sort();
|
||||
normalized.poi = cats.join(',');
|
||||
// Sort POI categories
|
||||
const pois = params.getAll('poi').sort();
|
||||
if (pois.length > 0) {
|
||||
normalized.poi = pois.join(',');
|
||||
}
|
||||
|
||||
if (params.tab) {
|
||||
normalized.tab = params.tab;
|
||||
if (params.get('tab')) {
|
||||
normalized.tab = params.get('tab')!;
|
||||
}
|
||||
|
||||
const input = JSON.stringify(normalized);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue