Do not display empty maps.
authorStéphane Jacob <sj@m4x.org>
Mon, 6 Jun 2011 11:35:01 +0000 (13:35 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 6 Jun 2011 11:35:01 +0000 (13:35 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/gmapsgeocoder.php
htdocs/javascript/profile.js
templates/geoloc/form.address.tpl

index 2e44a01..302080f 100644 (file)
@@ -32,13 +32,16 @@ class GMapsGeocoder extends Geocoder {
 
     static public function buildStaticMapURL($latitude, $longitude, $color, $separator = '&')
     {
+        if (!$latitude || !$longitude) {
+            return null;
+        }
+
         $parameters = array(
             'size'    => '300x100',
             'markers' => 'color:' . $color . '|' . $latitude . ',' . $longitude,
             'zoom'    => '12',
             'sensor'  => 'false'
         );
-        global $globals;
 
         return Platal::globals()->maps->static_map . '?' . http_build_query($parameters, '', $separator);
     }
index 0d63c9b..b8b1c2c 100644 (file)
@@ -317,8 +317,13 @@ function addressChanged(prefid, color)
     var text = $('#' + prefid + '_cont').find("[name*='[text]']").val();
     $('#' + prefid + '_cont').find('[name*=changed]').val("1");
     $.xpost('map_url/', { text:text, color:color }, function(data) {
-        $('#' + prefid + '_static_map_url').show();
-        $('#' + prefid + '_static_map_url').find('img').attr('src', data);
+        if (data) {
+            $('#' + prefid + '_static_map_url').show();
+            $('#' + prefid + '_static_map_url').find('img').attr('src', data);
+        } else {
+            $('#' + prefid + '_static_map_url').hide();
+            $('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox').removeAttr('checked');
+        }
     });
 }
 
index 99e9b69..b4add50 100644 (file)
@@ -52,7 +52,7 @@
   </td>
   <td>
 {/if}
-  <div id="{$prefid}_static_map_url" {if !t($address.latitude)}style="display: none"{/if}>
+  <div id="{$prefid}_static_map_url" {if !t($address.componentsIds)}style="display: none"{/if}>
     <img src="{insert name="getStaticMapURL" latitude=$address.latitude longitude=$address.longitude color=$profile->promoColor()}" alt="Position de l'adresse" />
     {if t($geocoding_removal)}
     <br />