KatastrUI={};KatastrUI.displayDocument=function(a,b){var c=this.map;$.get(a,function(f,d){var e=new google.maps.InfoWindow({position:c.getCenter(),content:b?f:"<pre>"+f+"</pre>"});InfoWindowUI.openWindow(e)})};KatastrUI.showPoint=function(d,a){var b=19;var c=this.map.getZoom();if(a){this.map.setCenter(d)}if(c<b-2){this.map.setCenter(d);c=b;this.map.setZoom(b)}this.dataPresenter.showPointInfo(d,this.getMapUrl(d,c))};KatastrUI.getMapUrl=function(e,b){var d="?lat="+e.lat()+"&lng="+e.lng()+"&zoom="+b;var a=document.location;var c=a.protocol+"//"+a.host+a.pathname;return c+d};KatastrUI.onAddressLocated=function(a){var b=a.geometry.location;this.showPoint(b)};KatastrUI.initialize=function(){this.addressLocator=new AddressLocator("#search-results",EventBinder.bind(this,this.onAddressLocated),function(){layout.open("west")});this.initGeocoder();this.initMap();AdManager.initAds(this.map);if(Config.streetViewContainer){StreetView.initialize(this.map)}InfoWindowUI.initialize(this.map,this.geocoder);this.dataPresenter=InfoWindowUI;this.initControls();google.maps.event.addListener(this.map,"click",EventBinder.bind(this,this.onMapClick));this.initByUserRequest();this.initAutocomplete()};KatastrUI.initAutocomplete=function(){var a=$("#address-search-input")[0];var c=new google.maps.places.Autocomplete(a,{types:["geocode"]});var b=new google.maps.LatLngBounds(new google.maps.LatLng(48.42,51.1),new google.maps.LatLng(11.8,19));c.setBounds(b)};KatastrUI.showLayerDialog=function(e,a,c){var b=$("#"+e);if(!b.length){var d=document.createElement("div");var b=$('<div id="'+e+'" style="display:hidden; scroll: auto"><div style="padding: 10px; 5px" id="'+e+'-info"></div></div>').appendTo("body");b.dialog({height:400,width:400});$.get(a,function(f){$("#"+e+"-info").html(f)});$.ajax({url:c,dataType:"json",success:EventBinder.bind(this,this.createLayerList,b)})}else{b.dialog("open")}};KatastrUI.createLayerList=function(e,d){var c=d.layers;for(var b=0;b<c.length;b++){var a=c[b];e.append(this.createNewLayerButton(d,a))}};KatastrUI.createNewLayerButton=function(d,b){var a=document.createElement("div");var c=document.createElement("a");c.innerHTML=b.title;c.href="#";google.maps.event.addDomListener(c,"click",EventBinder.bind(this,this.onNewLayerButtonClicked,d,b));a.appendChild(c);return a};KatastrUI.onNewLayerButtonClicked=function(c,a){var b=KatastrWmsLayerFactory.getWMSLayerByUrl(c.baseUrl,KatastrUI.map,a.name,c.copyright,13,20);this.addWmsLayer(b,a.title,false)};KatastrUI.initMap=function(){this.map=new google.maps.Map(document.getElementById("map_canvas"),Config.mapOptions);this.map.setCenter(new google.maps.LatLng(Config.default_location.lat,Config.default_location.lng));this.map.setZoom(Config.default_location.zoom);this.map.setMapTypeId(Config.defaultMapType);if(Config.earthPlugin){this.addEarthPlugin()}};KatastrUI.initGeocoder=function(){this.geocoder=new google.maps.Geocoder()};KatastrUI.initByUserRequest=function(){this.initLocationByUserRequest();this.initAddressByUserRequest()};KatastrUI.initLocationByUserRequest=function(){var b=LocationParser.getLocation();if(b==null){return}var a=new google.maps.LatLng(b.lat,b.lng);this.map.setCenter(a,b.zoom);this.showPoint(a,false)};KatastrUI.initAddressByUserRequest=function(){var a=AddressParser.getAddress();if(a==null){return}this.findByAddress(a)};KatastrUI.addEarthPlugin=function(){this.map.addMapType(G_SATELLITE_3D_MAP);this.map.getEarthInstance(function(b){var a="/static/katastr.kml";b.getLayerRoot().enableLayerById(b.LAYER_BUILDINGS,false);google.earth.fetchKml(b,a,function(c){if(c){b.getFeatures().appendChild(c)}})})};KatastrUI.onMapClick=function(a){if(a.latLng){this.showPoint(a.latLng,false)}};KatastrUI.latlngToDegrees=function(a){return{lat:this.numericalToDegrees(a.lat())+" "+(a.lat()>=0?"N":"S"),lng:this.numericalToDegrees(a.lng())+" "+(a.lng()>=0?"E":"W")}};KatastrUI.roundToPrecision=function(c,a){var b=Math.pow(10,a);return Math.floor(c*b)/b};KatastrUI.numericalToDegrees=function(g){var e=Math.floor(g);var a=g-e;var d=a*3600;var f=Math.floor(d/60);var c=(d-f*60);var b=this.roundToPrecision(c,3);return e+"°"+f+"'"+b+"''"};KatastrUI.getRightTopControlYPos=function(){return 30+25*this.mapControls.length};KatastrUI.addGeolocationControl=function(){var a=GeoLocationFactory.getGeoLocation();if(a!=null){this.addMapControl(new LinkControl(this.map,"Lokalizuj mě",EventBinder.bind(this,this.geolocate,a)))}};KatastrUI.geolocate=function(a){a.getCurrentPosition(EventBinder.bind(this,this.onGeoLocated),EventBinder.bind(this,this.onGeoLocationFailed),{enableHighAccuracy:true})};KatastrUI.onGeoLocated=function(a){this.showPoint(new google.maps.LatLng(a.coords.latitude,a.coords.longitude))};KatastrUI.onGeoLocationFailed=function(){alert("Geolokace selhala.")};KatastrUI.toggleLayer=function(c,b,a){if(a){c.setMap(this.map)}else{c.setMap(null)}if(b!=undefined){b(a)}};KatastrUI.toggleRealityFilterPanel=function(a){if(a){layout.open("east")}else{layout.close("east")}};KatastrUI.initControls=function(){this.mapControls=[];this.addWmsLayer(KatastrWmsLayerFactory.getDefaultWMSLayer(this.map),"Katastrální mapy",true);if(!Config.mobileVersion){this.addWmsLayer(KatastrWmsLayerFactory.getWMSLayer(this.map,"DEF_PARCELY"),"Def. body parcel",false);this.addWmsLayer(KatastrWmsLayerFactory.getWMSLayer(this.map,"DEF_BUDOVY"),"Def. body budov",false);this.addWmsLayer(KatastrWmsLayerFactory.getWMSLayer(this.map,"RST_PK_I"),"Pozemkový katastr",false)}this.addGeolocationControl();if(!Config.mobileVersion){this.addLayerOverlayControl("Panoramio",false,new google.maps.panoramio.PanoramioLayer());this.addMapControl(new LinkControl(this.map,"Nápověda",EventBinder.bind(this,this.displayDocument,"/static/help.html",true)));this.addMapControl(new LinkControl(this.map,"Územní plány",EventBinder.bind(this,this.showLayerDialog,"layers-up","/static/wms/up_info.html","/static/wms/up_wms.json",true)))}};KatastrUI.addMapControl=function(b){this.mapControls.push(b);var a=b.getContainer();a.index=1;this.map.controls[google.maps.ControlPosition.RIGHT_TOP].push(a)};KatastrUI.onResize=function(){google.maps.event.trigger(this.map,"resize")};KatastrUI.addWmsLayer=function(c,b,a){var d=new WmsLayerOverlay(this.map,c);this.addLayerOverlayControl(b,a,d)};KatastrUI.addLayerOverlayControl=function(c,a,b,d){var e=new CheckboxControl(this.map,c,a,EventBinder.bind(this,this.toggleLayer,b,d));this.addMapControl(e)};
