1 | /*=========================================== |
---|
2 | VARIABLES |
---|
3 | ============================================*/ |
---|
4 | |
---|
5 | // information sur la carte |
---|
6 | var imgLATmin = 0; // latmin d'origine |
---|
7 | var imgLATmax = 0; // latmax d'origine |
---|
8 | var imgLONmin = 0; // lonmin d'origine |
---|
9 | var imgLONmax = 0; // lonmax d'origine |
---|
10 | var imgHaut = 360; // hauteur de l'image |
---|
11 | var imgLarg = 720; // largeur de l'image |
---|
12 | var position = 1; // position de la souris (affichage) |
---|
13 | var resolution = 0.5; |
---|
14 | |
---|
15 | function clicDefault() { |
---|
16 | document.getElementById("calque_chargement").style.display = "inline"; |
---|
17 | document.getElementById("resizediv").style.display = "none"; |
---|
18 | } |
---|
19 | |
---|
20 | function onClicCarte(e) { |
---|
21 | var coeff =1/parseInt((imgHaut/(imgLATmax-imgLATmin))*resolution); |
---|
22 | document.getElementById("form_carte:clicX").value = parseInt( ( xCurseur(e) - findPosX(document.getElementById("form_carte:carte")) ) *coeff) / coeff; |
---|
23 | document.getElementById("form_carte:clicY").value = parseInt( ( yCurseur(e) - findPosY(document.getElementById("form_carte:carte")) ) *coeff) / coeff; |
---|
24 | |
---|
25 | document.getElementById("form_carte:centerLonClick").value = findLonN(document.getElementById("form_carte:clicX").value); |
---|
26 | document.getElementById("form_carte:centerLatClick").value = findLatN(document.getElementById("form_carte:clicY").value); |
---|
27 | document.getElementById("calque_chargement").style.display = "inline"; |
---|
28 | document.getElementById("resizediv").style.display = "none"; |
---|
29 | |
---|
30 | |
---|
31 | //alert("nouvelle position :: " + document.getElementById("form_carte:clicX").value + " " + document.getElementById("form_carte:clicY").value ); |
---|
32 | |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | // position x de la sourie |
---|
37 | function xCurseur(e) { |
---|
38 | if (document.all) return event.clientX + document.body.scrollLeft; |
---|
39 | else return e.pageX; |
---|
40 | } |
---|
41 | |
---|
42 | // position y de la sourie |
---|
43 | function yCurseur(e) { |
---|
44 | if (document.all) return event.clientY + document.body.scrollTop; |
---|
45 | else return e.pageY; |
---|
46 | } |
---|
47 | |
---|
48 | /*=============================== |
---|
49 | POSITION SOURIS |
---|
50 | ===============================*/ |
---|
51 | function montrerPositionSouris(e) { |
---|
52 | var div1 = document.getElementById("position1"); |
---|
53 | div1.style.visibility = "visible"; |
---|
54 | |
---|
55 | positionSouris(e); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | function cacherPositionSouris(e) { |
---|
61 | var div1 = document.getElementById("position1"); |
---|
62 | div1.style.visibility = "hidden"; |
---|
63 | var div2 = document.getElementById("loupe"); |
---|
64 | div2.style.visibility = "hidden"; |
---|
65 | } |
---|
66 | |
---|
67 | function positionSouris(e) { |
---|
68 | var posX = xCurseur(e); |
---|
69 | var posY = yCurseur(e); |
---|
70 | //var coeff =1/parseInt((imgHaut/(imgLATmax-imgLATmin))*resolution); |
---|
71 | |
---|
72 | |
---|
73 | //var posXimg = parseInt( ( xCurseur(e) - findPosX(document.getElementById("form_carte:carte")) ) *coeff) / coeff; |
---|
74 | //var posYimg = parseInt( ( yCurseur(e) - findPosY(document.getElementById("form_carte:carte")) ) *coeff) / coeff; |
---|
75 | |
---|
76 | var posXimg = posX - findPosX(document.getElementById("form_carte:carte")); |
---|
77 | var posYimg = posY - findPosY(document.getElementById("form_carte:carte")); |
---|
78 | var div1 = document.getElementById("position1"); |
---|
79 | //div.style.left = (posX + 10) + "px"; |
---|
80 | //div.style.top = (posY + 5) + "px"; |
---|
81 | div1.innerHTML = "<div class='latitude'>  latitude : " + findLatN(posYimg) + "</div><div class='longitude'>  longitude : " + findLonN(posXimg) + "</div>"; |
---|
82 | //div1.innerHTML = "<div class='latitude'>  latitude : " + posYimg +"</div><div class='longitude'>  longitude : " + posXimg + "</div>"; |
---|
83 | |
---|
84 | positionLoupe(posX, posY); |
---|
85 | } |
---|
86 | |
---|
87 | function positionLoupe(posX, posY) { |
---|
88 | document.getElementById("loupe").style.top = posY+20; |
---|
89 | document.getElementById("loupe").style.left = posX; |
---|
90 | } |
---|
91 | |
---|
92 | function deplacerPositionSouris(e) { |
---|
93 | var div1 = document.getElementById("position1"); |
---|
94 | if (position == 1) { |
---|
95 | div1.style.bottom = "auto;"; |
---|
96 | div1.style.top = "-5px;"; |
---|
97 | position = 0; |
---|
98 | } |
---|
99 | else { |
---|
100 | div1.style.bottom = "-5px;"; |
---|
101 | div1.style.top = "auto;"; |
---|
102 | position = 1; |
---|
103 | } |
---|
104 | positionSouris(e); |
---|
105 | } |
---|
106 | |
---|
107 | /*====================== |
---|
108 | INITIALISATION |
---|
109 | ======================*/ |
---|
110 | function initCoordonneeCarte() { |
---|
111 | imgLATmax = document.getElementById("form_carte:latitude_max").value; |
---|
112 | imgLATmin = document.getElementById("form_carte:latitude_min").value; |
---|
113 | imgLONmax = document.getElementById("form_carte:longitude_max").value; |
---|
114 | imgLONmin = document.getElementById("form_carte:longitude_min").value; |
---|
115 | //imgHaut = parseInt( 360/ (imgLATmax-imgLATmin))*(imgLATmax-imgLATmin); |
---|
116 | //imgLarg = parseInt( 720/ (imgLONmax-imgLONmin))*(imgLONmax-imgLONmin); |
---|
117 | resolution = document.getElementById("form_carte:resolution").value; |
---|
118 | |
---|
119 | if (imgLATmax == null || imgLATmin == null || imgLONmax == null || imgLONmin == null) |
---|
120 | alert("erreur d'initialisation des coordonnees"); |
---|
121 | } |
---|
122 | |
---|
123 | /*======================= |
---|
124 | LOCALISATION DES OBJETS |
---|
125 | =======================*/ |
---|
126 | // POSITION X D'UN OBJET |
---|
127 | function findPosX(obj) |
---|
128 | { |
---|
129 | if(obj!=null){ |
---|
130 | var curleft = 0; |
---|
131 | if (obj.offsetParent){ |
---|
132 | while (obj.offsetParent){ |
---|
133 | curleft += obj.offsetLeft; |
---|
134 | obj = obj.offsetParent; |
---|
135 | } |
---|
136 | } |
---|
137 | else |
---|
138 | if (obj.x){ |
---|
139 | curleft += obj.x; } |
---|
140 | return curleft; |
---|
141 | } |
---|
142 | return 0; |
---|
143 | } |
---|
144 | |
---|
145 | // POSITION Y D'UN OBJET |
---|
146 | function findPosY(obj) { |
---|
147 | if(obj!=null) { |
---|
148 | var curtop = 0; |
---|
149 | if (obj.offsetParent){ |
---|
150 | while (obj.offsetParent) { |
---|
151 | curtop += obj.offsetTop; |
---|
152 | obj = obj.offsetParent; |
---|
153 | } |
---|
154 | } |
---|
155 | else if (obj.y) { |
---|
156 | curtop += obj.y; } |
---|
157 | return curtop; |
---|
158 | } |
---|
159 | return 0; |
---|
160 | } |
---|
161 | |
---|
162 | /*================================================= |
---|
163 | CONVERSION pixel -> LAT/LON |
---|
164 | ==================================================*/ |
---|
165 | |
---|
166 | //converti de pixel ? Lat bloque a -90 90 |
---|
167 | function findLatN(lat) { |
---|
168 | var coef = (imgLATmax-imgLATmin)/imgHaut; |
---|
169 | var lati = (imgHaut-lat)*coef - (-imgLATmin); |
---|
170 | if (lati>90) |
---|
171 | return 90; |
---|
172 | if (lati<-90) |
---|
173 | return -90 |
---|
174 | return Math.round(lati*100)/100; |
---|
175 | } |
---|
176 | |
---|
177 | //converti de pixel ? Lon bloque a -180 180 |
---|
178 | function findLonN(lon){ |
---|
179 | coef = (imgLONmax - imgLONmin)/imgLarg; |
---|
180 | longitude = lon*coef - (-imgLONmin); |
---|
181 | if (longitude>180) |
---|
182 | return 180; |
---|
183 | if (longitude <-180) |
---|
184 | return -180; |
---|
185 | return Math.round(longitude*100)/100; |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | //converti de pixel ? Lat |
---|
190 | function findLat(lat) { |
---|
191 | var coef = (imgLATmax-imgLATmin)/imgHaut; |
---|
192 | var lati = (imgHaut-lat)*coef - (-imgLATmin); |
---|
193 | return Math.round(lati*100)/100; |
---|
194 | } |
---|
195 | |
---|
196 | //converti de pixel ? Lon |
---|
197 | function findLon(lon){ |
---|
198 | coef = (imgLONmax - imgLONmin)/imgLarg; |
---|
199 | longitude = lon*coef - (-imgLONmin); |
---|
200 | return Math.round(longitude*100)/100; |
---|
201 | } |
---|
202 | |
---|
203 | /*================================================= |
---|
204 | CONVERSION lAT/LON -> pixel |
---|
205 | ==================================================*/ |
---|
206 | function findX(lon) { |
---|
207 | pixelX = (lon - imgLONmin)/(imgLONmax-imgLONmin)*imgLarg; |
---|
208 | return Math.round(pixelX); |
---|
209 | } |
---|
210 | |
---|
211 | function findY(lat) { |
---|
212 | pixelY = (imgLATmax-lat)/(imgLATmax-imgLATmin)*imgHaut; |
---|
213 | return Math.round(pixelY); |
---|
214 | } |
---|