/** * How much an OpenStreetMap place says about itself (scripts/build-backpacker-places.mjs). * * The map is for places worth going to. OpenStreetMap holds every bench with * a tap, so a place earns its pin by being described: a name, a web page, a * phone number, opening hours, an entry in Wikipedia or Wikidata, an operator. * Kept free of app imports so the build script and the node test runner load it. */ type Tags = Readonly>; export function osmScore(tags: Tags): number { let score = 0; if (tags.wikidata || tags.wikipedia) score += 3; if (tags.website || tags['contact:website']) score += 2; if (tags.phone || tags['contact:phone']) score += 1; if (tags.opening_hours) score += 1; if (tags.operator || tags.brand || tags.network) score += 1; if (tags.stars || tags.bottle === 'yes' || tags['internet_access:fee'] === 'no') score += 1; if (tags['name:en'] || tags.name) score += 1; return score; } /** Whether another place of the same kind is already kept within about 350 m. */ export function nearKept(kept: ReadonlySet, latitude: number, longitude: number): boolean { const cell = (value: number) => Math.round(value / 0.0035); const y = cell(latitude); const x = cell(longitude); for (let dy = -1; dy <= 1; dy += 1) { for (let dx = -1; dx <= 1; dx += 1) { if (kept.has(`${y + dy}:${x + dx}`)) return true; } } return false; } export function keepCell(kept: Set, latitude: number, longitude: number): void { const cell = (value: number) => Math.round(value / 0.0035); kept.add(`${cell(latitude)}:${cell(longitude)}`); }