From 483841af89da8e5d4079ad7283f48603e07dc553 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 30 May 2014 22:15:04 +0200 Subject: [PATCH] Fix: Position will be shown on map and centered on when updating. --- app/scripts/directives/nodeForm.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/scripts/directives/nodeForm.js b/app/scripts/directives/nodeForm.js index 9e7a9aa..753f7e5 100644 --- a/app/scripts/directives/nodeForm.js +++ b/app/scripts/directives/nodeForm.js @@ -44,8 +44,7 @@ angular.module('ffffng') $scope.node.coords = lat + ' ' + lng; }); - $scope.updateMap = function () { - var coords = $scope.coords || ''; + function withValidCoords(coords, callback) { coords = coords.trim(); if (_.isEmpty(coords)) { return; @@ -60,7 +59,14 @@ angular.module('ffffng') var lat = Number(parts[0]); var lng = Number(parts[1]); - updateNodePosition(lat, lng); + callback(lat, lng); + } + + $scope.updateMap = function (optCoords) { + var coords = optCoords || $scope.coords || ''; + withValidCoords(coords, function (lat, lng) { + updateNodePosition(lat, lng); + }); }; $scope.resetCoords = function () { @@ -101,6 +107,13 @@ angular.module('ffffng') } }); }; + + $scope.updateMap($scope.node.coords); + withValidCoords($scope.node.coords, function (lat, lng) { + $scope.center.lat = lat; + $scope.center.lng = lng; + $scope.center.zoom = 12; + }); }; return {