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

Last change on this file since 8501 was 8501, checked in by cljosse, 13 years ago

[edit_gmaps] Improvement of the display.


File size: 6.7 KB
Line 
1
2/* Déclaration des variables  */
3var geocoder;
4var map;
5var marker;
6var markers = new Array;
7var detect = navigator.userAgent.toLowerCase();
8
9function onLoad() {
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  zoom = coordinates.ZOOM;
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        'dragstart',
69        function () {
70            updateMarkerAddress('Dragging...');
71        });
72
73        google.maps.event.addListener(marker,
74            'drag',
75            function () {
76                updateMarkerStatus('Dragging...');
77                updateMarkerPosition(marker.getPosition());
78            }
79            );
80
81            google.maps.event.addListener(marker,
82        'dragend',
83        function () {
84            updateMarkerStatus('Drag ended');
85            geocodePosition(marker.getPosition());
86           
87            }
88        );
89
90
91
92                        // Update current position info.   
93                       updateMarkerPosition(LatLng);
94                       geocodePosition(LatLng);
95             
96                  return false;
97   
98
99 
100
101
102 }
103
104       function updateMarkerStatus(str) {   
105                document.getElementById('markerStatus').innerHTML = str; 
106        }   
107       
108        function updateMarkerPosition(latLng) {   
109                document.Envoie.lat.value=latLng.lat() ;
110                document.Envoie.lon.value = latLng.lng();
111               
112               
113                }
114           
115           function updateMarkerAddress(str) {
116               document.getElementById('markerAdress').innerHTML = str;
117       
118               jQuery("#match").val(str);
119            }
120
121
122       
123
124
125        function geocodePosition(pos) {
126            geocoder.geocode({ 'latLng': pos },
127               function (results, status) {
128                   /* Si le géocodage inversé a réussi */
129                   if (status == google.maps.GeocoderStatus.OK) {
130                       updateMarkerAddress(results[0].formatted_address);
131                   } else {
132                       updateMarkerAddress('Cannot determine address at this location.');
133                   }
134               });
135        }
136
137 
138        /* Fonction de géocodage déclenchée en cliquant surle bouton "Geocoder"  */
139        function codeAddress() {
140            /* Récupération de la valeur de l'adresse saisie */
141         
142            /* Appel au service de geocodage avec l'adresse en paramètre */
143            if (typeof map == "undefined") onLoad();
144
145            var address = document.getElementById("match").value;
146
147  geocoder.geocode({ 'address': address }, function (results, status) {
148      /* Si l'adresse a pu être géolocalisée */
149      if (status == google.maps.GeocoderStatus.OK) {
150          /* Récupération de sa latitude et de sa longitude */
151          coordinates.LAT = results[0].geometry.location.lat();
152          coordinates.LON = results[0].geometry.location.lng();
153          onLoad();
154         
155           
156
157      } else {
158          alert("Cannot determine location at this adress.: " + status);
159      }
160  });
161}
162
163//=======================================================
164function On_Click(a, b, c) {
165    document.Envoie.lat.value = b;
166    document.Envoie.lon.value = c;
167
168    coordinates = {LAT:a,
169     LON : b} ;
170    LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON);
171    updateMarkerPosition(LatLng);
172
173
174}
175
176jQuery(window).load(
177
178      function () {
179//Récupérer tous les inputs radios appartenant à un même groupe
180 /*         a = jQuery('input[type=hidden][name=Selectthumbnail]');
181          b = a.length;
182          c = jQuery('input[type=hidden]:checked').length;
183          d = jQuery('input[type=hidden][name="Selectthumbnail"]').attr('value');
184*/
185
186        //  onLoad();
187      }); 
188
189jQuery(document).ready(function () {
190
191
192    jQuery('.cluetip').cluetip({
193        width: 300, height: 100,
194        splitTitle: '|'
195    }
196  );
197  jQuery("#search").click(function (e) {
198
199        coordinates = { ADRESSE: jQuery("#match").val(),
200                        LAT:0,LON:0,ZOOM: 18 
201                       };
202        codeAddress();
203        return false;
204    });
205
206    jQuery("#match").keydown(function (e) {
207        // e.target         pour FireFox
208        // event.srcElement pour IE
209        var Obj = e ? e.target : event.srcElement;
210        if (Obj.tagName != "INPUT") return false;
211        var Code = e.keyCode || e.which;
212        if (Code != 13) return true;
213        coordinates = { ADRESSE: jQuery("#match").val(),
214                        LAT:0,LON:0,ZOOM: 18 
215                       };
216        codeAddress();
217        return false;
218    });
219
220
221});
222
Note: See TracBrowser for help on using the repository browser.