Ignore:
Timestamp:
Jan 4, 2011, 2:24:50 PM (13 years ago)
Author:
cljosse
Message:

[edit_gmaps] clean up.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/edit_gmaps/admin/js/JScript.js

    r8456 r8466  
    33var geocoder;
    44var map;
    5 var infowindow = new google.maps.InfoWindow();
    65var marker;
    7 
    8 function onLoad()
    9             {
     6var markers = new Array;
     7var detect = navigator.userAgent.toLowerCase();
     8
     9function onLoad() {
     10    var reg = new RegExp('/', "g");
     11   
     12  coordinates.ADRESSE=  coordinates.ADRESSE.replace("/",", ");
     13
     14          document.getElementById("match").value = coordinates.ADRESSE;
    1015                geocoder = new google.maps.Geocoder();
    1116                    var mapElement = document.getElementById("map");
    1217             if  ( coordinates.LAT  <= 90 ) {
    13                  LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON);
     18               
     19                 n = coordinates.ADRESSE.indexOf("/");
     20                 if (n>0)
     21                     zoom = 5;
     22                     else
    1423                            zoom = 18 ;
    15              }else {
    16                             LatLng = new google.maps.LatLng(49, 3);
    17                             zoom = 3;
     24                        } else {
     25                            coordinates.LAT=49 ;coordinates.LON = 3;
     26                       
     27                            geocoder.geocode({ 'address': coordinates.ADRESSE }, function (results, status) {
     28                                /* Si l'adresse a pu être géolocalisée */
     29                                if (status == google.maps.GeocoderStatus.OK) {
     30                                    /* Récupération de sa latitude et de sa longitude */
     31                                    coordinates.LAT = results[0].geometry.location.lat();
     32                                    coordinates.LON = results[0].geometry.location.lng();
     33                                    LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON);
     34                                    updateMarkerPosition(LatLng);
     35                                    geocodePosition(LatLng);
     36                                }
     37                            });
     38                 
     39                            zoom = 4;
    1840                        }
    1941 
    20 
     42   LatLng = new google.maps.LatLng(coordinates.LAT, coordinates.LON);
     43 
    2144
    2245            /*
     
    3255                    };
    3356       
    34                     var map = new google.maps.Map( mapElement, mapOpts );
     57                    map = new google.maps.Map( mapElement, mapOpts );
    3558
    3659             
     
    3861
    3962         if (coordinates)
    40                     var marker = new google.maps.Marker( {
     63                   marker = new google.maps.Marker( {
    4164                            position: map.getCenter(),
    4265                            map: map,
     
    7093
    7194
     95
    7296                        // Update current position info.   
    7397                       updateMarkerPosition(LatLng);
    7498                       geocodePosition(LatLng);
    7599             
    76                     return false;
     100                  return false;
    77101   
    78102
    79             function blowupUrl(theUrl) {
    80                 var win = new Window({
    81                     title: document.title,
    82                     url: theUrl,
    83                     classname: "alphacube",
    84                     left: 0, top: 0,
    85                     width: "640", height: "480",
    86                     minimizable: false,
    87                     maximizable: false,
    88                     draggable: false,
    89                     resizable: true,
    90                     destroyOnClose: true,
    91                     hideEffect: Element.hide,
    92                     showEffectOptions: { duration: 1.5 }
    93                 })
    94                 win.setConstraint(true, { top: 20, left: 20, bottom: 30, right: 20 });
    95                 win.maximize();
    96                 win.showCenter(true, 20, 20);
    97              
    98             }
    99 
    100 
    101 
    102 
    103 
    104       infowindow = new google.maps.InfoWindow();
    105 
    106       function geocodePosition(pos) {
    107           m = typeof geocoder;
    108             if (m == "undefined" ) return;
    109         geocoder.geocode({     
    110                 'latLng': pos    },
    111                 function(responses) {     
    112                     if (responses && responses.length > 0) {       
    113                         updateMarkerAddress(responses[0].formatted_address);
    114                     } else {       
    115                         updateMarkerAddress('Cannot determine address at this location.');     
    116                       }   
    117                 });
    118        }   
    119        
     103 
     104
     105
     106 }
     107
    120108       function updateMarkerStatus(str) {   
    121109                document.getElementById('markerStatus').innerHTML = str;
     
    129117           
    130118           function updateMarkerAddress(str) {               
    131                  message =  str;
    132                  document.getElementById('markerAdress').innerHTML = str;
    133 
    134             }
    135 
    136 
     119                  document.getElementById('markerAdress').innerHTML = str;
     120
     121            }
     122
     123
     124       
     125
     126
     127        function geocodePosition(pos) {
     128            geocoder.geocode({ 'latLng': pos },
     129               function (results, status) {
     130                   /* Si le géocodage inversé a réussi */
     131                   if (status == google.maps.GeocoderStatus.OK) {
     132                       updateMarkerAddress(results[0].formatted_address);
     133                   } else {
     134                       updateMarkerAddress('Cannot determine address at this location.');
     135                   }
     136               });
    137137        }
    138138
    139 
    140139 
    141 
    142 
    143 
    144      
    145   /* Initialisation de la carte  */
    146         function initialize() {
    147             geocoder = new google.maps.Geocoder();
    148             var latlng = new google.maps.LatLng(40.730885, -73.997383);
    149             var myOptions = {
    150                 zoom: 8,
    151                 center: latlng,
    152                 mapTypeId: 'roadmap'
    153             }
    154             map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    155         }
    156 
    157 
    158140        /* Fonction de géocodage déclenchée en cliquant surle bouton "Geocoder"  */
    159141        function codeAddress() {
    160142            /* Récupération de la valeur de l'adresse saisie */
     143         
     144            /* Appel au service de geocodage avec l'adresse en paramètre */
     145            if (typeof map == "undefined") onLoad();
     146
    161147            var address = document.getElementById("match").value;
    162             /* Appel au service de geocodage avec l'adresse en paramètre */
    163             geocoder.geocode({ 'address': address }, function (results, status) {
    164                 /* Si l'adresse a pu être géolocalisée */
    165                 if (status == google.maps.GeocoderStatus.OK) {
    166                     /* Récupération de sa latitude et de sa longitude */
    167                     document.Envoie.lat.value = results[0].geometry.location.lat();
    168                     document.Envoie.lon.value = results[0].geometry.location.lng();
    169                     map.setCenter(results[0].geometry.location);
    170                     /* Affichage du marker */
    171                     var marker = new google.maps.Marker({
    172                         map: map,
    173                         position: results[0].geometry.location
    174                     });
    175                     /* Permet de supprimer le marker précédemment affiché */
    176                     markers.push(marker);
    177                     if (markers.length > 1)
    178                         markers[(i - 1)].setMap(null);
    179                     i++;
    180                 } else {
    181                     alert("Le geocodage n\'a pu etre effectue pour la raison suivante: " + status);
    182                 }
     148
     149  geocoder.geocode({ 'address': address }, function (results, status) {
     150      /* Si l'adresse a pu être géolocalisée */
     151      if (status == google.maps.GeocoderStatus.OK) {
     152          /* Récupération de sa latitude et de sa longitude */
     153          coordinates.LAT = results[0].geometry.location.lat();
     154          coordinates.LON = results[0].geometry.location.lng();
     155          onLoad();
     156         
     157           
     158
     159      } else {
     160          alert("Cannot determine location at this adress.: " + status);
     161      }
     162  });
     163        }
     164
     165
     166
     167
     168        jQuery().ready(function () {
     169
     170
     171            jQuery('.cluetip').cluetip({
     172                width: 300, height: 100,
     173                splitTitle: '|'
     174            }
     175  );
     176
     177            // Resize possible 
     178            jQuery("#cadre").resizable({
     179                handles: "all",
     180                animate: true,
     181                animateDuration: "slow",
     182                animateEasing: "swing",
     183                preventDefault: true,
     184                preserveCursor: true,
     185                autoHide: true,
     186                ghost: true
    183187            });
    184         }
    185 
    186 
    187 
    188   /* Fonction de géocodage inversé  */
    189   function codeLatLng() {
    190    var lat = parseFloat(document.Envoie.lat.value);
    191    var lng = parseFloat(document.Envoie.lon.value);
    192    var latlng = new google.maps.LatLng(lat, lng);
    193 
    194    geocoder.geocode({ 'latLng': latlng },
    195               function(results, status) {
    196                     /* Si le géocodage inversé a réussi */
    197                     if (status == google.maps.GeocoderStatus.OK) {
    198                      if (results[1]) {
    199                         map.setZoom(11);
    200                         marker = new google.maps.Marker({
    201                         position: latlng,
    202                         map: map
    203                        });
    204       /* Affichage de l'infowindow sur le marker avec l'adresse récupérée */
    205       infowindow.setContent(results[1].formatted_address);
    206       infowindow.open(map, marker);
    207      }
    208     } else {
    209      alert("Le geocodage a echoue pour la raion suivante : " + status);
    210     }
    211    });
    212   }
    213  
     188
     189            jQuery("#match").keydown(function (e) {
     190
     191                // e.target         pour FireFox
     192                // event.srcElement pour IE
     193                var Obj = e ? e.target : event.srcElement;
     194                if (Obj.tagName != "INPUT") return false;
     195
     196
     197                var Code = e.keyCode || e.which;
     198                if (Code != 13) return true;
     199                    coordinates.ADRESSE=   document.getElementById("match").value  ;
     200                    codeAddress();
     201                return false;
     202            });
     203
     204
     205        });
     206
Note: See TracChangeset for help on using the changeset viewer.