/************************************************************************** ** Projet : OPAC ** Nom du fichier : vectorLayer.js ** Créé le : 20/06/06 Par : GSR ** Contenu : Fichier des fonctionnalités de gestion des actions lors d'une selection sur la carte ** ** ** Modifications : ** numéro :1 auteur :LAZA date :19/07/2006 objet :äjout de l'outil de mésure ** ** ***************************************************************************/ function CreateVectorLayer(id) { this.vLayer = new jsGraphics(id); this.startCircle = vectorLayer_startCircle; this.initPoly = vectorLayer_initPoly; this.growCircle = vectorLayer_growCircle; this.stopCircle = vectorLayer_stopCircle; this.growPoly = vectorLayer_growPoly; this.growPolyTemp = vectorLayer_growPolyTemp; this.stopPoly = vectorLayer_stopPoly; this.stopDot = vectorLayer_stopDot; this.pix2Geo = vectorLayer_Pix2Geo; this.calculateRadius = vectorLayer_calculateRadius; this.clear = vectorLayer_clear; /**** Modif 1 de laza */ this.initMesure = vectorLayer_initMesure; this.displayMeasure = vectorLayer_displayMeasure; this.showMeasure = vectorLayer_showMeasure; /* Fin de modif de Laza */ this.vLayer.setColor("#355F0B"); this.vLayer.setStroke(2); this.x0 = 0; this.y0 = 0; this.xCoords = new Array(); this.yCoords = new Array(); } function vectorLayer_startCircle(e) { this.clear(); this.x0 = e.x; this.y0 = e.y; this.vLayer.drawEllipse(this.x0+deltax, this.y0+deltay, 1, 1); this.vLayer.paint(); } function vectorLayer_growCircle(e,wPix,hPix,extent) { this.clear(); w = Math.abs(this.x0 - e.x); h = Math.abs(this.y0 - e.y); Incr = (w > h)? w : h; //transformation des coordonnées du centre // calcul de l'angle entre P(x0,y0) et S(e.x,e.y) radius = this.calculateRadius(Incr,e) this.vLayer.drawEllipse(this.x0-Math.abs(radius)+deltax, this.y0-Math.abs(radius)+deltay, radius*2, radius*2); this.vLayer.paint(); this.vLayer.setColor("#F0E9CE"); this.vLayer.fillRect(e.x+7+deltax,e.y-17+deltay, 110,16); this.vLayer.paint(); this.vLayer.setColor("#3D3413"); this.vLayer.setStroke(1); this.vLayer.drawRect(e.x+6+deltax,e.y-18+deltay, 111,17); this.vLayer.setStroke(2); // calcul de l'étendue var coords = extent.split('+'); var valPix = (coords[2] - coords[0])/wPix; this.valGeo = Math.abs(valPix * Incr/1000); this.valGeo = (this.valGeo > 10) ? Math.round(this.valGeo) : Math.round(this.valGeo * 10) / 10; //this.vLayer.drawString("Rayon : " + this.valGeo + " km.",this.x0 + 3,this.y0-2); this.vLayer.drawString("Rayon : " + this.valGeo + " km.",e.x + 10+deltax ,e.y-17+deltay); this.vLayer.paint(); this.vLayer.setColor("#355F0B"); } function vectorLayer_calculateRadius(Incr, e) { dAdj = (e.x - this.x0); dOpp = -(e.y - this.y0); tanAngle = dOpp/dAdj; cotanAngle = 1 / tanAngle; coef = 0 ; Angle = Math.atan(tanAngle); if ((e.x this.y0)) { Angle = Angle + Math.PI; } else if (e.x>=this.x0 && e.y > this.y0) { Angle = Angle + 2*Math.PI; } if (Angle < Math.PI / 4 || Angle >= 7 * Math.PI / 4) coef = Math.tan(Angle); else if (Angle >= Math.PI/4 && Angle < 3*Math.PI/4) coef = 1/Math.tan(Angle); else if (Angle >= 3*Math.PI/4 && Angle < 5 * Math.PI / 4) coef = Math.tan(Angle); else if (Angle >= 5 * Math.PI / 4 && Angle < 7 * Math.PI / 4) coef = 1/Math.tan(Angle); Incr = Incr * Math.SQRT2 - ((1-Math.abs(coef)) * (Incr * Math.SQRT2 - Incr)); return Incr; } function vectorLayer_stopCircle(e,wPix,hPix,extent) { aXGeoCoords = this.pix2Geo(this.x0,wPix, hPix, extent, false); aYGeoCoords = this.pix2Geo(this.y0,wPix, hPix, extent, true); aBBoxL = aXGeoCoords -1000 - this.valGeo*1000 ; aBBoxR = aXGeoCoords + 1000 + this.valGeo*1000 ; aBBoxT = aYGeoCoords + 1000 + this.valGeo*1000 ; aBBoxB = aYGeoCoords -1000 - this.valGeo*1000 ; //alert(aBBoxL +" "+ aBBoxR +" "+ aBBoxT +" "+ aBBoxB+" "+this.valGeo*1000); if (niveauEtude == 'communes')strSQLSel = " the_geom_gisui separateurjs setSRID('BOX3D("+ aBBoxL + " " + aBBoxB + "," + aBBoxR + " " + aBBoxT + ")'::box3d,27582) AND DISTANCE(centroid(the_geom_gisui),GeomFromText('POINT("+aXGeoCoords +" "+aYGeoCoords+")',27582)) <= " + this.valGeo*1000 ; if (niveauEtude == 'iris')strSQLSel = " the_geom separateurjs setSRID('BOX3D("+ aBBoxL + " " + aBBoxB + "," + aBBoxR + " " + aBBoxT + ")'::box3d,27582) AND DISTANCE(centroid(the_geom),GeomFromText('POINT("+aXGeoCoords +" "+aYGeoCoords+")',27582)) <= " + this.valGeo*1000 ; paneCarte(); this.clear(); } function vectorLayer_stopDot(wPix,hPix,extent){ aXGeoCoords = this.pix2Geo(this.x0,wPix, hPix, extent, false); aYGeoCoords = this.pix2Geo(this.y0,wPix, hPix, extent, true); if (niveauEtude == 'communes')strSQLSel = " WITHIN(GeomFromText('POINT("+aXGeoCoords +" "+ aYGeoCoords +")',27582),the_geom_gisui)" ; if (niveauEtude == 'iris')strSQLSel = " WITHIN(GeomFromText('POINT("+aXGeoCoords +" "+ aYGeoCoords +")',27582),the_geom)" ; paneCarte(); this.clear(); } function vectorLayer_initPoly() { this.clear(); this.xCoords = new Array(); this.yCoords = new Array(); } function vectorLayer_growPoly(e) { this.clear(); this.xCoords.push(e.x+deltax); this.yCoords.push(e.y+deltay); this.vLayer.drawPolyline(this.xCoords,this.yCoords); this.vLayer.paint(); } function vectorLayer_initMesure(e){ this.clear(); deltax1 = parseInt(visualisationDiv.offsetLeft) ; deltay1 = parseInt(visualisationDiv.offsetTop) ; this.xCoords.push(e.x+deltax1); this.yCoords.push(e.y+deltay1); //this.vLayer.drawPolyline(this.xCoords,this.yCoords); this.vLayer.drawPoint(e.x+deltax1,e.y+deltay1); this.vLayer.setStroke(2); this.vLayer.paint(); } function vectorLayer_growPolyTemp(e) { this.clear(); this.vLayer.drawPolyline(this.xCoords,this.yCoords); this.vLayer.paint(); //this.vLayer.drawLine(this.xCoords[this.xCoords.length-1],this.yCoords[this.yCoords.length-1],e.x,e.y); //this.vLayer.paint(); } function vectorLayer_stopPoly(e,pixW, pixH, extent) { // fermeture du polygone if (e.x+deltax != this.xCoords[0] || e.y+deltay != this.yCoords[0]) { this.xCoords.push(this.xCoords[0]); this.yCoords.push(this.yCoords[0]); } this.vLayer.drawPolyline(this.xCoords,this.yCoords); this.vLayer.paint(); // Correction des coordonnées for (i=0;i 1) { Xprev = axCoords[i-1]; Yprev = ayCoords[i-1]; Xfin = axCoords[i]; Yfin = ayCoords[i]; XGeoPrev = this.pix2Geo(Xprev,carteW, carteH, extent, false); YGeoPrev = this.pix2Geo(Yprev,carteW, carteH, extent, true); XGeofin = this.pix2Geo(Xfin,carteW, carteH, extent, false); YGeofin = this.pix2Geo(Yfin,carteW, carteH, extent, true); distance_x = Xfin-Xprev; distance_y = Yfin-Yprev; distanceGeo_x = XGeofin - XGeoPrev; distanceGeo_y = YGeofin - YGeoPrev; distanceGeo = Math.sqrt((Math.pow(distanceGeo_x, 2)) + (Math.pow(distanceGeo_y, 2))); } var cntSegLen = Math.round(distanceGeo).toString().length; numSize = Math.max(0, (4 - cntSegLen)); var segLenGEO = roundN(distanceGeo, numSize); if (segLenGEO > 1000) { segLenGEO = roundN(segLenGEO/1000,1); calcUnit2 = " km"; } else { segLenGEO = roundN(segLenGEO,0); calcUnit2 = " m"; } xM = Xprev+distance_x/2; yM = Yprev+distance_y/2; this.vLayer.setColor("#3D3413"); this.vLayer.setStroke(2); this.vLayer.fillRect(xM-30, yM-6, 60, 12); this.vLayer.setColor("#FFFFFF"); this.vLayer.setFont("arial","9px",Font.BOLD); this.vLayer.drawStringRect(segLenGEO+calcUnit2, xM-30 , yM-5 , 60, 'center'); } } // // Round to a specified decimal // function roundN(numin, rf) { return ( Math.round(numin * Math.pow(10, rf)) / Math.pow(10, rf) ); } /* Fin de modif 1 de laza */ function print_r(aArray) { var str=''; var tabul = '\t'; if(typeof(aArray)=='object') { for(i=0;i