var x=0,default_x=0,y=0,default_y=0,scale=1,svg;
function zoomAndPan(){svg.getElementById("groupPanel").setAttribute("transform","translate("+x+", "+y+") scale("+scale+")");var b,c;$("circle.vector").each(function(){b=$(this).attr("id");c=svg.getElementById(b);svg.change(c,{r:3/scale,"stroke-width":2/scale})});var a;$("polyline.vector").each(function(){b=$(this).attr("id");a=svg.getElementById(b);svg.change(a,{"stroke-width":2/scale})});var d;$("path.vector").each(function(){b=$(this).attr("id");d=svg.getElementById(b);svg.change(d,{"stroke-width":0.5/
scale})})}function selectVisualization(){$("#choice").prop("checked")!=true?$("#openlayersmap").hide():$("#placeholder").hide();$(".choice").show()}function styleOSM(){var b=$("#placeholder");b={border:"1px solid #aaa",width:b.width(),height:b.height(),"float":"right"};$("#openlayersmap").css(b)}function loadSVG(){var b=$("#placeholder");b.svg({onLoad:function(c){svg=c}});b.find("svg:nth-child(2)").remove()}
function addZoomPanControllers(){var b=$("#placeholder");if($("#placeholder svg").length>0){var c=$("#pmaThemeImage").attr("value");$('<img class="button" id="left_arrow" src="'+c+'west-mini.png">').appendTo(b);$('<img class="button" id="right_arrow" src="'+c+'east-mini.png">').appendTo(b);$('<img class="button" id="up_arrow" src="'+c+'north-mini.png">').appendTo(b);$('<img class="button" id="down_arrow" src="'+c+'south-mini.png">').appendTo(b);$('<img class="button" id="zoom_in" src="'+c+'zoom-plus-mini.png">').appendTo(b);
$('<img class="button" id="zoom_world" src="'+c+'zoom-world-mini.png">').appendTo(b);$('<img class="button" id="zoom_out" src="'+c+'zoom-minus-mini.png">').appendTo(b)}}
function resizeGISVisualization(){var b=$("#placeholder");$("input[name='visualizationSettings[width]']").parents("tr").remove();$("input[name='visualizationSettings[height]']").parents("tr").remove();var c=b.width(),a=$(".gis_table").width();a=document.documentElement.clientWidth-100-a;b.width(a);$("svg").attr("width",a);x=default_x=(a-c)/2}function initGISVisualization(){selectVisualization();resizeGISVisualization();styleOSM();drawOpenLayers();loadSVG();addZoomPanControllers();zoomAndPan()}
$(document).ready(function(){$(".gis_table").length>0&&initGISVisualization();$("#choice").live("click",function(){if($(this).prop("checked")==false){$("#placeholder").show();$("#openlayersmap").hide()}else{$("#placeholder").hide();$("#openlayersmap").show()}});$("#placeholder").live("mousewheel",function(a,d){if(d>0){scale*=1.5;x=a.layerX-(a.layerX-x)*1.5;y=a.layerY-(a.layerY-y)*1.5}else{scale/=1.5;x=a.layerX-(a.layerX-x)/1.5;y=a.layerY-(a.layerY-y)/1.5}zoomAndPan();return true});var b=0,c=0;$("svg").live("dragstart",
function(a,d){$("#placeholder").addClass("placeholderDrag");b=Math.round(d.offsetX);c=Math.round(d.offsetY)});$("svg").live("mouseup",function(){$("#placeholder").removeClass("placeholderDrag")});$("svg").live("drag",function(a,d){newX=Math.round(d.offsetX);x+=newX-b;b=newX;newY=Math.round(d.offsetY);y+=newY-c;c=newY;zoomAndPan()});$("#placeholder").live("dblclick",function(a){scale*=1.5;x=a.layerX-(a.layerX-x)*1.5;y=a.layerY-(a.layerY-y)*1.5;zoomAndPan()});$("#zoom_in").live("click",function(a){a.preventDefault();
scale*=1.5;width=$("#placeholder svg").attr("width");height=$("#placeholder svg").attr("height");x=width/2-(width/2-x)*1.5;y=height/2-(height/2-y)*1.5;zoomAndPan()});$("#zoom_world").live("click",function(a){a.preventDefault();scale=1;x=default_x;y=default_y;zoomAndPan()});$("#zoom_out").live("click",function(a){a.preventDefault();scale/=1.5;width=$("#placeholder svg").attr("width");height=$("#placeholder svg").attr("height");x=width/2-(width/2-x)/1.5;y=height/2-(height/2-y)/1.5;zoomAndPan()});$("#left_arrow").live("click",
function(a){a.preventDefault();x+=100;zoomAndPan()});$("#right_arrow").live("click",function(a){a.preventDefault();x-=100;zoomAndPan()});$("#up_arrow").live("click",function(a){a.preventDefault();y+=100;zoomAndPan()});$("#down_arrow").live("click",function(a){a.preventDefault();y-=100;zoomAndPan()});$(".polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, .geometrycollection").live("mousemove",function(a){contents=$.trim(escapeHtml($(this).attr("name")));$("#tooltip").remove();
contents!=""&&$('<div id="tooltip">'+contents+"</div>").css({position:"absolute",display:"none",top:a.pageY+10,left:a.pageX+10,border:"1px solid #fdd",padding:"2px","background-color":"#fee",opacity:0.8}).appendTo("body").fadeIn(200)});$(".polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, .geometrycollection").live("mouseout",function(){$("#tooltip").remove()})});
