Drawer headers: a shared DrawerHeader component renders the desktop nav-bar layout (back + centered title + close) and a mobile variant (left title, no back button, a single X that dismisses the top sheet — back when there is a parent, otherwise close). Place details uses the place name as its title with a compact, borderless header, and on mobile moves the photos below the place type. The X and back buttons now have aria-labels. Sheet scrolling: the content only scrolls while the sheet is at its largest detent; below that, dragging anywhere on the sheet (including list rows and links, not just the header) resizes it. At the largest detent, pulling down on the content while it is scrolled to the top shrinks the sheet (overscroll to shrink). Place details opens at the medium detent again. The mobile photo carousel no longer bleeds to the sheet edges, gets a wider gap and the same corner radius as the action buttons.
88 lines
1.8 KiB
JavaScript
88 lines
1.8 KiB
JavaScript
import { humanizeOsmTag } from './format-text';
|
|
|
|
export function getLocalizedName(tags, defaultName = 'Untitled Place') {
|
|
if (!tags) return defaultName;
|
|
|
|
// 1. Get user's preferred languages
|
|
const languages = navigator.languages || [navigator.language || 'en'];
|
|
|
|
// 2. Try to find a match for each preferred language
|
|
for (const lang of languages) {
|
|
if (!lang) continue;
|
|
|
|
// Handle "en-US", "de-DE", etc. -> look for "name:en", "name:de"
|
|
const shortLang = lang.split('-')[0];
|
|
const tagKey = `name:${shortLang}`;
|
|
|
|
if (tags[tagKey]) {
|
|
return tags[tagKey];
|
|
}
|
|
}
|
|
|
|
// 3. Fallback to standard "name"
|
|
if (tags.name) {
|
|
return tags.name;
|
|
}
|
|
|
|
// 4. Fallback to "name:en" (common in international places without local name)
|
|
if (tags['name:en']) {
|
|
return tags['name:en'];
|
|
}
|
|
|
|
// 5. Final fallback
|
|
return defaultName;
|
|
}
|
|
|
|
// The display name for a place: an explicit title (saved places) wins, then the
|
|
// localized OSM name. Shared by the place details body and the drawer header so
|
|
// both agree on the title.
|
|
export function getPlaceName(place) {
|
|
if (!place) return 'Untitled Place';
|
|
return place.title || getLocalizedName(place.osmTags);
|
|
}
|
|
|
|
const PLACE_TYPE_KEYS = [
|
|
'craft',
|
|
'amenity',
|
|
'shop',
|
|
'tourism',
|
|
'historic',
|
|
'leisure',
|
|
'office',
|
|
'aeroway',
|
|
'building',
|
|
'landuse',
|
|
'public_transport',
|
|
'highway',
|
|
'waterway',
|
|
'natural',
|
|
'place',
|
|
'border_type',
|
|
'admin_title',
|
|
];
|
|
|
|
export function getPlaceType(tags) {
|
|
if (!tags) return null;
|
|
|
|
let fallbackKey = null;
|
|
|
|
for (const key of PLACE_TYPE_KEYS) {
|
|
const value = tags[key];
|
|
if (value) {
|
|
if (value === 'yes') {
|
|
if (!fallbackKey) {
|
|
fallbackKey = key;
|
|
}
|
|
continue;
|
|
}
|
|
return humanizeOsmTag(value);
|
|
}
|
|
}
|
|
|
|
if (fallbackKey) {
|
|
return humanizeOsmTag(fallbackKey);
|
|
}
|
|
|
|
return null;
|
|
}
|