Projet

Général

Profil

0001-misc-only-request-geocoding-if-a-city-or-postcode-is.patch

Frédéric Péters, 14 mai 2019 20:19

Télécharger (2,41 ko)

Voir les différences:

Subject: [PATCH] misc: only request geocoding if a city (or postcode) is given
 (#33097)

 wcs/qommon/static/js/qommon.geolocation.js | 28 +++++++++++++---------
 1 file changed, 17 insertions(+), 11 deletions(-)
wcs/qommon/static/js/qommon.geolocation.js
70 70
    if (! $map.data('address-sync')) return;
71 71
    $('div[data-geolocation]').on('change', 'input[type=text], textarea, select', function(event) {
72 72
      var address = '';
73
      var found_city = false;
73 74
      $(['number-and-street', 'house', 'road', 'postcode', 'city', 'country']).each(function(idx, elem) {
74 75
        var part = $('div[data-geolocation="' + elem + '"]').find('input, textarea, select').val();
75 76
        if (part) {
......
77 78
          if (elem == 'number-and-street' || elem == 'road' || elem == 'city') {
78 79
            address += ', ';
79 80
          }
80
        }
81
      });
82
      $.getJSON(WCS_ROOT_URL + '/api/geocoding?q=' + address, function(data) {
83
        if (data && $(data).length > 0) {
84
          var coords = {lat: data[0].lat, lon: data[0].lon};
85
          var map = $map[0].leaflet_map;
86
          map.flyTo(coords);
87
          if (map.marker === null) {
88
            map.marker = L.marker([0, 0]);
89
            map.marker.addTo(map);
81
          if (elem == 'postcode' || elem == 'city') {
82
            found_city = true;
90 83
          }
91
          map.marker.setLatLng(coords);
92 84
        }
93 85
      });
86
      if (found_city) {
87
        $.getJSON(WCS_ROOT_URL + '/api/geocoding?q=' + address, function(data) {
88
          if (data && $(data).length > 0) {
89
            var coords = {lat: data[0].lat, lon: data[0].lon};
90
            var map = $map[0].leaflet_map;
91
            map.flyTo(coords);
92
            if (map.marker === null) {
93
              map.marker = L.marker([0, 0]);
94
              map.marker.addTo(map);
95
            }
96
            map.marker.setLatLng(coords);
97
          }
98
        });
99
      }
94 100
    });
95 101
  }
96 102
  function unset_sync_callback() {
97
-