var HOST_CORE = 'http://cc.worldseatemp.com'; var STATIC_HOST_MAPIMAGES = "http://map-icons.worldseatemp.com"; 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) { if (e.ctrlKey) { window.open($(this).find('a').attr('href'), $(this).find('a').attr('href')+Math.random()); e.preventDefault(); } else { window.location=$(this).find('a').attr('href'); e.preventDefault(); } }; var divClickOut = function(e) { window.open($(this).find('a').attr('href'), $(this).find('a').attr('href')); e.preventDefault(); }; var lngChange = function(url) { window.location=url; }; function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); } $(document).ready(function() { $('.typeahead').typeahead({ name: 'countries', local: RESORTS, limit: 10 }); $('#lngOuter').hover( function() {$('#lngSelect').show();}, function() {$('#lngSelect').hide();} ); $('.lngSelectRow').hover( function () {$(this).addClass('selected');}, function () {$(this).removeClass('selected');} ); $('#cFormat').click(function() { $('#format').val('c'); $('#chFormat').submit(); }); $('#fFormat').click(function() { $('#format').val('f'); $('#chFormat').submit(); }); var height = $('#current .resortName').height(); if (height>30) { $('#current .details tr').addClass('narrow'); $('#current .resortName').addClass('narrowResortName'); } $('#mapMenu div').click(tabs.click); $('#slider .months td').click(function () { var index = $('#slider .months td').index(this); slider.click(index); }); $('#slider .selector td').click(function () { var index = $('#slider .selector td').index(this); slider.click(index); }); pageInit(); preload([HOST_CORE+'/img/slider-bck.png',HOST_CORE+'/img/slider-point.png',HOST_CORE+'/img/slider-point-sel.png']); map.initializeStaticMap(); }); var map = { type: '', subtype: '', resortId: 0, markers: [], map: {}, initializeCountryMap: function(x1, y1, x2, y2, type, subtype) { if (type!=undefined) map.type=type; if (subtype!=undefined) map.subtype=subtype; var dx = (x2-x1)/30; var dy = (y2-y1)/30; map.init(); map.map.fitBounds(L.latLngBounds(L.latLng(y2+dy, x1-dx), L.latLng(y1-dy, x2+dx))); }, initializeMapByBounds: function(x1, y1, x2, y2, noExtend) { // try to initialize by hash first var x = 0; var y = 0; var hash = window.location.hash; if (hash.length>0) { hash = hash.substring(1); var pos = hash.indexOf(','); if (pos>0) { x = hash.substring(0,pos); y = hash.substring(pos+1); }; } if (x!=0 && y!=0) { map.init(); map.map.setView([y, x], 10); } else { var dx = 0; var dy = 0; if (noExtend==undefined) { dx = (x2-x1)/30; dy = (y2-y1)/30; }; map.init(); map.map.fitBounds(L.latLngBounds(L.latLng(y2+dy, x1-dx), L.latLng(y1-dy, x2+dx))); } }, 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: divElName=='staticMap'?'':'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}, 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: resort.lnk}).addTo(map.map).on('click', map.markerClick)); }); }, type: 'POST', url: PATH_PREFIX + '/ajax/getBoundsResorts/' }); if (map.postProcessor!=undefined) map.postProcessor(); }, markerClick: function(evt) { window.location = evt.target.options.data; }, getIconUrl: function(r) { if (map.type=='') { return STATIC_HOST_MAPIMAGES+"/"+encodeURIComponent(r.name)+'/'+r.current+'/'; } else { return STATIC_HOST_MAPIMAGES+"/"+encodeURIComponent(r.name)+'/'+eval('r.sst.'+map.type)+'/'; } }, switchMapType: function(type) { map.type=type; map.drawIcons(); }, 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.resortId = staticMap.attr('resortId'); map.init('staticMap', { dragging: false, zoomControl: false}); map.map.on('click', function() {window.location=$('#staticMap').attr('url');}); map.map.setView([y, x], z); } } }; var chart = new Object(); chart.drawYBars = function(elementId, values, yTicks, clickHandler, color) { if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.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: MONTH_TICKS }, yaxis: { ticks: yTicks, padMin: 0 } }, series:[{color: color===undefined?'#7098ad':color}] }); if (clickHandler!=undefined) { $('#'+elementId).bind('jqplotDataClick', clickHandler); } }; chart.drawDayTempChart = function(elementId, values, ticks, legendLabels, monthId, isUS) { var strFormat = GET_CHART_FORMAT_STRING(monthId, isUS); if (('#'+elementId).length == 0) return; $('#'+elementId).html(''); $.jqplot(elementId, values, { 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,'']] }, yaxis:{ ticks: ticks } }, highlighter: { show: true, sizeAdjust: 5, formatString: strFormat, tooltipLocation: 'ne' }, cursor: { show: false }, legend: { renderer: $.jqplot.EnhancedLegendRenderer, show:true, rendererOptions: { numberRows: 1 }, location: 's', placement: 'outsideGrid' }, series:[ {label: legendLabels[0], color: '#eaa228'}, {label: legendLabels[1], color: '#4bb2c5'}, {markerOptions: { size: 10 }, showLine:false } ] }); }; var tabs = new Object(); tabs.click = function(el) { var tab = $(this).attr('id'); if ('tabCurrent'==tab) { map.switchMapType(''); $('#sliderPanel').hide(); $('#tabCurrent').addClass('sel'); $('#tabMonth').removeClass('sel'); } else if ('tabMonth'==tab) { map.switchMapType('m'+slider.getMonthId()); $('#sliderPanel').show(); $('#tabCurrent').removeClass('sel'); $('#tabMonth').addClass('sel'); } }; var slider = new Object(); slider.getMonthId = function() { var index = 0; var month = 0; $('#slider tr.months td').each(function(i, el) { index++; if ($(el).hasClass('sel')) { month = index; } }); return month; }; slider.click = function(index) { $('#slider td').removeClass('sel'); $('#slider tr.months td').eq(index).addClass('sel'); $('#slider tr.selector td').eq(index).addClass('sel'); map.switchMapType('m'+(index+1)); };