var pbbox=[];
function kresli_print(){var a=$("input[name=form_mierka]:checked").val(),b=$("input[name=form_papier]:checked").val(),c=a+b,d=parseInt(olMapa.map.getCenter().lon),f=parseInt(olMapa.map.getCenter().lat);if(pbbox[c]==undefined){data={form_papier:b,form_mierka:a};$.post("/json/print_bbox/",data,function(e){pbbox[c]=e;var g="POLYGON (";g+=e.xmin+d+" ";g+=e.ymin+f+",";g+=e.xmin+d+" ";g+=e.ymax+f+",";g+=e.xmax+d+" ";g+=e.ymax+f+",";g+=e.xmax+d+" ";g+=e.ymin+f+",";g+=e.xmin+d+" ";g+=e.ymin+f+")";olMapa.kresli_tlacoveWKT(g)},
"json")}else{a=pbbox[c];b="POLYGON (";b+=a.xmin+d+" ";b+=a.ymin+f+",";b+=a.xmin+d+" ";b+=a.ymax+f+",";b+=a.xmax+d+" ";b+=a.ymax+f+",";b+=a.xmax+d+" ";b+=a.ymin+f+",";b+=a.xmin+d+" ";b+=a.ymin+f+")";olMapa.kresli_tlacoveWKT(b)}}function zmaz_print(){if(olMapa.vrstvy.olPrintBBox!=undefined){olMapa.map.removeLayer(olMapa.vrstvy.olPrintBBox);olMapa.vrstvy.olPrintBBox=null}}
var nastavenie_merania={displayUnits:null,handlerOptions:{persist:true}},measureControls={mline:new OpenLayers.Control.Measure(OpenLayers.Handler.Path,nastavenie_merania),mpolygon:new OpenLayers.Control.Measure(OpenLayers.Handler.Polygon,nastavenie_merania)},aktivnaVrstva={vrstvy:[],register_selectov:[],tlacitko:null,pridajVrstvu:function(a,b,c){this.vrstvy[a]={nazov:b,triedy:c,zapnuta:false}},zapniVrstvu:function(a){if(this.jeAktivna(this.vrstvy[a])){var b='<option id="sel_'+a+'" value="'+a+'">'+
this.vrstvy[a].nazov+"</option>";$("#aktivna_vrstva").append(b)}this.vrstvy[a].zapnuta=true},vypniVrstvu:function(a){$("#sel_"+a).remove();this.vrstvy[a].zapnuta=false},reset:function(){if($("#aktivna_vrstva").val())this.register_selectov[this.tlacitko]=$("#aktivna_vrstva").val();this.tlacitko=tlacitko;$("#aktivna_vrstva").empty();for(var a in this.vrstvy)if(this.jeAktivna(this.vrstvy[a])&&this.vrstvy[a].zapnuta){var b='<option id="sel_'+a+'" value="'+a+'">'+this.vrstvy[a].nazov+"</option>";$("#aktivna_vrstva").append(b)}this.register_selectov[this.tlacitko]&&
$("#sel_"+this.register_selectov[this.tlacitko]).attr("selected","selected")},jeAktivna:function(a){for(var b in a.triedy)if(a.triedy[b]==this.tlacitko)return true;return false}},olMapa={vrstvy:[],dotaz_vrstvy:[],vrstva_konf:null,vrstva_konf_base:null,map:null,bod_kliku:null,znacky_pocet:0,zb:null,init:function(){var a={controls:[],theme:null,units:config.units,projection:config.projection,maxExtent:new OpenLayers.Bounds(config.maxExtent[0],config.maxExtent[1],config.maxExtent[2],config.maxExtent[3])};
olMapa.vrstva_konf={resolutions:config.resolutions,units:config.units,projection:config.projection,visibility:false,buffer:0};olMapa.vrstva_konf_base={resolutions:config.resolutions,units:config.units,projection:config.projection,isBaseLayer:true,buffer:1,transitionEffect:"resize"};olMapa.map=new OpenLayers.Map("map",a);olMapa.map.addControl(new OpenLayers.Control.PanZoomBar({div:OpenLayers.Util.getElement("panzoom_panel"),slideFactor:250}));olMapa.map.addControl(new OpenLayers.Control.ScaleLine);
olMapa.map.addControl(new OpenLayers.Control.Scale(OpenLayers.Util.getElement("mierka")));olMapa.map.addControl(new OpenLayers.Control.MousePosition({div:OpenLayers.Util.getElement("koordinaty")}));olMapa.map.addControl(new OpenLayers.Control.Attribution);olMapa.map.addControl(new OpenLayers.Control.Navigation);olMapa.map.events.register("click",olMapa.map,function(d){bod_kliku=olMapa.map.getLonLatFromViewPortPx(d.xy);switch(tlacitko){case "identify":olMapa.dotaz(d);break;case "bod":d=olMapa.map.getLonLatFromViewPortPx(d.xy);
$("#id_poi_coord1").val(d.lon);$("#id_poi_coord2").val(d.lat);$("#bod_text").dialog("open");break}});olMapa.map.events.register("zoomend",olMapa.map,function(){olMapa.zmenenyZoom()});olMapa.map.events.register("moveend",olMapa.map,function(){zalozka=="tlac"&&kresli_print()});a=new OpenLayers.Control.NavigationHistory;olMapa.map.addControl(a);var b=new OpenLayers.Control.Panel({div:OpenLayers.Util.getElement("panel-nav")});b.addControls([a.next,a.previous]);olMapa.map.addControl(b);OpenLayers.Feature.Vector.style["default"].strokeWidth=
2;for(var c in measureControls){a=measureControls[c];a.events.on({measure:olMapa.handleMeasurements,measurepartial:olMapa.handleMeasurements});olMapa.map.addControl(a)}if(config.overview_image!="-"){c={layers:[new OpenLayers.Layer.Image("Nahladova vrstva","/media/"+config.overview_image,new OpenLayers.Bounds(config.overview_bounds[0],config.overview_bounds[1],config.overview_bounds[2],config.overview_bounds[3]),new OpenLayers.Size(config.overview_size[0],config.overview_size[1]),{numZoomLevels:1,
alwaysInRange:true})],size:new OpenLayers.Size(config.overview_size[0],config.overview_size[1])};c=new OpenLayers.Control.OverviewMap(c);c.isSuitableOverview=function(){return true};olMapa.map.addControl(c);$("#olControlOverviewMapMaximizeButton").click(function(){$(".olControlAttribution").css("right",config.overview_size[0]+30+"px")});$("#OpenLayers_Control_minimizeDiv").click(function(){$(".olControlAttribution").css("right","2px")})}},zmenenyZoom:function(){var a=olMapa.map.getZoom();$("#zoom_level").html("ZL: "+
a);$(".chb_vrstva").each(function(){if(a<$(this).attr("rel")){if($(this).attr("checked")){var c=$(this).attr("id");olMapa.vrstvy[c].setVisibility(false);aktivnaVrstva.vypniVrstvu(c);$(".legenda_"+c).hide()}$(this).attr("disabled",true);$(this).next("label").addClass("vypnute")}else if(!$(this).parent().parent().prev().children().children().hasClass("vypnute")){$(this).parent().parent().hasClass("vypnute")||$(this).attr("disabled",false);if($(this).attr("checked")&&!$(this).attr("disabled")&&$(this).next("label").hasClass("vypnute")){c=
$(this).attr("id");olMapa.vrstvy[c].setVisibility(true);aktivnaVrstva.zapniVrstvu(c);$(".legenda_"+c).show()}$(this).next("label").removeClass("vypnute")}});var b=Math.round(olMapa.map.getScale());$("#form_mierka_"+b).attr("checked","checked");zalozka=="tlac"&&kresli_print()},pridajPodkladovuVrstvu:function(a){var b="pvrstva"+a.id;olMapa.vrstva_konf_base.attribution=a.copyright;olMapa.vrstvy[b]=new OpenLayers.Layer.WMS(a.nazov,a.wms_url,{layers:a.wms_vrstva,format:"image/"+a.format,tckey:config.tckey},
olMapa.vrstva_konf_base);olMapa.dotaz_vrstvy[b]={vrstva:a.wms_vrstva_original,id:a.id}},pridajVrstvu:function(a){var b="vrstva"+a.id;olMapa.vrstva_konf.attribution=a.copyright;if(a.wms_url==a.wms_url_original){olMapa.vrstva_konf.singleTile=true;var c=a.wms_map}else{olMapa.vrstva_konf.singleTile=false;c=null}olMapa.vrstvy[b]=new OpenLayers.Layer.WMS(a.nazov,a.wms_url,{map:c,layers:a.wms_vrstva,transparent:true,format:"image/"+a.format,tckey:config.tckey},olMapa.vrstva_konf);olMapa.dotaz_vrstvy[b]=
{vrstva:a.wms_vrstva_original,id:a.id};c=[];a.ident&&c.push("identify");aktivnaVrstva.pridajVrstvu(b,a.nazov,c)},zobraz:function(a,b,c){olMapa.map.setCenter(new OpenLayers.LonLat(b,c),a)},prepniMeranie:function(a){for(key in measureControls){var b=measureControls[key];if(a==key)b.activate();else{b.deactivate();$("#meranie").empty()}}},handleMeasurements:function(a){var b=a.units,c=a.measure,d="";d+=a.order==1?"d\u013a\u017eka: "+c.toFixed(3)+" "+b:"plocha: "+c.toFixed(3)+" "+b+"<sup>2</sup>";$("#meranie").html(d)},
dotaz:function(a){$("#load").show();var b=$("#aktivna_vrstva").val();if(b!=null){var c="/json/feature_info/"+olMapa.dotaz_vrstvy[b].vrstva+"/";a={bbox:olMapa.vrstvy[b].map.getExtent().toBBOX(),x:a.xy.x,y:a.xy.y,width:olMapa.vrstvy[b].map.size.w,height:olMapa.vrstvy[b].map.size.h};$.getJSON(c,a,function(d){atrOkno.zobraz(d.text,d.vrstva);d=$("#aktivna_vrstva").val();d!=null?$.getJSON("/json/zoomlevel/layer/"+olMapa.dotaz_vrstvy[d].id+"/",function(f){$(".zobr_obj").click(function(){$.getJSON($(this).attr("rel"),
function(e){olMapa.kresliWKT(e,f)})})}):$("#load").hide()})}else{$("#load").hide();$("<div></div>").attr("id","ident-error").html('<p class="ui-state-error ui-corner-all" style="padding: 5px;">Mus\u00edte ma\u0165 zapnut\u00fa aspo\u0148 jednu vrstvu, v ktorej je mo\u017en\u00e9 identifikova\u0165 objekty. Tak\u00e1to vrstva sa n\u00e1sledne zobraz\u00ed aj v zozname Akt\u00edvnych vrstiev.').appendTo(document.body).dialog({title:"Upozornenie pre pou\u017e\u00edvate\u013eov",zIndex:6E3,resizable:false,
close:function(){$(this).dialog("destroy");$("#ident-error").remove()}})}},stitky:[],kresliZnacku:function(a,b,c){if(c!=null&&a!=""&&!isNaN(a)&&b!=""&&!isNaN(b)){a=new OpenLayers.LonLat(parseFloat(a),parseFloat(b));if(olMapa.znacky_pocet==0){olMapa.vrstvy.olznacky=new OpenLayers.Layer.Markers("olznacky");olMapa.map.addLayer(olMapa.vrstvy.olznacky)}b=new OpenLayers.Size(20,34);var d=new OpenLayers.Pixel(-(b.w/2),-b.h);b=new OpenLayers.Icon("/media/gisplan/red_bod.png",b,d);olMapa.vrstvy.olznacky.addMarker(new OpenLayers.Marker(a,
b));olMapa.znacky_pocet++;this.map.setCenter(a);if(c!=""){b=new OpenLayers.Popup("stitok"+olMapa.znacky_pocet,a,new OpenLayers.Size(0,0),c,false);b.autoSize=true;b.minSize=new OpenLayers.Size(10,10);b.maxSize=new OpenLayers.Size(100,500);b.setBackgroundColor("#FFF79F");b.setOpacity(0.8);b.setBorder("2px solid white");olMapa.map.addPopup(b);olMapa.stitky.push(b)}c=a.lon+":"+a.lat+":"+c;a=$("#form_body");b=a.val();b==""?a.val(c):a.val(b+"^^"+c)}},kresli_tlacoveWKT:function(a){var b=OpenLayers.Util.applyDefaults({strokeWidth:2,
strokeColor:"#FF0000",fillColor:"#FFFFFF",fillOpacity:0.2},OpenLayers.Feature.Vector.style["default"]);olMapa.vrstvy.olPrintBBox!=undefined&&olMapa.map.removeLayer(olMapa.vrstvy.olPrintBBox);olMapa.vrstvy.olPrintBBox=new OpenLayers.Layer.Vector("olPrintBBox",{style:b});olMapa.map.addLayer(olMapa.vrstvy.olPrintBBox);a=(new OpenLayers.Format.WKT).read(a);olMapa.vrstvy.olPrintBBox.addFeatures([a])},highlight_layer:null,kresliWKT:function(a,b){if(a.geom!=""&&a.bbox!=""){OpenLayers.Feature.Vector.style["default"].pointRadius=
25;var c=OpenLayers.Util.applyDefaults({strokeWidth:4,strokeColor:"#3DD4C2",strokeOpacity:0.5,fillOpacity:0.2},OpenLayers.Feature.Vector.style["default"]);this.highlight_layer&&this.map.removeLayer(this.highlight_layer);this.highlight_layer=new OpenLayers.Layer.Vector("highlight",{style:c});this.map.addLayer(this.highlight_layer);c=(new OpenLayers.Format.WKT).read(a.geom);ideal_zoom=this.map.getZoomForExtent(new OpenLayers.Bounds(a.bbox.left,a.bbox.down,a.bbox.right,a.bbox.up),true);b.zoom_level<=
ideal_zoom?this.map.setCenter(new OpenLayers.LonLat(a.bbox.left+(a.bbox.right-a.bbox.left)/2,a.bbox.down+(a.bbox.up-a.bbox.down)/2),b.zoom_level):this.map.setCenter(new OpenLayers.LonLat(a.bbox.left+(a.bbox.right-a.bbox.left)/2,a.bbox.down+(a.bbox.up-a.bbox.down)/2),ideal_zoom);this.highlight_layer.addFeatures([c])}OpenLayers.Feature.Vector.style["default"].pointRadius=6}};

