Changeset 12126 for extensions/edit_gmaps/admin/js/JScript.js
- Timestamp:
- Sep 10, 2011, 5:02:19 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/edit_gmaps/admin/js/JScript.js
r10060 r12126 8 8 9 9 function onLoad() { 10 11 12 13 14 15 16 17 18 if (coordinates.LAT <= 90 && coordinates.LAT != " " && coordinates.LAT != "") {19 20 21 coordinates.LAT=49 ;coordinates.LON = 3;22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 10 var reg = new RegExp('/', "g"); 11 12 if (coordinates.ADRESSE) 13 coordinates.ADRESSE = coordinates.ADRESSE.replace("/", ", "); 14 15 document.getElementById("match").value = coordinates.ADRESSE; 16 geocoder = new google.maps.Geocoder(); 17 var mapElement = document.getElementById("map"); 18 if (coordinates.LAT <= 90 && coordinates.LAT != " " && coordinates.LAT != "") { 19 20 } else { 21 coordinates.LAT = 49; coordinates.LON = 3; 22 coordinates.ZOOM = coordinates.ZOOM | 18; 23 geocoder.geocode({ 'address': coordinates.ADRESSE }, function (results, status) { 24 /* Si l'adresse a pu être géolocalisée */ 25 if (status == google.maps.GeocoderStatus.OK) { 26 /* Récupération de sa latitude et de sa longitude */ 27 coordinates.LAT = results[0].geometry.location.lat(); 28 coordinates.LON = results[0].geometry.location.lng(); 29 LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON); 30 updateMarkerPosition(LatLng); 31 geocodePosition(LatLng); 32 } 33 }); 34 35 36 } 37 37 zoom = coordinates.ZOOM; 38 39 40 41 42 43 44 45 46 47 var mapOpts = {48 center:LatLng,49 zoom:zoom,50 mapTypeId: google.maps.MapTypeId.SATELLITE 51 52 53 map = new google.maps.Map( mapElement, mapOpts);54 55 56 57 58 if (coordinates)59 marker = new google.maps.Marker( { 60 61 62 draggable: true63 64 65 66 67 38 LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON); 39 40 41 /* 42 MapTypeId.ROADMAP affiche un plan (de type carte routière). 43 MapTypeId.SATELLITE affiche une vue satellite. 44 MapTypeId.HYBRID affiche une vue mixte entre les deux précédentes. 45 MapTypeId.TERRAIN affiche une vue du relief. 46 */ 47 var mapOpts = { 48 center: LatLng, 49 zoom: zoom, 50 mapTypeId: google.maps.MapTypeId.SATELLITE 51 }; 52 53 map = new google.maps.Map(mapElement, mapOpts); 54 55 56 57 58 if (coordinates) 59 marker = new google.maps.Marker({ 60 position: map.getCenter(), 61 map: map, 62 draggable: true 63 }); 64 65 66 // Add dragging event listeners. 67 google.maps.event.addListener(marker, 68 68 'dragstart', 69 69 function () { 70 70 updateMarkerAddress('Dragging...'); 71 71 }); 72 72 73 73 google.maps.event.addListener(marker, 74 74 'drag', 75 75 function () { 76 77 76 updateMarkerStatus('Dragging...'); 77 updateMarkerPosition(marker.getPosition()); 78 78 } 79 79 ); 80 80 81 81 google.maps.event.addListener(marker, 82 82 'dragend', 83 83 function () { 84 84 85 86 85 86 87 87 // getElevation({ latLng: marker.getPosition() }); 88 89 90 91 88 geocodePosition(marker.getPosition()); 89 updateMarkerStatus('Drag ended'); 90 getElevation({ 'latLng': marker.getPosition() }); 91 92 92 93 93 } 94 94 ); 95 95 96 // styleIcon = new StyledIcon(StyledIconTypes.BUBBLE, { color: "#cccccc", text: "Drag Me!" }); 97 // var styleMaker1 = new StyledMarker({ styleIcon: styleIcon, position: new google.maps.LatLng(37.383477473067, -121.880502070713), map: map, draggable: true }); 98 99 // google.maps.event.addDomListener(styleMaker1, "dragend", getElevation); 100 // Update current position info. 101 102 updateMarkerPosition(LatLng); 103 geocodePosition(LatLng); 104 getElevation({ 'latLng': marker.getPosition() }); 105 106 return false; 107 108 109 110 111 112 } 113 114 function updateMarkerStatus(str) { 115 document.getElementById('markerStatus').innerHTML = str; 116 } 117 118 function updateMarkerPosition(latLng) { 119 document.Envoie.lat.value=latLng.lat() ; 120 document.Envoie.lon.value = latLng.lng(); 121 dms_frac = dec2dms(latLng.lng()); 122 if (document.Envoie.lon.value < 0) 123 document.Envoie.lonRef.value = "W"; 124 else 125 document.Envoie.lonRef.value = "E"; 126 document.Envoie.lonDMS.value = Math.abs(dms_frac.Degre) +"/1" + " " + dms_frac.Minute +"/1" + " " + dms_frac.Numerator + "/" + dms_frac.Denominator; 127 dms_frac = dec2dms(latLng.lat()); 128 if (document.Envoie.lat.value < 0) 129 document.Envoie.latRef.value = "S"; 130 else 131 document.Envoie.latRef.value = "N"; 132 document.Envoie.latDMS.value = Math.abs(dms_frac.Degre) + "/1" + " " + dms_frac.Minute + "/1" + " " + dms_frac.Numerator + "/" + dms_frac.Denominator; 133 // update_datas(); 134 } 135 136 137 function update_datas() { 138 n= jQuery(document.EditJPEG); 139 140 jQuery.each(n[0], function (i) { 141 142 143 n00 = this; 144 n0 = n00.id; 145 n1 = n00.name; 146 n2 = jQuery(n00).val(); 147 try { 148 if (n0 == "alt") { 149 n3 = dec2frac(document.Envoie[n0].value); 150 n3 = n3.Numerator + "/" + n3.Denominator; 151 jQuery(this).val(n3); 152 } 153 else { 154 n3 = document.Envoie[n0].value; 155 jQuery(this).val(n3); 156 } 157 } 158 catch (e) { 159 n3 = n0; 160 } 161 162 163 164 } 165 ) 166 167 168 169 } 170 171 function updateMarkerAddress(str) { 172 document.getElementById('markerAdress').innerHTML = str; 173 174 jQuery("#match").val(str); 175 } 176 177 function getElevation(event) { 178 var elevator = new google.maps.ElevationService(); 179 var locations = []; 180 181 // Retrieve the clicked location and push it on the array 182 var clickedLocation = event.latLng; 183 locations.push(clickedLocation); 184 185 // Create a LocationElevationRequest object using the array's one value 186 var positionalRequest = { 187 'locations': locations 188 } 189 190 // Initiate the location request 191 if (elevator) { 192 elevator.getElevationForLocations(positionalRequest, function (results, status) { 193 if (status == google.maps.ElevationStatus.OK) { 194 195 // Retrieve the first result 196 if (results[0]) { 197 coordinates.ALT = results[0].elevation; 198 document.Envoie.alt.value = coordinates.ALT; 199 altDMS = dec2frac(coordinates.ALT); 200 document.Envoie.altRef.value = "0"; 201 document.Envoie.altDMS.value = altDMS.Numerator + "/" + altDMS.Denominator; 202 //styleIcon.set("text", "Elevation: " + results[0].elevation + "m"); 203 } else { 204 // alert("No results found"); 205 } 206 } else { 207 alert("Elevation service failed due to: " + status); 208 } 96 // styleIcon = new StyledIcon(StyledIconTypes.BUBBLE, { color: "#cccccc", text: "Drag Me!" }); 97 // var styleMaker1 = new StyledMarker({ styleIcon: styleIcon, position: new google.maps.LatLng(37.383477473067, -121.880502070713), map: map, draggable: true }); 98 99 // google.maps.event.addDomListener(styleMaker1, "dragend", getElevation); 100 // Update current position info. 101 102 updateMarkerPosition(LatLng); 103 geocodePosition(LatLng); 104 getElevation({ 'latLng': marker.getPosition() }); 105 106 return false; 107 108 109 110 111 112 } 113 114 function updateMarkerStatus(str) { 115 document.getElementById('markerStatus').innerHTML = str; 116 } 117 118 function updateMarkerPosition(latLng) { 119 document.Envoie.lat.value = latLng.lat(); 120 document.Envoie.lon.value = latLng.lng(); 121 dms_frac = dec2dms(latLng.lng()); 122 if (document.Envoie.lon.value < 0) 123 document.Envoie.lonRef.value = "W"; 124 else 125 document.Envoie.lonRef.value = "E"; 126 document.Envoie.lonDMS.value = Math.abs(dms_frac.Degre) + "/1" + " " + dms_frac.Minute + "/1" + " " + dms_frac.Numerator + "/" + dms_frac.Denominator; 127 dms_frac = dec2dms(latLng.lat()); 128 if (document.Envoie.lat.value < 0) 129 document.Envoie.latRef.value = "S"; 130 else 131 document.Envoie.latRef.value = "N"; 132 document.Envoie.latDMS.value = Math.abs(dms_frac.Degre) + "/1" + " " + dms_frac.Minute + "/1" + " " + dms_frac.Numerator + "/" + dms_frac.Denominator; 133 // update_datas(); 134 } 135 136 function update_datas() { 137 n = jQuery(document.EditJPEG); 138 jQuery.each(n[0], function (i) { 139 n00 = this; 140 n0 = n00.id; 141 n1 = n00.name; 142 n2 = jQuery(n00).val(); 143 try { 144 if (n0 == "alt") { 145 n3 = dec2frac(document.Envoie[n0].value); 146 n3 = n3.Numerator + "/" + n3.Denominator; 147 jQuery(this).val(n3); 148 } 149 else { 150 n3 = document.Envoie[n0].value; 151 jQuery(this).val(n3); 152 } 153 } 154 catch (e) { 155 n3 = n0; 156 } 157 }) 158 } 159 160 function updateMarkerAddress(str) { 161 document.getElementById('markerAdress').innerHTML = str; 162 jQuery("#match").val(str); 163 } 164 165 function getElevation(event) { 166 var elevator = new google.maps.ElevationService(); 167 var locations = []; 168 169 // Retrieve the clicked location and push it on the array 170 var clickedLocation = event.latLng; 171 locations.push(clickedLocation); 172 173 // Create a LocationElevationRequest object using the array's one value 174 var positionalRequest = { 175 'locations': locations 176 } 177 178 // Initiate the location request 179 if (elevator) { 180 elevator.getElevationForLocations(positionalRequest, function (results, status) { 181 if (status == google.maps.ElevationStatus.OK) { 182 183 // Retrieve the first result 184 if (results[0]) { 185 coordinates.ALT = results[0].elevation; 186 document.Envoie.alt.value = coordinates.ALT; 187 altDMS = dec2frac(coordinates.ALT); 188 document.Envoie.altRef.value = "0"; 189 190 document.Envoie.altDMS.value = altDMS.Numerator + "/" + altDMS.Denominator; 191 //styleIcon.set("text", "Elevation: " + results[0].elevation + "m"); 192 } else { 193 // alert("No results found"); 194 } 195 } else { 196 alert("Elevation service failed due to: " + status); 197 } 198 }); 199 } 200 } 201 function geocodePosition(pos) { 202 geocoder.geocode({ 'latLng': pos }, 203 function (results, status) { 204 /* Si le géocodage inversé a réussi */ 205 if (status == google.maps.GeocoderStatus.OK) { 206 updateMarkerAddress(results[0].formatted_address); 207 } else { 208 updateMarkerAddress('Cannot determine address at this location.'); 209 } 209 210 }); 210 } 211 } 212 213 214 215 function geocodePosition(pos) { 216 geocoder.geocode({ 'latLng': pos }, 217 function (results, status) { 218 /* Si le géocodage inversé a réussi */ 219 if (status == google.maps.GeocoderStatus.OK) { 220 updateMarkerAddress(results[0].formatted_address); 221 } else { 222 updateMarkerAddress('Cannot determine address at this location.'); 223 } 224 }); 225 } 226 227 228 /* Fonction de géocodage déclenchée en cliquant surle bouton "Geocoder" */ 229 function codeAddress() { 230 /* Récupération de la valeur de l'adresse saisie */ 231 232 /* Appel au service de geocodage avec l'adresse en paramètre */ 233 if (typeof map == "undefined") onLoad(); 234 235 var address = document.getElementById("match").value; 211 } 212 /* Fonction de géocodage déclenchée en cliquant surle bouton "Geocoder" */ 213 function codeAddress() { 214 /* Récupération de la valeur de l'adresse saisie */ 215 216 /* Appel au service de geocodage avec l'adresse en paramètre */ 217 if (typeof map == "undefined") onLoad(); 218 219 var address = document.getElementById("match").value; 236 220 237 221 geocoder.geocode({ 'address': address }, function (results, status) { 238 /* Si l'adresse a pu être géolocalisée */ 239 if (status == google.maps.GeocoderStatus.OK) { 240 /* Récupération de sa latitude et de sa longitude */ 241 coordinates.LAT = results[0].geometry.location.lat(); 242 coordinates.LON = results[0].geometry.location.lng(); 243 onLoad(); 244 245 246 247 } else { 248 alert("Cannot determine location at this adress.: " + status); 249 } 222 /* Si l'adresse a pu être géolocalisée */ 223 if (status == google.maps.GeocoderStatus.OK) { 224 /* Récupération de sa latitude et de sa longitude */ 225 coordinates.LAT = results[0].geometry.location.lat(); 226 coordinates.LON = results[0].geometry.location.lng(); 227 onLoad(); 228 } else { 229 alert("Cannot determine location at this adress.: " + status); 230 } 250 231 }); 251 232 } … … 253 234 //======================================================= 254 235 function On_Click(a, b, c) { 255 document.Envoie.lat.value = b; 256 document.Envoie.lon.value = c; 257 258 coordinates = {LAT:a, 259 LON : b} ; 260 LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON); 261 updateMarkerPosition(LatLng); 262 263 236 document.Envoie.lat.value = b; 237 document.Envoie.lon.value = c; 238 coordinates = { LAT: a, 239 LON: b 240 }; 241 LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON); 242 updateMarkerPosition(LatLng); 264 243 } 265 244 266 245 jQuery(window).load( 267 268 246 function () { 269 //Récupérer tous les inputs radios appartenant à un même groupe270 /* a = jQuery('input[type=hidden][name=Selectthumbnail]');271 272 273 274 */247 //Récupérer tous les inputs radios appartenant à un même groupe 248 /* a = jQuery('input[type=hidden][name=Selectthumbnail]'); 249 b = a.length; 250 c = jQuery('input[type=hidden]:checked').length; 251 d = jQuery('input[type=hidden][name="Selectthumbnail"]').attr('value'); 252 */ 275 253 276 254 // onLoad(); 277 }); 255 }); 278 256 279 257 jQuery(document).ready(function () { 280 258 281 jQuery('.cluetip').cluetip({ 282 width: 300, height: 100, 283 splitTitle: '|', 284 clickThrough: true 285 } 259 /* 260 jQuery('.cluetip').cluetip({ 261 width: 300, height: 100, 262 splitTitle: '|', 263 clickThrough: true 264 } 286 265 ); 266 */ 267 jQuery('.cluetip').tipTip({ maxWidth: '600px', 'delay': 0, 'fadeIn': 200, 'fadeOut': 200 }); 287 268 jQuery("#search").click(function (e) { 288 269 289 290 LAT:0,LON:0,ZOOM: 18 ,ALT:0291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 270 coordinates = { ADRESSE: jQuery("#match").val(), 271 LAT: 0, LON: 0, ZOOM: 18, ALT: 0 272 }; 273 codeAddress(); 274 return false; 275 }); 276 277 jQuery("#match").keydown(function (e) { 278 // e.target pour FireFox 279 // event.srcElement pour IE 280 var Obj = e ? e.target : event.srcElement; 281 if (Obj.tagName != "INPUT") return false; 282 var Code = e.keyCode || e.which; 283 if (Code != 13) return true; 284 coordinates = { ADRESSE: jQuery("#match").val(), 285 LAT: 0, LON: 0, ZOOM: 18, ALT: 0 286 }; 287 codeAddress(); 288 return false; 289 }); 309 290 310 291 … … 314 295 315 296 316 // DECIMAL TO FRACTION 317 // 318 function dec2frac( valeur_decimal ) { 319 decimal = valeur_decimal.toString() ; 320 num = ''; 321 den = 1; 322 dec = false; 323 324 // find least reduced fractional form of number 325 for( i = 0, ix = decimal.length ; i < ix; i++ ) 326 { 327 // build the denominator as we 'shift' the decimal to the right 328 if( dec ) den *= 10; 329 330 // find the decimal place/ build the numberator 331 if( decimal.charAt(i) == '.' ) dec = true; 332 else num += decimal.charAt(i); 333 } 334 num = parseInt(num); 335 336 // whole number, just return it 337 if( den == 1 ) return num; 338 339 num2 = num; 340 den2 = den; 341 rem = 1; 342 // Euclid's Algorithm (to find the gcd) 343 while( num2 % den2 ) { 344 rem = num2 % den2; 345 num2 = den2; 346 den2 = rem; 347 } 348 if( den2 != den ) rem = den2; 349 ret1 = { Numerator: (num / rem), Denominator: (den / rem) }; 350 // new Array() 351 // ret1->Numerator =(num / rem ) ; 352 // ret1->Denominator=(den / rem); 353 354 // now $rem holds the gcd of the numerator and denominator of our fraction 355 return ret1; 356 357 } 297 // DECIMAL TO FRACTION 298 // 299 function dec2frac(valeur_decimal) { 300 decimal = valeur_decimal.toString(); 301 num = ''; 302 den = 1; 303 dec = false; 304 305 // find least reduced fractional form of number 306 for (i = 0, ix = decimal.length; i < ix; i++) { 307 // build the denominator as we 'shift' the decimal to the right 308 if (dec) den *= 10; 309 310 // find the decimal place/ build the numberator 311 if (decimal.charAt(i) == '.') dec = true; 312 else num += decimal.charAt(i); 313 } 314 num = parseInt(num); 315 316 // whole number, just return it 317 if (den == 1) return num; 318 319 num2 = num; 320 den2 = den; 321 rem = 1; 322 // Euclid's Algorithm (to find the gcd) 323 while (num2 % den2) { 324 rem = num2 % den2; 325 num2 = den2; 326 den2 = rem; 327 } 328 if (den2 != den) rem = den2; 329 ret1 = { Numerator: (num / rem), Denominator: (den / rem) }; 330 // new Array() 331 // ret1->Numerator =(num / rem ) ; 332 // ret1->Denominator=(den / rem); 333 334 // now $rem holds the gcd of the numerator and denominator of our fraction 335 return ret1; 336 337 } 358 338 359 339 function dec2dms(l) { 360 sign = 1; 361 if (l < 0) { sign = -1; } 362 l = Math.abs(Math.round(l * 1000000.)) 363 d = Math.floor(l / 1000000) * sign; 364 m = Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60); 365 s = Math.floor(((((l / 1000000) - Math.floor(l / 1000000)) * 60) - Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60)) * 100000) * 60 / 100000; 366 frac_s = dec2frac(s); 367 s2 = (frac_s.Numerator / frac_s.Denominator); 368 return { dms: d + "° " + m + "' " + s + "''", 369 Degre:d, Minute:m,Sec:s, 370 Numerator: frac_s.Numerator, 371 Denominator:frac_s.Denominator}; 372 } 373 340 sign = 1; 341 if (l < 0) { sign = -1; } 342 l = Math.abs(Math.round(l * 1000000.)) 343 d = Math.floor(l / 1000000) * sign; 344 m = Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60); 345 s = Math.floor(((((l / 1000000) - Math.floor(l / 1000000)) * 60) - Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60)) * 100000) * 60 / 100000; 346 frac_s = dec2frac(s); 347 s2 = (frac_s.Numerator / frac_s.Denominator); 348 return { dms: d + "° " + m + "' " + s + "''", 349 Degre: d, Minute: m, Sec: s, 350 Numerator: frac_s.Numerator, 351 Denominator: frac_s.Denominator 352 }; 353 } 354
Note: See TracChangeset
for help on using the changeset viewer.