UNPKG

mapwize-ui-react-native

Version:

Fully featured and ready to use UI to add Mapwize Indoor Maps and Navigation in your React Native app.

167 lines (155 loc) 6.26 kB
// @ts-nocheck import { lang_floor, lang_search_no_results } from '../localizor'; export const buildFloorDisplays = (floors, language) => { return floors.map(f => { const translation = translationForLanguage(f.translations, language); return { title: (translation === null || translation === void 0 ? void 0 : translation.shortTitle) || '' + f.number, number: f.number }; }); }; export const buildLanguageDisplays = languages => { return languages.map(l => { return { code: l, value: LANGUAGES[l] }; }); }; export const buildPlaceDetails = (placeDetails, language) => { const translation = translationForLanguage(placeDetails === null || placeDetails === void 0 ? void 0 : placeDetails.translations, language); return { ...placeDetails, objectClass: 'PlaceDetails', titleLabel: translation === null || translation === void 0 ? void 0 : translation.title, subtitleLabel: (translation === null || translation === void 0 ? void 0 : translation.subtitle) !== undefined ? translation === null || translation === void 0 ? void 0 : translation.subtitle : translation === null || translation === void 0 ? void 0 : translation.subTitle, detailsLabel: translation === null || translation === void 0 ? void 0 : translation.details }; }; export const buildPlacelistDetails = (placelist, places, language) => { const translation = translationForLanguage(placelist.translations, language); places = places.map(p => { const t = translationForLanguage(p.translations, language); return { ...p, objectClass: 'Place', titleLabel: t === null || t === void 0 ? void 0 : t.title, subtitleLabel: t === null || t === void 0 ? void 0 : t.subtitle, floorLabel: lang_floor(language, p.floor) }; }); return { ...placelist, titleLabel: translation === null || translation === void 0 ? void 0 : translation.title, subtitleLabel: translation === null || translation === void 0 ? void 0 : translation.subtitle, detailsLabel: translation === null || translation === void 0 ? void 0 : translation.details, places: places }; }; export const buildPlacelist = (placelist, language) => { const translation = translationForLanguage(placelist.translations, language); return { ...placelist, titleLabel: translation === null || translation === void 0 ? void 0 : translation.title, subtitleLabel: translation === null || translation === void 0 ? void 0 : translation.subtitle, detailsLabel: translation === null || translation === void 0 ? void 0 : translation.details }; }; export const buildSearchResult = (searchResult, language) => { const map = searchResult === null || searchResult === void 0 ? void 0 : searchResult.map(s => { if (!s) { return {}; } const translation = translationForLanguage(s.translations, language); let floorLabel; if (s.floor || s.floor === 0) { floorLabel = lang_floor(language || 'en', s.floor); } return { ...s, title: translation === null || translation === void 0 ? void 0 : translation.title, subtitle: translation === null || translation === void 0 ? void 0 : translation.subtitle, floorLabel }; }); // Fixing missing title for translation return map.filter(s => s.title); }; export const titleForLanguage = (object, language) => { var _translationForLangua; return (_translationForLangua = translationForLanguage(object.translations, language)) === null || _translationForLangua === void 0 ? void 0 : _translationForLangua.title; }; export const subtitleForLanguage = (object, language) => { var _translationForLangua2; return (_translationForLangua2 = translationForLanguage(object.translations, language)) === null || _translationForLangua2 === void 0 ? void 0 : _translationForLangua2.subtitle; }; export const buildLanguageDisplay = language => { return LANGUAGES[language]; }; export const buildDirectionInfo = (direction, unit) => { const timeInMinuts = Math.floor(direction.traveltime / 60); let distanceLabel; if (unit === 'm') { distanceLabel = Math.floor(direction.distance) + ' m'; } else { distanceLabel = Math.floor(direction.distance * 3.28084) + ' ft'; } return { durationLabel: timeInMinuts < 1 ? '< 1 min' : timeInMinuts + ' min', distanceLabel: distanceLabel }; }; export const buildNavigationInfo = (navigationInfo, unit) => { const timeInMinuts = Math.floor(navigationInfo.duration / 60); let distanceLabel; if (unit === 'm') { distanceLabel = Math.floor(navigationInfo.distance) + ' m'; } else { distanceLabel = Math.floor(navigationInfo.distance * 3.28084) + ' ft'; } return { durationLabel: timeInMinuts < 1 ? '< 1 min' : timeInMinuts + ' min', distanceLabel: distanceLabel }; }; export const buildDirectionError = language => { return { durationLabel: '', distanceLabel: '', errorLabel: lang_search_no_results(language) }; }; export const translationForLanguage = (translations, language) => { //TODO check why translations is undefined const filterTranslation = translations === null || translations === void 0 ? void 0 : translations.filter(t => t.language === language); if ((filterTranslation === null || filterTranslation === void 0 ? void 0 : filterTranslation.length) === 0) { return translations === null || translations === void 0 ? void 0 : translations[0]; } else { return filterTranslation === null || filterTranslation === void 0 ? void 0 : filterTranslation[0]; } }; const LANGUAGES = { da: 'Dansk', de: 'Deutsch', nl: 'Nederlands', hu: 'Magyar', es: 'Español', fr: 'Français', en: 'English', fi: 'Suomi', ru: 'Pусский язык', zh: '中文', pt: 'Português', it: 'Italiano', no: 'Norsk', ja: '日本語', ar: 'العربية', sv: 'Svenska', tr: 'Türkçe', ko: '한국어', ca: 'català', et: 'Eesti', zf: '正體字' }; export const replaceColorInBase64svg = (svg, toColor) => { const encoded = svg.replace('data:image/svg+xml;base64,', ''); let decoded = atob(encoded); decoded = decoded.replace(/#000000/g, toColor); // @ts-ignore return 'data:image/svg+xml;base64,' + btoa(decoded); }; //# sourceMappingURL=index.js.map