Révision 7f9aab46
Ajouté par Victor Pongnian il y a plus de 11 ans
js/pano.js | ||
---|---|---|
1 |
if (img_prefix == undefined) var img_prefix = './tiles/ttn_mediatheque/mediatheque_70';
|
|
1 |
if (img_prefix == undefined) var img_prefix = 'http://pano.tetaneutral.net/data/tsf2/vpongnian/tiles/ttn_mediatheque/mediatheque_70';
|
|
2 | 2 |
if (to_cap == undefined) var to_cap = 0; |
3 | 3 |
if (to_ele == undefined) var to_ele = 0; |
4 | 4 |
if (to_zoom == undefined) var to_zoom = 0; |
... | ... | |
8 | 8 |
if (ref_points == undefined) var ref_points = new Array(); |
9 | 9 |
if (image_loop == undefined) var image_loop = true; |
10 | 10 |
|
11 |
|
|
11 | 12 |
var debug_mode = false; |
12 | 13 |
var canvas; |
13 | 14 |
var cntext; |
... | ... | |
31 | 32 |
var point_colors = {'pano_point' : '255,128,128', |
32 | 33 |
'ref_point' : '128,128,255', |
33 | 34 |
'loc_point' : '128,255,128', |
35 |
'temporary' : '255,255,128', |
|
34 | 36 |
'unlocated' : '255,255,255'}; |
35 | 37 |
var test = {x:0, y:0, i:100}; |
36 | 38 |
|
39 |
|
|
37 | 40 |
function nmodulo(val, div) { // pour obtenir un modulo dans l'espace des nombres naturels N. |
38 | 41 |
return Math.floor((val%div+div)%div); // il y a peut être plus simple, mais en attendant .... |
39 | 42 |
} |
... | ... | |
165 | 168 |
if (twidth) { |
166 | 169 |
cntext.restore(); |
167 | 170 |
} |
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
function insert_drawn_point(lat,lon,alt) { |
|
175 |
|
|
176 |
var rt = 6371; // Rayon de la terre |
|
177 |
var alt1 = document.getElementById('pos_alt').childNodes[0].nodeValue; |
|
178 |
var lat1 = document.getElementById('pos_lat').childNodes[0].nodeValue*Math.PI/180; |
|
179 |
var lon1 = document.getElementById('pos_lon').childNodes[0].nodeValue*Math.PI/180; |
|
180 |
var alt2 = alt; |
|
181 |
var lat2 = lat*Math.PI/180; |
|
182 |
var lon2 = lon*Math.PI/180; |
|
183 |
|
|
184 |
var dLat = lat2-lat1; |
|
185 |
var dLon = lon2-lon1; |
|
186 |
|
|
187 |
var a = Math.sin(dLat/2)*Math.sin(dLat/2) + Math.sin(dLon/2)*Math.sin(dLon/2)*Math.cos(lat1)*Math.cos(lat2); // |
|
188 |
var angle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); |
|
189 |
var d = angle*rt; // distance du point en Kms |
|
190 |
|
|
191 |
var y = Math.sin(dLon) * Math.cos(lat2); |
|
192 |
var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon); |
|
193 |
var cap = Math.atan2(y,x); // cap pour atteindre le point en radians |
|
194 |
var e = Math.atan2((alt2 - alt1)/1000 - d*d/(2*rt),d); // angle de l'élévation en radians |
|
195 |
|
|
196 |
return {d:d, cap:cap*180/Math.PI, ele:e*180/Math.PI}; // les résultats sont en degrés |
|
197 |
} |
|
198 |
|
|
199 |
localate_point = function () { |
|
200 |
|
|
201 |
var lat = document.getElementById("loca_latitude").value; |
|
202 |
var lon = document.getElementById("loca_longitude").value; |
|
203 |
var alt = document.getElementById("loca_altitude").value; |
|
204 |
if (lat == '' || isNaN(lat) || lat <= -90 || lat > 90) { |
|
205 |
alert("La latitude "+lat+"n'est pas correcte"); |
|
206 |
return; |
|
207 |
} |
|
208 |
if (lat == '' || isNaN(lon) || lon <= -180 || lon > 180) { |
|
209 |
alert("La longitude "+lon+"n'est pas correcte"); |
|
210 |
return; |
|
211 |
} |
|
212 |
if (lat == '' || isNaN(alt) || alt < -400) { |
|
213 |
alert("l'altitude "+alt+"n'est pas correcte"); |
|
214 |
return; |
|
215 |
} |
|
216 |
var opt_ced = new Array(); |
|
217 |
opt_dce = insert_drawn_point(lat,lon,alt); |
|
218 |
// -----Première solution : afficher dynamiquement le point ! |
|
219 |
var d = opt_dce.d; |
|
220 |
var cap = opt_dce.cap; |
|
221 |
var ele = opt_dce.ele; |
|
222 |
|
|
223 |
display_temp(d, cap, ele); |
|
224 |
|
|
225 |
} |
|
226 |
|
|
227 |
function display_temp(d,cap,ele) { |
|
228 |
|
|
229 |
point_list[point_list.length] = new Array("point temporaire", d,cap,ele, "temporary"); |
|
230 |
reset_zooms(); |
|
231 |
putImage(last.x, last.y); |
|
232 |
} |
|
233 |
|
|
234 |
function arrayUnset(array, value){ |
|
235 |
array.splice(array.indexOf(value), 1); |
|
236 |
} |
|
237 |
|
|
238 |
erase_point = function() { |
|
239 |
|
|
240 |
for (var i=0; i<point_list.length; i++) { |
|
241 |
if(point_list[i][0] == "point temporaire"){ |
|
242 |
arrayUnset(point_list,point_list[i]); |
|
243 |
loop = erase_point(); |
|
244 |
} |
|
245 |
} |
|
246 |
reset_zooms(); |
|
247 |
putImage(last.x, last.y); |
|
168 | 248 |
} |
169 | 249 |
|
170 | 250 |
function get_file_name(x, y, z) { // recherche du fichier correspondant au zoom et à la position |
... | ... | |
181 | 261 |
} |
182 | 262 |
|
183 | 263 |
function keys(key) { |
264 |
|
|
184 | 265 |
hide_links(); |
185 | 266 |
evt = key || event; |
186 |
evt.preventDefault(); |
|
187 |
evt.stopPropagation(); |
|
267 |
//evt.preventDefault();
|
|
268 |
//evt.stopPropagation();
|
|
188 | 269 |
if (!key) { |
189 | 270 |
key = window.event; |
190 | 271 |
key.which = key.keyCode; |
... | ... | |
192 | 273 |
// alert(key); |
193 | 274 |
// if (!evt.shiftKey) return; |
194 | 275 |
switch (key.which) { |
195 |
case 66: // b |
|
276 |
/*case 66: // b
|
|
196 | 277 |
alert(key.pageX); |
197 | 278 |
test.x=tile.width*(ntiles.x-3); |
198 | 279 |
test.y=0; |
... | ... | |
202 | 283 |
test.x=0; |
203 | 284 |
test.y=tile.height*(ntiles.y-3); |
204 | 285 |
putImage(test.x, test.y); |
205 |
return; |
|
286 |
return;*/
|
|
206 | 287 |
case 36: // home |
207 | 288 |
putImage(0, zm.im.height/2); |
208 | 289 |
return; |
... | ... | |
440 | 521 |
if (ref_points[lbl] != undefined) { |
441 | 522 |
typ = 'ref_point'; |
442 | 523 |
if (!is_located) rxy = {x:ref_points[lbl].x*this.im.width, y:ref_points[lbl].y*this.im.height} |
443 |
} else if(lnk == '' && is_visible) { |
|
524 |
} else if(lnk == '' && is_visible && lbl != 'point temporaire') {
|
|
444 | 525 |
typ = 'loc_point'; |
526 |
}else if(is_visible && lbl =='point temporaire') { |
|
527 |
typ = 'temporary'; |
|
528 |
|
|
445 | 529 |
} else if(is_visible) { |
446 | 530 |
typ = 'pano_point'; |
447 | 531 |
lnk += '&to_zoom='+this.value; |
448 |
} |
|
532 |
}
|
|
449 | 533 |
this.pt_list[i]['type'] = typ; |
450 | 534 |
this.pt_list[i]['cap'] = cap; |
451 | 535 |
this.pt_list[i]['ele'] = ele; |
... | ... | |
700 | 784 |
speed.y = 0; |
701 | 785 |
} |
702 | 786 |
|
787 |
|
|
788 |
|
|
703 | 789 |
canvas_set_size = function() { |
704 | 790 |
canvas.style.border = border_width+"px solid red"; |
705 | 791 |
canvas.width = window.innerWidth-2*border_width; |
... | ... | |
713 | 799 |
putImage(last.x, last.y); |
714 | 800 |
} |
715 | 801 |
|
802 |
|
|
803 |
|
|
804 |
function paramIn(e) { |
|
805 |
|
|
806 |
e = e || window.event; |
|
807 |
var relatedTarget = e.relatedTarget || e.fromElement; |
|
808 |
|
|
809 |
while (relatedTarget != adding && relatedTarget.nodeName != 'BODY' && relatedTarget != document && relatedTarget != localisation) { |
|
810 |
relatedTarget = relatedTarget.parentNode; |
|
811 |
} |
|
812 |
|
|
813 |
if (relatedTarget != adding && relatedTarget != localisation) { |
|
814 |
document.removeEventListener('keydown', keys, false); |
|
815 |
} |
|
816 |
} |
|
817 |
|
|
818 |
function paramOut(e) { |
|
819 |
|
|
820 |
e = e || window.event; |
|
821 |
var relatedTarget = e.relatedTarget || e.toElement; |
|
822 |
|
|
823 |
while (relatedTarget != adding && relatedTarget.nodeName != 'BODY' && relatedTarget != document && relatedTarget != localisation) { |
|
824 |
relatedTarget = relatedTarget.parentNode; |
|
825 |
} |
|
826 |
|
|
827 |
if (relatedTarget != adding && relatedTarget != localisation) { |
|
828 |
document.addEventListener('keydown', keys, false); |
|
829 |
} |
|
830 |
|
|
831 |
} |
|
832 |
|
|
716 | 833 |
window.onload = function() { |
834 |
|
|
835 |
localisation = document.getElementById("locadraw"); |
|
836 |
adding = document.getElementById("adding"); |
|
717 | 837 |
canvas = document.getElementById("mon-canvas"); |
718 | 838 |
cntext = canvas.getContext("2d"); |
719 | 839 |
canvas_set_size(); |
... | ... | |
746 | 866 |
elvtn_control.onclick = change_angle; |
747 | 867 |
|
748 | 868 |
change_angle(); |
749 |
|
|
869 |
loca_temp = document.getElementById("loca_button"); |
|
870 |
loca_temp.onclick = localate_point; |
|
871 |
loca_erase = document.getElementById("loca_erase"); |
|
872 |
loca_erase.onclick = erase_point; |
|
750 | 873 |
canvas.addEventListener('mousedown', onImageClick, false); |
751 |
addEventListener('keydown', keys, false); |
|
874 |
document.addEventListener('keydown', keys, false);
|
|
752 | 875 |
canvas.addEventListener('mousewheel', wheel_zoom, false); |
753 | 876 |
window.onresize = canvas_resize; |
877 |
adding.addEventListener('mouseover',paramIn,false); |
|
878 |
adding.addEventListener('mouseout',paramOut,false); |
|
879 |
localisation.addEventListener('mouseover',paramIn,false); |
|
880 |
localisation.addEventListener('mouseout',paramOut,false); |
|
881 |
|
|
754 | 882 |
}; |
Formats disponibles : Unified diff
Version réaliée pour la sage de Victor Pongnian