UNPKG

@allmaps/annotation

Version:

Functions for generating and parsing IIIF georeference annotations

36 lines (35 loc) 1.1 kB
import { parseAnnotation } from './parser.js'; import { generateAnnotation } from './generator.js'; import { isAnnotation1, isGeoreferencedMap2 } from './guards.js'; export function toAnnotation1(annotation) { if (isAnnotation1(annotation)) { return annotation; } else { const convertedAnnotation = generateAnnotation(parseAnnotation(annotation)); if ('items' in convertedAnnotation) { return convertedAnnotation.items[0]; } else { return convertedAnnotation; } } } export function toAnnotationPage1(annotationPage) { return { ...annotationPage, items: annotationPage.items.map(toAnnotation1) }; } export function toGeoreferencedMap2(georeferencedMap) { if (isGeoreferencedMap2(georeferencedMap)) { return georeferencedMap; } else { const convertedMap = parseAnnotation(generateAnnotation(georeferencedMap)); return convertedMap[0]; } } export function toGeoreferencedMaps2(georeferencedMap) { return georeferencedMap.map(toGeoreferencedMap2); }