Načítavam dáta o destinácii...
'+icon('warn')+'
';
var retry = panel.querySelector('[data-hme-retry]');
if (retry && state.active) {
retry.addEventListener('click', function(){ fetchData(state.active); });
}
}
function showDependencyError() {
panel.innerHTML = 'Dáta sa nepodarilo načítať
'+esc(message || 'Skús vybrať destináciu znova.')+'
'+icon('warn')+'
';
}
function clearClock() {
if (state.clock) {
window.clearInterval(state.clock);
state.clock = null;
}
}
function renderPanel(dest, data) {
var country = data.country_data || {};
var weather = data.weather || {};
var current = weather.current || {};
var forecast = weather.forecast && weather.forecast.forecastday ? weather.forecast.forecastday : [];
var wxLoc = weather.location || {};
var currency = getCurrency(country);
var rate = data.currency && data.currency.rate ? data.currency.rate : null;
var capital = country.capital && country.capital[0] ? country.capital[0] : dest.city;
var cont = country.continents && country.continents[0] ? country.continents[0] : 'Nedostupné';
var tz = country.timezones && country.timezones[0] ? country.timezones[0] : 'UTC';
var side = translateDrivingSide(country.car && country.car.side ? country.car.side : '');
var flag = country.flags && country.flags.svg ? country.flags.svg : '';
var t = calcTime(wxLoc.tz_id);
var lat = country.latlng && country.latlng[0] ? Number(country.latlng[0]) : dest.lat;
var lng = country.latlng && country.latlng[1] ? Number(country.latlng[1]) : dest.lng;
var dist = haversine(48.1486, 17.1077, lat, lng);
var destCode = data.airports && data.airports[0] ? data.airports[0].iata : ((country.cca3 || dest.slug).slice(0, 3).toUpperCase());
var visa = visaText(data.visa || {});
var airports = data.airports || [];
var forecastHtml = forecast.slice(0, 3).map(function(day) {
var date = day.date ? new Date(day.date + 'T12:00:00') : null;
var name = date ? new Intl.DateTimeFormat('sk-SK', { weekday: 'short' }).format(date) : 'Deň';
var max = day.day && typeof day.day.maxtemp_c !== 'undefined' ? Math.round(day.day.maxtemp_c) : (day.day && typeof day.day.avgtemp_c !== 'undefined' ? Math.round(day.day.avgtemp_c) : '--');
var min = day.day && typeof day.day.mintemp_c !== 'undefined' ? Math.round(day.day.mintemp_c) : '';
var txt = day.day && day.day.condition ? day.day.condition.text : 'Nedostupné';
var code = day.day && day.day.condition ? day.day.condition.code : 1000;
var rain = day.day && typeof day.day.daily_chance_of_rain !== 'undefined' ? Number(day.day.daily_chance_of_rain) : 0;
return 'Mapa sa nepodarila načítať
Knižnica Leaflet nie je dostupná. Skontrolujte, či optimalizačný alebo bezpečnostný plugin neblokuje CDN unpkg.com alebo jsdelivr.net.
'+esc(name)+'
'+esc(txt)+'
'+esc(max)+'°C '+(min !== '' ? ''+esc(min)+'°C' : '')+'
'+(rain > 20 ? ''+icon('drop')+esc(rain)+'%
' : '')+''+esc(ap.iata)+'
'+esc(ap.name)+'
'+esc(ap.city || 'Mesto nedostupné')+'
Dáta letísk nie sú dostupné. Nahrajte CSV súbor do uploads.
';
airportsHtml = '' + airportsHtml + '
';
var arcSVG = '';
clearClock();
panel.innerHTML =
'' +
'' +
'
' +
''+(flag ? '
' : '')+'
'+esc(dest.name)+'
'+esc(cont)+'·'+esc(capital)+'·'+esc(tz)+'
Destinácia
' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'
' +
''+icon('pin')+'
'+esc(capital)+'
Hlavné mesto
'+icon('area')+'
'+fmtNum(country.area)+' km²
Rozloha
'+icon('people')+'
'+fmtPop(country.population)+'
Obyvateľov
'+icon('lang')+'
'+esc(getFirstLanguage(country))+'
Jazyk
'+icon('car')+'
'+esc(side)+'
Jazda
'+icon('clock')+'
'+esc(tz)+'
Časové pásmo
' +
'' +
'' +
'' +
'' +
'' +
'
' +
''+icon('wx')+'Aktuálne počasie
' +
'Teplota a stav
'+esc(Math.round(current.temp_c || 0))+'°C
'+esc(current.condition ? current.condition.text : 'Nedostupné')+'
'+esc(wxLoc.name || dest.city)+'
'+icon('wx')+'
Vlhkosť vzduchu
'+esc(current.humidity || '--')+'%
UV '+esc(current.uv || '--')+'
Aktuálne podmienky
'+icon('info')+'
'+icon('clock')+'Miestny čas
'+esc(t.time)+'
'+esc(t.date)+'
Slovensko: '+esc(t.sk)+'
'+icon('money')+'Kurz meny
1 EUR =
'+esc(fmtRate(rate))+' '+esc(currency.code)+'
'+esc(currency.symbol ? currency.symbol + ' ' + currency.name : currency.name)+'
'+esc(current.humidity || '--')+'%
Vlhkosť
'+esc(current.wind_kph || '--')+'
km/h vietor
'+esc(current.vis_km || '--')+'
km viditeľnosť
'+esc(current.uv || '--')+'
UV index
Východ: '+esc(forecast[0] && forecast[0].astro ? forecast[0].astro.sunrise : '--')+'Západ: '+esc(forecast[0] && forecast[0].astro ? forecast[0].astro.sunset : '--')+'
' +
''+icon('wx')+'3-dňová predpoveď
'+forecastHtml+'
'+icon('plane')+'Vzdialenosť zo Slovenska
BTS
Bratislava
'+esc(destCode)+'
'+esc(dest.name)+'
'+fmtNum(dist)+' km
Vzdušná čiara
~'+esc(flightTime(dist))+'
Odhad letu
'+icon('info')+'Vstup pre Slovákov
'+icon('info')+esc(visa.label)+'
'+esc(visa.detail)+'
Vždy overte aktuálny stav na mzv.sk. Zdroj: passportindex.org.
'+icon('plane')+'Letiská
'+airportsHtml+'',
iconSize: [18, 18],
iconAnchor: [9, 9]
})
}).addTo(state.map);
marker.bindTooltip(dest.name, { direction: 'top', offset: [0, -8], opacity: 0.92 });
marker.on('click', function(){ selectCountry(dest.slug, true); });
state.markers[dest.slug] = marker;
bounds.push([dest.lat, dest.lng]);
});
if (bounds.length) {
state.map.fitBounds(bounds, { padding: [22, 22], maxZoom: 3 });
}
window.setTimeout(function(){
if (state.map && state.map.invalidateSize) {
state.map.invalidateSize();
}
}, 120);
window.setTimeout(function(){
mapEl.classList.add('is-ready');
}, 2600);
}
function renderDropdown(items) {
if (!items.length) {
dropdown.innerHTML = '';
} else {
dropdown.innerHTML = items.map(function(dest){
return '';
}).join('');
}
dropdown.classList.add('is-open');
}
function closeDropdown() {
dropdown.classList.remove('is-open');
}
function attachSearch() {
search.addEventListener('input', function(){
var q = normalizeSearch(search.value.trim());
searchWrap.classList.toggle('has-value', q.length > 0);
if (q.length < 3) {
if (state.prefetchTimer) {
window.clearTimeout(state.prefetchTimer);
state.prefetchTimer = null;
}
closeDropdown();
return;
}
var matches = CONFIG.filter(function(dest){
return normalizeSearch(dest.name).indexOf(q) !== -1 ||
normalizeSearch(dest.country).indexOf(q) !== -1 ||
normalizeSearch(dest.city).indexOf(q) !== -1 ||
normalizeSearch(dest.slug).indexOf(q) !== -1;
}).slice(0, 10);
renderDropdown(matches);
if (state.prefetchTimer) {
window.clearTimeout(state.prefetchTimer);
}
state.prefetchTimer = window.setTimeout(function(){
if (matches[0]) {
prefetchData(matches[0].slug);
}
}, 260);
});
clearBtn.addEventListener('click', function(){
search.value = '';
search.focus();
searchWrap.classList.remove('has-value');
closeDropdown();
});
dropdown.addEventListener('click', function(event){
var button = event.target.closest('[data-slug]');
if (!button) { return; }
var slug = button.getAttribute('data-slug');
var dest = CONFIG.find(function(item){ return item.slug === slug; });
if (dest) {
search.value = dest.name;
searchWrap.classList.add('has-value');
}
selectCountry(slug, true);
});
document.addEventListener('click', function(event){
if (!root.contains(event.target)) {
closeDropdown();
}
});
}
function ensureLeaflet(callback) {
if (window.L) {
callback();
return;
}
if (!document.querySelector('link[href*="leaflet.css"]')) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = LEAFLET_CSS;
document.head.appendChild(link);
}
var index = 0;
function loadNext() {
if (window.L) {
callback();
return;
}
if (index >= LEAFLET_JS_URLS.length) {
showDependencyError();
return;
}
var script = document.createElement('script');
script.src = LEAFLET_JS_URLS[index];
script.async = false;
script.dataset.hmeLeaflet = '1';
index += 1;
script.onload = function(){
if (window.L) {
callback();
} else {
loadNext();
}
};
script.onerror = loadNext;
document.head.appendChild(script);
}
loadNext();
}
function bootWidget() {
if (state.booted) {
return;
}
if (!window.L) {
showDependencyError();
return;
}
state.booted = true;
initMap();
attachSearch();
if (DEFAULT_SLUG && CONFIG.some(function(item){ return item.slug === DEFAULT_SLUG; })) {
selectCountry(DEFAULT_SLUG, false);
} else {
showHint();
}
}
function scheduleBoot() {
var started = false;
function start() {
if (started) {
return;
}
started = true;
ensureLeaflet(bootWidget);
}
if ('IntersectionObserver' in window) {
var observer = new IntersectionObserver(function(entries){
entries.forEach(function(entry){
if (entry.isIntersecting) {
observer.disconnect();
start();
}
});
}, { rootMargin: '360px 0px' });
observer.observe(root);
window.setTimeout(start, 3500);
return;
}
if ('requestIdleCallback' in window) {
window.requestIdleCallback(start, { timeout: 1800 });
} else {
window.setTimeout(start, 500);
}
}
scheduleBoot();
})();