var HOST_CORE = "http://core.pogoda360.ru" var STATIC_HOST_MAPIMAGES = "http://map-icons.pogoda360.ru"; try { document.domain = 'pogoda360.ru'; } catch (e){} var bPop = {opacity: 0.6, speed: 10, zIndex: 100}; if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str){ return this.indexOf(str) == 0; }; }; var bPop = {opacity: 0.6, speed: 20, zIndex: 100}; pageInit = function() {}; var ajx = { request: function(params) { jQuery.ajax({ data: params.data, error: function(data, status, request) { if (params.error!=undefined) { params.error(data, status, request); } else { ajx.defaultError(data, status, request); } }, success: function(data, status, request) { if (data.length>=4 && data.substring(0,4)=='err:') { ajx.displayErrorMessage(data.substring(4)); } else { params.success(data, status, request); } }, type: 'POST', url: params.url }); }, defaultError: function(data, status, request) { }, displayErrorMessage: function(msg) { } }; var divClick = function(e) { var a = $(this).find('a'); if (e.ctrlKey) { window.open(a.attr('href'), a.attr('href')+Math.random()); } else { if (a.attr('target')!=undefined) { window.open(a.attr('href'), a.attr('href')+Math.random()); } else { window.location=a.attr('href'); } } e.preventDefault(); }; var divClickOut = function(e) { var href = $(this).find('a').attr('href'); if (!href.startsWith('javascript')) { window.open(href, href); e.preventDefault(); } }; function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); } $(document).ready(function() { $('.button').hover( function () { $(this).addClass('button-over'); }, function () { $(this).removeClass('button-over'); } ).click(divClick); if ($('#searchCity').length) { var cities = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: '/ajax/cities/%QUERY/', limit: 20 }); cities.initialize(); $('#searchCity').typeahead({ minLength: 2, highlight: true },{ name: 'cities', displayKey: 'v', source: cities.ttAdapter() }).on('typeahead:selected', function() { $('#searchForm').submit(); }); $('#searchCity').width($('#searchMain').width()-70); $('#searchCity').keypress(function(e) { if(e.which == 10 || e.which == 13) { $('#searchForm').submit(); } }); } $('.multiple').click(function() { $('#searchCity').val($('.multiple').attr('name')); $('#searchForm').submit(); }); $('.tabs .tab').click(tabs.setTab); $('.subTabs .subTab').click(tabs.setSubTab); preload([HOST_CORE+'/i/buttons-over.png']); $('.button').click(divClick); $('#map-banner').click(divClick); $('#current').click(divClick); pageInit(); map.initializeStaticMap(); }); var map = { type: 'weather', subtype: '', resortId: 0, markers: [], map: {}, initializeStaticMap: function() { if (map.initialized) return; map.initialized = true; if ($('#staticMap').length) { var staticMap = $('#staticMap'); var x = staticMap.attr('x'); var y = staticMap.attr('y'); var z = staticMap.attr('z'); map.cityId = staticMap.attr('cityId'); map.init('staticMap', { dragging: false, zoomControl: false}); map.map.on('click', function() {window.location=$('#staticMap').attr('url');}); map.map.setView([y, x], z); } }, init: function(divElName, extraSettings) { var settings = {scrollWheelZoom: false}; if (extraSettings!=undefined) jQuery.extend(settings, extraSettings); map.map = L.map(divElName==undefined?'weatherMapCanvas':divElName, settings); L.tileLayer('https://tiles.turtella.ru/v1/{z}/{y}/{x}', { attribution: 'Tiles © Esri — Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri', minZoom: 2, maxZoom: 10 }).addTo(map.map); map.map.on('moveend', map.drawIcons); }, drawIcons: function() { var markers = []; var bounds = map.map.getBounds(); jQuery.ajax({ data: {x1: bounds.getWest(), x2: bounds.getEast(), y1: bounds.getSouth(), y2: bounds.getNorth(), width: map.map.getSize().x, height: map.map.getSize().y, cityId: map.cityId}, success: function(data, status, request) { var json = jQuery.parseJSON(data); var newMarkers = []; $.each(map.markers, function(index, m) { m.remove(); }); $.each(json, function(index, resort) { map.markers.push(L.marker([ resort.y, resort.x], {icon: L.icon({iconUrl: map.getIconUrl(resort), iconAnchor: [30, 15]}), data: ''}).addTo(map.map)); }); }, type: 'POST', url: 'http://pogoda360.ru/ajax/getBoundsResorts/' }); if (map.postProcessor!=undefined) map.postProcessor(); }, getIconUrl: function(r) { if (map.type=='weather') { return STATIC_HOST_MAPIMAGES+'/w/'+encodeURIComponent(r.name)+'/'+r.temp+'/'+r.code+'/'; } else if (map.type=='avg') { return STATIC_HOST_MAPIMAGES+'/a/'+encodeURIComponent(r.name)+'/'+eval('r.avg.'+map.subtype)+'/'; } else { if (!r.isMarine) return CORE_HOST+'/img/s.gif'; if (map.subtype=='') { return STATIC_HOST_MAPIMAGES+'/s/'+encodeURIComponent(r.name)+'/'+r.seaTemp+'/'; } else { return STATIC_HOST_MAPIMAGES+'/s/'+encodeURIComponent(r.name)+'/'+eval('r.msst.'+map.subtype)+'/'; } } } }; var chart = new Object(); chart.months = ['january','february','march','april','may','june','july','august','september','october','november','december']; chart.monthsChego = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']; chart.mTicks = ['янв','фев','мар','апр','май','июн','июл','авг','сен','окт','ноя','дек']; chart.monthTicks = ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь']; chart.seasonTicks = ['','Январь','','','Февраль','','','Март','','','Апрель','','','Май','','','Июнь','','','Июль','','','Август','','','Сентябрь','','','Октябрь','','','Ноябрь','','','Декабрь','']; chart.drawTemp = function(elementId, monthTitle, dayTemp, nightTemp, ticks) { if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.jqplot(elementId, [dayTemp, nightTemp], { axes:{ xaxis:{ ticks: [[0,''],[1,'1'],[3,'3'],[5,'5'],[7,'7'],[9,'9'],[11,'11'],[13,'13'],[15,'15'],[17,'17'],[19,'19'],[21,'21'],[23,'23'],[25,'25'],[27,'27'],[29,'29'],[31,'31'],[32,'']], tickOptions: { formatString: monthTitle+' %d' } }, yaxis:{ ticks: ticks, tickOptions: { formatString: '%s°C' } } }, highlighter: { show: true, sizeAdjust: 5, useAxesFormatters: true, tooltipLocation: 'ne' }, cursor: { show: false }, legend: { renderer: $.jqplot.EnhancedLegendRenderer, show:true, rendererOptions: { numberRows: 1 }, location: 's', placement: 'outsideGrid' }, series:[ {label:'Температура днем   ', color: '#fed065'}, {label:'Температура ночью', color: '#449bb5'}, {markerOptions: { size: 10 }, showLine:false } ] }); }; chart.drawSeaTemp = function(elementId, monthTitle, seaTemp, ticks) { if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.jqplot(elementId, [seaTemp], { axes:{ xaxis:{ ticks: [[0,''],[1,'1'],[3,'3'],[5,'5'],[7,'7'],[9,'9'],[11,'11'],[13,'13'],[15,'15'],[17,'17'],[19,'19'],[21,'21'],[23,'23'],[25,'25'],[27,'27'],[29,'29'],[31,'31'],[32,'']], tickOptions: { formatString: monthTitle+' %d' } }, yaxis:{ ticks: ticks, tickOptions: { formatString: '%s°C' } } }, highlighter: { show: true, sizeAdjust: 5, useAxesFormatters: true, tooltipLocation: 'ne' }, cursor: { show: false } }); }; chart.drawMBars = function(elementId, lnk, values, yTicks, color1, color2) { if (('#'+elementId).length == 0) return; $.jqplot(elementId, values, { stackSeries: true, captureRightClick: true, seriesDefaults:{ renderer:$.jqplot.BarRenderer, rendererOptions: { barMargin: 10 }, pointLabels: {show: false, hideZeros: true, stackedValue: true} }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: chart.mTicks }, yaxis: { ticks: yTicks, padMin: 0 } }, series:[ {color: color1===undefined?'#4bb2c5':color1}, {color: color2===undefined?'#fed065':color2} ] }); if (lnk!='-') { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { window.location=lnk+chart.months[pointIndex]+'/'; }); }; }; chart.drawYBars = function(elementId, values, yTicks, lnk, color, hash) { if (('#'+elementId).length == 0) return; $.jqplot(elementId, values, { captureRightClick: true, seriesDefaults:{ renderer:$.jqplot.BarRenderer, rendererOptions: { barMargin: 5 }, pointLabels: {show: true, ypadding: 2, formatString: function(){return '%s';}()} }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: chart.mTicks }, yaxis: { ticks: yTicks, padMin: 0 } }, series:[{color: color===undefined?'#4bb2c5':color}] }); if (lnk=='sst') { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { chart.popup($('#mainPage').attr('publicId'), pointIndex+1, 'sst'); }); } else if (lnk=='-'){ // do nothing } else { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { window.location=lnk+chart.months[pointIndex]+'/'+(hash==undefined?'':hash); }); }; }; chart.drawYTempBars = function(elementId, values, yTicks, lnk) { if (('#'+elementId).length == 0) return; $.jqplot(elementId, values, { captureRightClick: true, seriesDefaults:{ renderer:$.jqplot.BarRenderer, rendererOptions: { barMargin: 4, barPadding: 0, shadowDepth: 0 }, pointLabels: {show: true, ypadding: 2} }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: chart.mTicks }, yaxis: { ticks: yTicks, padMin: 0 } }, legend: { renderer: $.jqplot.EnhancedLegendRenderer, show:true, rendererOptions: { numberRows: 1 }, location: 's', placement: 'outsideGrid' }, series:[ {label:'Температура днем   ', color: '#fed065'}, {label:'Температура ночью', color: '#449bb5'}, {markerOptions: { size: 10 }, showLine:false } ] }); if (lnk=='-') { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { chart.popup($('#mainPage').attr('publicId'), pointIndex+1, 'temp'); }); } else { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { window.location=lnk+chart.months[pointIndex]+'/'; }); }; }; chart.drawYCloudsBars = function(elementId, values, lnk) { if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.jqplot(elementId, values, { captureRightClick: true, stackSeries: true, seriesDefaults:{ renderer:$.jqplot.BarRenderer, rendererOptions: { barMargin: 10 }, pointLabels: {show: true, ypadding: 2, formatString: function(){return '%s';}()} }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: chart.mTicks }, yaxis: { ticks: [[0,'0'],[5,'5'],[10,'10'],[15,'15'],[20,'20'],[25,'25'],[30,'30'],[35,'35']], padMin: 0 } }, legend: { renderer: $.jqplot.EnhancedLegendRenderer, show:true, rendererOptions: { numberRows: 1 }, location: 's', placement: 'outsideGrid' }, series:[ {label:'Пасмурные дни   ', color: '#7f9498'}, {label:'Облачные дни   ', color: '#73b5c1'}, {label:'Солнечные дни', color: '#3fd5f1'}, {markerOptions: { size: 10 }, showLine:false } ] }); if (lnk!='-') { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { window.location=lnk+chart.months[pointIndex]+'/'; }); } }; chart.drawPies = function(elementId, values) { if (('#'+elementId).length == 0) return; $.jqplot(elementId, [values], { seriesDefaults: { renderer: jQuery.jqplot.PieRenderer, rendererOptions: { showDataLabels: true, sliceMargin: 8, lineWidth: 5 } }, legend: { show:true, location: 'ne', placement: 'inside' }, seriesColors: [ "#3fd5f1", "#73b5c1", "#7f9498" ] }); }; chart.drawRCompareBars = function(elementId, values, yTicks, label1, label2, lnk1, lnk2, color1, color2) { if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.jqplot(elementId, values, { captureRightClick: true, seriesDefaults:{ renderer:$.jqplot.BarRenderer, rendererOptions: { barMargin: 3, barPadding: 6, shadowDepth: 0 } }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: chart.mTicks }, yaxis: { ticks: yTicks, padMin: 0 } }, legend: { renderer: $.jqplot.EnhancedLegendRenderer, show:true, rendererOptions: { numberRows: 1 }, location: 's', placement: 'outsideGrid' }, series:[ {label: label1+'    ', color: color1===undefined?'#eaa228':color1, pointLabels: {show: true, ypadding: 2, location: 'n', xpadding: 5}}, {label: label2, color: color2===undefined?'#4bb2c5':color2, pointLabels: {show: true, ypadding: 2, location: 'n'}}, {markerOptions: { size: 10 }, showLine:false } ] }); if (lnk!='-') { $('#'+elementId).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { if (seriesIndex==0) { window.location=lnk1+chart.months[pointIndex]+'/'; } else { window.location=lnk2+chart.months[pointIndex]+'/'; } }); }; }; chart.decade2Str = function(decade) { var monthId = Math.ceil(decade/3); var monthStr = chart.monthsChego[monthId-1]; var decadeId = decade%3; if (decadeId==0) decadeId=3; var dateStr = ''; if (decadeId==1) { dateStr = '1-10'; } else if (decadeId==2) { dateStr = '11-20'; } else { if (monthId==1 || monthId==3 || monthId==5 || monthId==7 || monthId==8 || monthId==10 || monthId==12) { dateStr = '21-31'; } else if (monthId==2) { dateStr = '21-28'; } else { dateStr = '21-30'; } } return dateStr+' '+monthStr; }; chart.drawChart = function(chartObject) { eval('chart.'+chartObject.fnName+'(\''+chartObject.elName+'\',chartObject);'); }; chart.popup = function(publicId, month, type) { $('#chartPop').bPopup({ content:'iframe', contentContainer:'.chartContainer', loadUrl:'/chart/'+publicId+'/'+month+'/'+type+'/' }); }; var years = new Object(); years.click = function(el) { $(el).closest('div').find('a').removeClass('sel'); $(el).addClass('sel'); }; var tabs = new Object(); tabs.tab = 'weather'; tabs.subTab = ''; tabs.setTab = function(el) { tabs.tab = $(this).attr('val'); var subType = ''; if (tabs.tab=='avg' || tabs.tab=='sstavg') { subType = 'm1'; } tabs.switchMapType(tabs.tab,subType); }; tabs.setSubTab = function(el) { tabs.switchMapType(tabs.tab, $(this).attr('val')); }; tabs.switchMapType = function(type, subtype) { // redraw tabs $('.tabs .tab').removeClass('tab-sel'); $('.tabs .tab[val="'+type+'"]').addClass('tab-sel'); if (subtype=='') { $('.subTabs').hide(); } else { $('.subTabs').show(); $('.subTabs .subTab').removeClass('subTab-sel'); $('.subTabs .subTab[val="'+subtype+'"]').addClass('subTab-sel'); } if (type=='sstavg') type='sst'; document.getElementById('weatherMapPanel').contentWindow.map.switchMapType(type, subtype); };