 var DistanceObject= Class.create(); DistanceObject.prototype = { initialize: function(Map) { this.A0={ 'inches': 1.0, 'mi': 63360.0, 'm': 39.3701, 'km': 39370.1, 'd': 4374754, }; this.A1="svgD"; this.A2="label_div"; this.A3="insertDiv"; this.A4=0; this.A5=2; this.A6=2; this.A8=this.A7=4; this.A9=Map; this.A10=14; this.A9.A12=this; this.A11=true; var html = '<div id ="'+this.A1+'" style="position:absolute; z-index:30; " ></div>'; new Insertion.Bottom($(this.A9.A54),html); $(this.A1).style.height=$(this.A9.A1).getStyle('height'); $(this.A1).style.width=$(this.A9.A1).getStyle('width'); this.A12="http://www.w3.org/2000/svg"; this.A13=screen.width; this.A14=screen.height; this.A37(); this.A17=null; this.A18=this.A43.bindAsEventListener(this); this.A19=this.A46.bindAsEventListener(this); this.A20=this.A45.bindAsEventListener(this); this.A21=this.A44.bindAsEventListener(this); this.A22=this.A47.bindAsEventListener(this); Event.observe($(this.A9.A54),'dblclick',this.A21); Event.observe(document,'keypress',this.A22); this.A23=null; this.A24=new Array(); this.A25=new Array(); this.A26="M"; this.A27="DistSurf"; this.A28=null; this.A29=0; this.A30=new Array(); this.A31=null; this.A33=this.A32=false; this.A34=null; this.A35=new Array(); Event.observe($('Oks'),"click",this.A68.bindAsEventListener(this)); Event.observe($('labelname'),"keypress",this.A68.bindAsEventListener(this)); }, A37: function() { this.A15=document.createElementNS(this.A12,"svg"); this.A15.setAttributeNS(null,"height",this.A14); this.A15.setAttributeNS(null,"width",this.A13); this.A15.setAttributeNS(null,"id","svgDraw"); this.A15.setAttributeNS(null,"position","absolute"); this.A15.setAttributeNS(null,"viewBox","0 0 "+this.A13+" " +this.A14); this.A16=document.createElementNS(this.A12,"g"); this.A16.setAttributeNS(null,"stroke","blue"); this.A16.setAttributeNS(null,"stroke-width",this.A5); this.A16.setAttributeNS(null,"stroke-opacity",0.65); this.A16.setAttributeNS(null,"fill-opacity",0.1); $(this.A1).appendChild(this.A15); this.A15.appendChild(this.A16); }, A38: function(pos,text) { var node = document.createElementNS(this.A12,"text"); node.setAttributeNS(null, "x", pos.x); node.setAttributeNS(null, "y", pos.y-this.A7); node.setAttributeNS(null, "fill", "red"); node.setAttributeNS(null, "stroke", "white"); node.setAttributeNS(null, "font-weight", "bold"); node.setAttributeNS(null, "style", "text-anchor:middle"); var stroke_w=(this.A6/this.puis); if(stroke_w>1)stroke_w=1; node.setAttributeNS(null, "stroke-width",stroke_w); var size=this.A10/this.puis; node.setAttributeNS(null, "font-size", size); node.setAttributeNS(null,"fill-opacity",1); this.A16.appendChild(node); new Insertion.Bottom(node,text); return node; }, A39: function(pos) { var node = document.createElementNS(this.A12,"circle"); node.setAttributeNS(null, "cx", pos.x); node.setAttributeNS(null, "cy", pos.y); node.setAttributeNS(null, "r",this.A7); node.setAttributeNS(null, "fill", "#000ccc"); this.A16.appendChild(node); return node; }, A40: function(pos) { var node = document.createElementNS(this.A12,"path"); var d = "M"+pos.x+","+pos.y+" "; node.setAttributeNS(null, "d", d); node.setAttributeNS(null, "fill", "none"); node.setAttributeNS(null, "stroke-linecap", "round"); node.setAttributeNS(null, "stroke-linejoin", "round"); if (this.A23=="polygon" || this.A23=="surface"){ node.setAttributeNS(null, "fill", "#000ccc"); node.setAttributeNS(null, "fill-rule", "evenodd"); } if (this.A23=="distance" || this.A23=="surface") node.setAttributeNS(null, "id", "DeleteFeature"); this.A16.appendChild(node); return node; }, A41:function(type) { if (type) this.A23=type; if ($("DeleteFeature")) this.A16.removeChild($("DeleteFeature")); Event.stopObserving($(this.A9.A1),'mousemove',this.A18); Event.stopObserving($(this.A9.A1),'mousedown',this.A19); Event.stopObserving($(this.A9.A1),'mouseup',this.A20); Event.stopObserving($(this.A9.A1), 'dblclick',this.A21); if (type=="point" || type=="insertion") { Event.observe($(this.A9.A1),'mousedown',this.A19); Event.observe($(this.A9.A1),'mouseup',this.A20); } else if (type=="line" || type=="distance" || type=="polygon" || type=="surface") { Event.observe($(this.A9.A1),'mousemove',this.A18); Event.observe($(this.A9.A1),'mousedown',this.A19); Event.observe($(this.A9.A1),'mouseup',this.A20); Event.observe($(this.A9.A1), 'dblclick',this.A21); } }, A42:function() { this.A26="M"; this.A24=new Array(); this.A35=new Array(); this.A25=new Array(); this.A11=true; this.A28=null; this.A17=null; }, A43:function(evt) { this.A54(this.A49(evt)); }, A44:function(evt) { if ($("tmp_point")) this.A16.removeChild($("tmp_point")); if (this.A23=="line" ||this.A23=="polygon") { if ( this.A25.length!=2) this.A64(this.A49(evt)); } else if(this.A23=="surface") { var posPixel=this.A49(evt); var intrersection1=intersection2=false; intersection1=this.A67(this.A24,posPixel); if (!intersection1) intersection2=this.A67(this.A24.reverse(false),posPixel); if (!(intersection1 || intersection2)) this.A42(); } else this.A42(); }, A45:function (evt) { var mouseUp= this.A49(evt); if ((this.A31.x==mouseUp.x )&&(this.A31.y==mouseUp.y )) this.A51(evt); }, A46:function (evt) { this.A31=this.A49(evt); }, A47: function (evt) { if(evt.keyCode==27) { this.A48(); } }, A48: function () { if ($("tmp_point")) this.A16.removeChild($("tmp_point")); if (this.A17)this.A16.removeChild(this.A17); this.A42(); $(this.A2).hide(); $(this.A3).hide(); this.A41(this.A23); }, A49: function(evt) { var pos={}; pos.x = Event.pointerX(evt)-Position.page($(this.A9.A1))[0]-Position.realOffset($(this.A9.A1))[0]; pos.y = Event.pointerY(evt)-Position.page($(this.A9.A1))[1]-Position.realOffset($(this.A9.A1))[1]; return pos; }, A50: function(posPixel) { var pos ={}; this.A61(); pos.x=parseFloat(this.box[0])+parseFloat(this.box[2])*(posPixel.x+(this.A13-this.A9.A24)/2)/this.A13;pos.y=parseFloat(this.box[1])+parseFloat(this.box[3])*(posPixel.y+(this.A14-this.A9.A25)/2)/this.A14;return pos; }, A51: function(evt){ if(Event.isLeftClick(evt)) this.A52(evt); else this.A53(evt); }, A52:function(evt){ if (Event.element(evt).id==this.A9.A59){ var posPixel=this.A49(evt); var posViewBox= this.A50(posPixel); if (this.A23=="point" || this.A23=="insertion") { if ($("DeleteFeature")) this.A16.removeChild($("DeleteFeature")); this.A30=this.A9.A78(posPixel.x,posPixel.y); this.A17=this.A39(posViewBox); this.A64(posPixel); this.lastPos=posViewBox; } else { this.A33=this.A32=false; if ( this.A23=="surface"){ this.A33=this.A67(this.A24,posPixel); if (!this.A33)this.A32=this.A67(this.A24.reverse(false),posPixel); } if (this.A33){ $('Infos').update("Intersection non autorisée"); $('Infos').show(); $(this.A27).update(""); } else { this.A24.push(posPixel); $('Infos').hide(); if (this.A11){ $(this.A27).update(""); if ($("DeleteFeature")) this.A16.removeChild($("DeleteFeature")); this.A28=this.A39(posViewBox); this.A28.setAttributeNS(null,"id","tmp_point"); this.A17=this.A40(posViewBox); this.A11=false; this.firstPos= this.A50(posPixel); } else { if ( this.A23=="distance") this.A29=this.DistSurf; if ( this.A23=="surface") if (this.A32){ $('Infos').update("Intersection non autorisée"); $('Infos').show(); $(this.A27).update(""); } else this.A59(this.A24); } this.A25.push(posViewBox); this.A26=this.A26+" "+posViewBox.x+","+posViewBox.y+" "; } } } }, A53:function(evt) { this.A25.pop(); this.A24.pop(); var newpath="M"; for ( var i=0;i<this.A25.length;i++) newpath+=this.A25[i].x+","+this.A25[i].y+" "; this.A26=newpath; this.A54(this.A49(evt)); if ( this.A23=="surface") $(this.A27).update(""); }, A54: function (posPixel){ this.A24.push(posPixel); if(this.A28&& !this.A9.A3){ var posViewBox= this.A50(posPixel); this.A28.setAttributeNS(null, "cx",posViewBox.x); this.A28.setAttributeNS(null, "cy",posViewBox.y); var newpath=this.A26+posViewBox.x+","+posViewBox.y+" "; if (this.A23=="distance") this.A58(); if (this.A23=="polygon" || this.A23=="surface") if(this.A25.length>1) newpath=newpath+" "+this.A25[0].x+","+this.A25[0].y+" "; this.A17.setAttribute("d",newpath); } this.A24.pop(); }, A55:function(depl_x,depl_y){ if ((this.A23=="distance" || this.A23=="surface")&&this.A24.length>0) { this.A24[this.A24.length-1].x+=depl_x; this.A24[this.A24.length-1].y+=depl_y; if (this.A23=="surface") { for (var i=0;i<this.A24.length-1;i++) { this.A24[i].x+=depl_x; this.A24[i].y+=depl_y; } } } }, A56: function (){ while (this.A16.lastChild) { this.A16.removeChild(this.A16.lastChild); this.A16.removeChild(this.A16.lastChild); } }, A57: function(){ if (this.A16.lastChild) { this.A16.removeChild(this.A16.lastChild); this.A16.removeChild(this.A16.lastChild); } }, A58: function() { var dist=0; for( var i=0;i<(this.A24.length-1);i++) { var x2=(this.A24[i].x-this.A24[i+1].x)*(this.A24[i].x-this.A24[i+1].x); var y2=(this.A24[i].y-this.A24[i+1].y)*(this.A24[i].y-this.A24[i+1].y); dist+=Math.sqrt(x2+y2); } dist= dist*this.A9.A106()*this.A0['d']/this.A0['m']; if (this.A9.A107()=="km") dist=((dist/1000)).toFixed(2); else dist= (Math.ceil(dist)); $(this.A27).update("Distance: "+dist+" "+this.A9.A107()); }, A59: function(tab) { if (tab.length>2 && this.A23=="surface") { tab.push(tab[0]); var sommes=0; var surf; var scal= this.A9.A106()*parseFloat(this.A0['d'])/parseFloat(this.A0['m']); for (k=0;k<tab.length-1;k++) { var xk= parseInt(tab[k].x*scal); var xk1=parseInt(tab[k+1].x*scal); var yk=parseInt(tab[k].y*scal); var yk1=parseInt(tab[k+1].y*scal); sommes = sommes + (xk1*yk-xk*yk1); } tab.pop(); sommes = sommes/2; surf = Math.abs(sommes); if (this.A9.A107()=="km") surf=(surf/1000000).toFixed(2); else surf= (Math.ceil(surf)); $(this.A27).update("Surface:"+surf+" "+this.A9.A107()+"2"); return surf; } }, A60:function(position,deplx,deply) { var dif_zoom=this.A4-position; this.A4=position; this.A61(); var centrex=parseFloat(this.box[0])+parseFloat(this.box[2]/2); var centrey=parseFloat(this.box[1])+parseFloat(this.box[3]/2); this.puis=Math.pow(this.A9.A20,this.A4-4); this.A6=this.A5/this.puis; var anc_rayon=this.A7;this.A7=this.A8/this.puis; this.A16.setAttribute("stroke-width",this.A6); var circles=$$('circle'); var stroke_w=(this.A6/this.puis); if(stroke_w>1)stroke_w=1; var size=this.A10/this.puis; for (var i=0;i<circles.length;i++) circles[i].setAttribute("r",this.A7); var Texts=$$('text'); for (var i=0;i<Texts.length;i++) { Texts[i].setAttribute("font-size",size); Texts[i].setAttribute("stroke-width",stroke_w); var posy=parseFloat(Texts[i].getAttribute("y"))+anc_rayon-this.A7;Texts[i].setAttribute("y",posy); } var width=parseFloat(this.A13/this.puis); var height=parseFloat(this.A14/this.puis); var left=parseFloat(centrex-width/2); var top=parseFloat(centrey-height/2); if (deplx!=0) { var viewx=((deplx)*this.box[2]/this.A13); viewx= viewx*Math.pow(this.A9.A20,dif_zoom); left=left-viewx ; } if (deply!=0) { var viewy=(deply*this.box[3]/this.A14); viewy=viewy* Math.pow(this.A9.A20,dif_zoom); top=top+viewy; } this.A62(left,top,width,height); }, A61:function() { this.box=new Array(); this.box=this.A15.getAttribute("viewBox"); this.box=this.box.split(' '); }, A62:function(left,top,width,height) { this.A15.setAttribute("viewBox",left+" "+top+" "+width+" "+height); this.A63(); }, A63:function() { var l= Position.positionedOffset($(this.A9.A54))[0]; var t = Position.positionedOffset($(this.A9.A54))[1]; var left=-l-(this.A13-this.A9.A24)/2; var top=-t-(this.A14-this.A9.A25)/2; $(this.A1).style.left=left+"px"; $(this.A1).style.top=top+"px"; }, A64: function(posPixel) { if (this.A23!="insertion"){ this.A65(this.A2,posPixel); if(this.A23=="line" || this.A23=="polygon") this.lastPos=this.A50(this.A24[parseInt(this.A24.length/2)-1]); $(this.A2).show(); $('labelname').focus(); } else{ $('insertDivForm').reset(); var hides=document.getElementsByClassName('hide', $('insertDivForm')); for (var i=0;i<hides.length;i++) hides[i].hide(); this.A65(this.A3,posPixel); $(this.A3).show(); } this.A41(); }, A65:function(Div,posPixel) { var l,t; if (posPixel.x >($(this.A9.A1).getWidth()-$(Div).getWidth())) l=posPixel.x-$(Div).getWidth(); else l=posPixel.x; if (posPixel.y>($(this.A9.A1).getHeight()-$(Div).getHeight())) t=posPixel.y-$(Div).getHeight(); else t=posPixel.y; $(Div).style.left=l+Position.page($(this.A9.A1))[0]+Position.realOffset($(this.A9.A1))[0]+"px"; $(Div).style.top=t+Position.page($(this.A9.A1))[1]+Position.realOffset($(this.A9.A1))[1]+"px"; }, A66:function(depl_x,depl_y){ this.A61(); var left=this.box[0]-depl_x*parseFloat(this.box[2])/this.A13;var top=this.box[1]-depl_y*parseFloat(this.box[3])/this.A14;this.A62(left,top,this.box[2],this.box[3]); this.A55(depl_x,depl_y); }, A67:function(array_pixel,point_pixel) { var ind=array_pixel.length; var intersection=0; if(ind>2) { if(point_pixel.x==array_pixel[ind-1].x) { a1=0;b1=0; vertical_1=true; } else { a1 = (point_pixel.y-array_pixel[ind-1].y) /( point_pixel.x-array_pixel[ind-1].x) ; b1 = point_pixel.y- point_pixel.x *(point_pixel.y-array_pixel[ind-1].y) /( point_pixel.x-array_pixel[ind-1].x) ; vertical_1=false; } for (k=1 ;k<ind-1; k++) { if( array_pixel[k].x==array_pixel[k-1].x) { a2=0;b2=0; vertical_2=true; } else { a2 = (array_pixel[k].y-array_pixel[k-1].y) /( array_pixel[k].x-array_pixel[k-1].x) ; b2 = array_pixel[k].y- array_pixel[k].x *(array_pixel[k].y-array_pixel[k-1].y) /( array_pixel[k].x-array_pixel[k-1].x); vertical_2=false; } if ((a1-a2)!=0 ) { if(vertical_1) { x= point_pixel.x; y= a2 * x + b2; } else if(vertical_2) { x= array_pixel[k].x; y= a1 * x + b1; } else { x= (b2-b1)/(a1-a2); y= a1 * x + b1; } var distp1p2=Math.sqrt((array_pixel[ind-1].x-point_pixel.x)*(array_pixel[ind-1].x-point_pixel.x)+(array_pixel[ind-1].y-point_pixel.y)*(array_pixel[ind-1].y-point_pixel.y)); var distp3p4=Math.sqrt((array_pixel[k-1].x-array_pixel[k].x)*(array_pixel[k-1].x-array_pixel[k].x)+(array_pixel[k-1].y-array_pixel[k].y)*(array_pixel[k-1].y-array_pixel[k].y)); var distpip1=Math.sqrt((point_pixel.x-x)*(point_pixel.x-x)+(point_pixel.y-y)*(point_pixel.y-y)); var distpip2=Math.sqrt((array_pixel[ind-1].x-x)*(array_pixel[ind-1].x-x)+(array_pixel[ind-1].y-y)*(array_pixel[ind-1].y-y)); var distpip3=Math.sqrt((array_pixel[k].x-x)*(array_pixel[k].x-x)+(array_pixel[k].y-y)*(array_pixel[k].y-y)); var distpip4=Math.sqrt((array_pixel[k-1].x-x)*(array_pixel[k-1].x-x)+(array_pixel[k-1].y-y)*(array_pixel[k-1].y-y)); if ( (distp1p2 > distpip1 )&&(distp1p2 > distpip2 )&&(distp3p4 > distpip3 )&&(distp3p4 > distpip4 ) ) intersection=1; } if (intersection==1) break; } } return intersection; }, A68: function(evt){ if (evt.keyCode==13 || Event.element(evt).id=='Oks'){ this.A38(this.lastPos,$('labelname').value); this.A42(); $(this.A2).hide(); $('labelname').clear(); this.A41(this.A23); } }, A69: function () { if(isValideSaisie()){ var form=$('insertDivForm').getElements(); var insertInfo= new Array(); for(var k=1;k<form.length-2;k++) { insertInfo[k]=form[k].value; } insertInfo.push('POINT('+this.A30[0]+' '+this.A30[1]+')'); var parametres= 'action=Insert&tabinfo='+insertInfo; var url = 'insert.php'; var myAjax = new Ajax.Request(url, { method: 'post', parameters: parametres }); $(this.A3).hide(); this.A41(this.A23); } } } 
