import { notFound } from "next/navigation"; import { deleteMap, renameMap } from "@/actions/maps"; import { ConfirmSubmit } from "@/components/confirm-submit"; import { MapLoader } from "@/components/map-loader"; import { PageBody, PageHeader } from "@/components/page"; import { getT } from "@/i18n/server"; import { prisma } from "@/lib/db"; import { fileUrl } from "@/lib/files"; import { hasRole } from "@/lib/access"; import { versionOf } from "@/lib/conflict"; import { requireBook } from "@/lib/session"; // Standard är OpenStreetMaps publika tjänster. Byt via miljövariabler vid tyngre användning. const TILE_URL = process.env.MAP_TILE_URL || "https://tile.openstreetmap.org/{z}/{x}/{y}.png"; const TILE_ATTRIBUTION = process.env.MAP_TILE_ATTRIBUTION || "© OpenStreetMap-bidragsgivare"; const GEOCODER_URL = process.env.MAP_GEOCODER_URL || "https://nominatim.openstreetmap.org/search"; export default async function MapPage({ params, searchParams, }: { params: Promise<{ bookId: string; mapId: string }>; searchParams: Promise<{ place?: string; marker?: string }>; }) { const { bookId, mapId } = await params; const { place, marker } = await searchParams; const canEdit = hasRole((await requireBook(bookId)).role, "EDITOR"); const { t } = await getT(); const [map, entities] = await Promise.all([ prisma.bookMap.findFirst({ where: { id: mapId, bookId }, include: { markers: { orderBy: { createdAt: "asc" } } } }), prisma.entity.findMany({ where: { bookId }, select: { id: true, name: true, kind: true }, orderBy: { name: "asc" } }), ]); if (!map) notFound(); const center: [number, number] | null = map.centerLat !== null && map.centerLng !== null ? [map.centerLat, map.centerLng] : null; return ( <> {t("map.title")} {map.code ? {map.code} : null} } /> ({ id: m.id, code: m.code, label: m.label, note: m.note, color: m.color, lat: m.lat, lng: m.lng, entityId: m.entityId, version: versionOf(m.updatedAt), }))} entities={entities} tileUrl={TILE_URL} tileAttribution={TILE_ATTRIBUTION} geocoderUrl={GEOCODER_URL} preselectEntityId={entities.some((e) => e.id === place) ? (place ?? null) : null} initialMarkerId={marker ?? null} /> ); }