source: extensions/edit_gmaps/admin/js/JScript.js @ 17776

Last change on this file since 17776 was 17776, checked in by cljosse, 12 years ago

[extensions] edit_gmaps compatibility 2.4 add batch mode global

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