function CaUtilsInterface(map) { this.map = map; // map interface object this.elMapView; this.elFlipLayerSHOCart1; this.elFlipLayerSHOCart2; this.elFlipImport; this.elFlipImportWait; this.elFlipLayers; this.elRegionSelect; this.isfullscreen; this.posAreas; this.posProvinces; this.isOnLayerSHOCart1; this.isOnLayerSHOCart2; this.showMapShopUrl; this.updateURLTimeout; this.pUpdateURL; this._create = function() { } this.initialize = function() { this.elMapView = document.getElementById('map_view'); this.elFlipLayerSHOCart1 = document.getElementById('cb_vrstva_klad1'); this.elFlipLayerSHOCart2 = document.getElementById('cb_vrstva_klad2'); this.elFlipImport = document.getElementById('import_tracklogu'); this.elFlipImportWait = document.getElementById('import_tracklogu_wait') this.elFlipLayers = document.getElementById('prepinac_vrstev'); this.elRegionSelect = document.getElementById('regionselect'); this.isfullscreen = false; if (this.isCookie("ca_header")) { if (this.getCookie("ca_header") == '1') { document.getElementById("stranka").style.display = "block"; document.getElementById("map_buttons").style.top = "185px"; this.map.cJoyZoom.move(15, 270); this.isfullscreen = false; } else { document.getElementById("stranka").style.display = "none"; document.getElementById("map_buttons").style.top = "15px"; this.map.cJoyZoom.move(15, 95); this.isfullscreen = true; } } this.posAreas = new Array(); this.posProvinces = new Array(); this.isOnLayerSHOCart1 = false; this.isOnLayerSHOCart2 = false; this.layerSHOCart1 = new OpenLayers.Layer.TMS('OLLayerSHOCart1', '', {'type':'png', 'getURL':jQuery.proxy(this.getLayerSHOCart1URL, this), 'isBaseLayer':false, 'alpha':true, resolutions:OLM.resolutions, zoomOffset:OLM.zoomOffset}); this.layerSHOCart2 = new OpenLayers.Layer.TMS('OLLayerSHOCart2', '', {'type':'png', 'getURL':jQuery.proxy(this.getLayerSHOCart2URL, this), 'isBaseLayer':false, 'alpha':true, resolutions:OLM.resolutions, zoomOffset:OLM.zoomOffset}); this.updateURLTimeout = null; this.pUpdateURL = jQuery.proxy(this.updateURL, this); this.attachEvents(); } this.updateSize = function() { var w = 0, h = 0; if (window.innerWidth) { //Non-IE w = this.elMapView.clientWidth + 16; h = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' w = document.documentElement.clientWidth - 16; h = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible w = document.body.clientWidth - 16; h = document.body.clientHeight; } if (w < 760) w = 760; hdif = 0; this.elMapView.style.height = (h - 13 + hdif)+"px"; this.map.map.updateSize(); } this.onMapMoveEnd = function() { if (this.updateURLTimeout) { clearTimeout(this.updateURLTimeout); } this.updateURLTimeout = setTimeout(this.pUpdateURL, 1000); } this.updateURL = function() { this.updateURLTimeout = null; var pos = this.map.getCenter(); var zoom = this.map.getZoom(); var n = "pos=" + parseFloat(pos.lat).toFixed(5) + "P" + parseFloat(pos.lng).toFixed(5) + "P" + zoom; window.location.hash = n; } this.onClickReportError = function() { this.reportError(); return false; } this.reportError = function() { if (window.location.hash.length > 0) { h = window.location.hash; } else { h = ''; } window.open("http://www.cykloserver.cz/hlaseni-chyb/" + h, "_blank"); } this.getLayerSHOCart1URL = function(bnds) { var nbnds = this.map.tranformToOLM(bnds); var url = 'http://www.cykloserver.cz/cykloatlas/klad.php?vport=256;256&bbox=' + nbnds.left + ',' + nbnds.bottom + ',' + nbnds.right + ',' + nbnds.top; return url; } this.getLayerSHOCart2URL = function(bnds) { var nbnds = this.map.tranformToOLM(bnds); var url = 'http://www.cykloserver.cz/cykloatlas/klad2.php?vport=256;256&bbox=' + nbnds.left + ',' + nbnds.bottom + ',' + nbnds.right + ',' + nbnds.top; return url; } this.onClickFlipLayerSHOCart1 = function() { this.flipLayerSHOCart(1); } this.onClickFlipLayerSHOCart2 = function() { this.flipLayerSHOCart(2); } this.flipLayerSHOCart = function(id) { if (id == 1) { if (this.isOnLayerSHOCart1) { this.map.map.removeLayer(this.layerSHOCart1); this.isOnLayerSHOCart1 = false; } else { this.map.map.addLayer(this.layerSHOCart1); this.isOnLayerSHOCart1 = true; } } else { if (this.isOnLayerSHOCart2) { this.map.map.removeLayer(this.layerSHOCart2); this.isOnLayerSHOCart2 = false; } else { this.map.map.addLayer(this.layerSHOCart2); this.isOnLayerSHOCart2 = true; } } } this.onClickFlipImport = function() { this.flipImport(); return false; } this.flipImport = function() { if (this.elFlipImport) { this.elFlipImportWait.style.display = "none"; this.elFlipImport.style.display = (this.elFlipImport.style.display == "block") ? "none" : "block"; } } this.onClickFlipLayers = function() { this.flipLayers(); return false; } this.flipLayers = function() { if (this.elFlipLayers) { this.elFlipLayers.style.display = (this.elFlipLayers.style.display == "block") ? "none" : "block"; } } this.setShowMapShopUrl = function(url) { this.showMapShopUrl = url; } this.onClickShowMapShop = function() { this.showMapShop(); return false; } this.showMapShop = function() { try { var pos = this.map.getCenter(); var zoom = this.map.getZoom(); url = this.showMapShopUrl; /*url+= 'c'; url+= ''; url+= ''+pos.lat; url+= '+'; url+= ''+pos.lng; url+= '+'; url+= ''+zoom;*/ window.open(url, "_blank"); } catch (e) { } return false; } this.onChangeAreaCB = function() { this.scrollToArea(); } this.scrollToArea = function() { if (this.elRegionSelect) { i = this.elRegionSelect.selectedIndex; v = this.elRegionSelect.value; if ((v != -1) && (v != -2)) { var bbox = this.posAreas[this.elRegionSelect.options[i].value]; var wgs84sw = this.s42towgs84(bbox.minx, bbox.miny, true); var latsw = wgs84sw.fi; var lngsw = wgs84sw.lambda; var wgs84ne = this.s42towgs84(bbox.maxx, bbox.maxy, true); var latne = wgs84ne.fi; var lngne = wgs84ne.lambda; this.map.showExtent(lngsw, latsw, lngne, latne); } } } this.scrollToProvince = function(id) { var wgs = this.s42towgs84(this.posProvinces[id].pposx, this.posProvinces[id].pposy, true); var lat = wgs.fi; var lng = wgs.lambda; this.map.setCenter(new OLM.LatLng(lat, lng), 9); } this.onClickFlipFullscreen = function() { this.flipFullscreen(); return false; } this.flipFullscreen = function() { if (this.isfullscreen) { this.setCookie("ca_header", 1); document.getElementById("stranka").style.display = "block"; document.getElementById("map_buttons").style.top = "185px"; this.map.cJoyZoom.move(15, 270); this.isfullscreen = false; } else { this.setCookie("ca_header", 0); document.getElementById("stranka").style.display = "none"; document.getElementById("map_buttons").style.top = "15px"; this.map.cJoyZoom.move(15, 95); this.isfullscreen = true; } } this.setCookie = function(key, value) { value = encodeURIComponent(value); value+= '; path=/'; var date = new Date(); date.setTime(date.getTime() + 90 * 24 * 60 * 60 * 1000); value+='; expires=' + date.toGMTString(); document.cookie = key + '=' + value; } this.isCookie = function(key) { if (document.cookie.indexOf(key + '=') == 0) return true; if (document.cookie.indexOf('; ' + key + '=') > 0) return true; return false; } this.getCookie = function(key) { var i = document.cookie.indexOf('; ' + key + '='); if (i == -1) { i = document.cookie.indexOf(key + '='); if (i == -1) { return false; } else { i+= key.length + 1; } } else { i+= key.length + 3; } var ie = document.cookie.indexOf(';', i); if (ie == -1) { return document.cookie.substring(i); } else { return document.cookie.substring(i, ie); } } this.s42towgs84 = function(y, x, f) { function formatwgs84(p) { p += 0.0001388888888888889; var sign = 1; if (p < 0) { sign = -1; p = -1 * p; } var deg = Math.floor(p); var min = Math.floor((p - deg) * 60); var sec = Math.round((p - deg - min / 60) * 3600 * 100) / 100 + 0.001; if (min < 10) { min = "0" + min; } if (sec < 10) { sec = "0" + sec; } sec = String(sec); sec = sec.substr(0, 5); return (sign < 0 ? "-" : "") + deg + "\xB0" + min + "\u2032" + sec + "\u2033"; } if (!y || !x) { return false; } var ro = 57.29577951308232; var a = 6378245; var c = 6356863.019; var e2 = 0.00673852541468; var ee = 0.006693421622970001; var pas = 3; var lnula = pas * 6 - 3; var b = x / 111134.861084; y = y - pas * 1000000 - 500000; var br = b / ro; var db = 16036.480269 * Math.sin(2 * br); db = db - 16.828067 * Math.sin(4 * br); db = db + 0.021975 * Math.sin(6 * br); db = db - 0.000031 * Math.sin(8 * br); var t = Math.sin(br) / Math.cos(br); var eta2 = e2 * Math.cos(br) * Math.cos(br); var n = a * a / (c * Math.sqrt(eta2 + 1)); b = b + db * ro * (1 + eta2) / n; b = b - (3 * ro * t * db * db * eta2) * (1 + eta2) / (2 * n * n); b = b - (ro * db * db * db * eta2) * (1 - t * t + 2 * eta2 - 6 * t * t * eta2) / (2 * n * n * n); br = b / ro; t = Math.sin(br) / Math.cos(br); eta2 = e2 * Math.cos(br) * Math.cos(br); n = a * a / (c * Math.sqrt(eta2 + 1)); l = lnula; l1 = (ro * y) / (n * Math.cos(br)); l += l1; l2 = - (ro * y * y * y) * (1 + 2 * t * t + eta2) / (6 * n * n * n * Math.cos(br)); l += l2; l3 = (ro * y * y * y * y * y) * (5 + 28 * t * t + 24 * t * t * t * t + 6 * eta2 + 8 * t * t * eta2) / (120 * n * n * n * n * n * Math.cos(br)); l += l3; b = b - (ro * t * y * y) * (1 + eta2) / (2 * n * n); b = b + (ro * t * y * y * y * y) * (5 + 3 * t * t + 6 * eta2 - 6 * t * t * eta2 - 3 * eta2 * eta2 - 9 * t * t * eta2 * eta2) / (24 * n * n * n * n); l = l / ro; b = b / ro; var f84 = b - 1.4 / 3600 / ro; var l84 = l - 6.2 / 3600 / ro; if (l > 18 / ro) { f84 = b - 1.2 / 3600 / ro; l84 = l - 6.1 / 3600 / ro; } f84 = f84 * 180 / Math.PI; l84 = l84 * 180 / Math.PI; if (!f) { f84 = formatwgs84(f84); l84 = formatwgs84(l84); } return {fi: f84, lambda: l84}; } this.attachEvents = function() { this.map.map.events.register('moveend', this, this.onMapMoveEnd); } this._create(); this.initialize(); }