var CORE_HOST = "https://cc.pogoda.turtella.ru"; var STATIC_HOST_MAPIMAGES = "https://map-icons.pogoda.turtella.ru"; document.domain = 'turtella.ru'; if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str){ return this.indexOf(str) == 0; }; }; 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(); } }; var map = { type: 'weather', subtype: '', resortId: 0, markers: [], map: {}, initializeInformerMap: function() { var hash = window.location.hash.split('#')[1]; var params = hash.split(','); var type = params[0]; var subType = params[1]; var x = params[2]*1; var y = params[3]*1; var z = params[4]*1; map.initializeFrameMap(0,0,x,y,z,type,subType); }, initializeFrameAndMap: function(x, y, z, type, subtype) { map.initializeFrameMap(0, 0, x, y, z, type, subtype); }, initializeFrameMap: function(w, h, x, y, z, type, subtype) { if (type!=undefined) map.type=type; if (subtype!=undefined) map.subtype=subtype; if (w==0 || h==0) { w = $(document).width(); h = $(document).height(); } $('#frameMapCanvas').width(w).height(h); map.init(); map.map.setView([y, x], z); }, init: function() { map.map = L.map('frameMapCanvas', {scrollWheelZoom: false}); L.tileLayer('https://tiles.turtella.ru/v1/{z}/{y}/{x}', { attribution: 'Погода курортов мира', 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, resortId: map.resortId}, 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.lnkMain}).addTo(map.map).on('click', map.markerClick)); }); }, type: 'POST', url: '/ajax/getBoundsResorts/' }); }, markerClick: function(evt) { top.location = evt.target.options.data; }, 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)+'/'; } } }, switchMapType: function(type, subtype) { map.type=type; map.subtype=subtype; map.drawIcons(); } }; window.addEventListener( "message", (event) => { if (event.origin !== "https://gid.turtella.ru") { console.log('bad origin'); } else { var d = event.data; if (d.action=='init') { map.initializeFrameMap(d.w, d.h, d.x, d.y, d.z, d.type, d.subtype); } else if (d.action='change') { map.switchMapType(d.type, d.subtype); } } }, false, );