Переглянути джерело

Support ability to search by coordinates

add a parameter like ….?q={"x":-1.591809385999568,"y":49.16196732500049}

or simply use text box
boutils 10 роки тому
батько
коміт
cf4461f704
1 змінених файлів з 30 додано та 13 видалено
  1. 30 13
      js/app.js

+ 30 - 13
js/app.js

@@ -692,6 +692,12 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
     $scope.mapType = 'Satellite';
     $scope.view    = {};
     $scope.isShown = {};
+
+
+    if($location.search().q) {
+      $scope.address = $location.search().q;
+      $scope.suggestLocation($location.search().q);
+    }
   };
 
   var isDate = function(value) {
@@ -1212,23 +1218,34 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
   var i = 0, j = 0;
   $scope.suggestLocation = function(val) {
 
-    $scope.suggestionsReady = false;
-    i++;
-    return $http.get(suggestURL, {
-      params: {
-        text: val
-      }
-    }).then(function(response) {
+    try {
+      var coordinates = JSON.parse(val);
 
-      if(val === $scope.address) { // Very important to debounce queries
-        $scope.suggestionsReady = response.data.suggestions.length !== 0;
-        $scope.suggestions = _.cloneDeep(response.data.suggestions);
+      if(coordinates && coordinates.x) {
+        $scope.geoCode = coordinates;
+        addCurrentMarker();
       }
+      return;
+    }
+    catch(e) {
+      $scope.suggestionsReady = false;
+      i++;
+      return $http.get(suggestURL, {
+        params: {
+          text: val
+        }
+      }).then(function(response) {
+
+        if(val === $scope.address) { // Very important to debounce queries
+          $scope.suggestionsReady = response.data.suggestions.length !== 0;
+          $scope.suggestions = _.cloneDeep(response.data.suggestions);
+        }
 
-      return response.data.suggestions.map(function(item){
-        return item.text;
+        return response.data.suggestions.map(function(item){
+          return item.text;
+        });
       });
-    });
+    }
   };
 
   $scope.toggleResultPane = function() {