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

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

[extensions] edit_gmaps compatibility 2.4

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