ang-google-maps
Advanced tools
Comparing version 1.0.6 to 1.0.8
{ | ||
"name": "ang-google-maps", | ||
"version": "1.0.6", | ||
"version": "1.0.8", | ||
"homepage": "https://github.com/khalednobani/ang-google-maps", | ||
@@ -5,0 +5,0 @@ "description": "Initialise Google Maps, Set Location, Drop Pins, Get Connected Routes between the current location and the destination.", |
@@ -6,14 +6,39 @@ (function(ang) { | ||
ang.module('main', ['ang-google-maps', 'ang-google-services']) | ||
.controller('mainCtrl', ['$scope', 'Direction', '$Geocode', mainCtrl]); | ||
.controller('mainCtrl', ['$scope', 'Direction', '$Geocode', '$rootScope', '$filter', mainCtrl]) | ||
.filter('getByName', function() { | ||
function mainCtrl($scope, Direction, $Geocode) { | ||
return function(input, name) { | ||
for (var index = 0, length = ('length' in input) ? input.length : 0; index < length; index++) { | ||
if (input[index]['name'] == name) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
}); | ||
function mainCtrl($scope, Direction, $Geocode, $rootScope, $filter) { | ||
var $Self = this; | ||
var $Self = this; | ||
// Models | ||
$scope.appName = 'Maps API'; | ||
$scope.currentDestination = 'dropOff1'; | ||
$scope.dropOffs = []; | ||
$scope.waypoints = []; | ||
$scope.location = {}; | ||
// Methods | ||
$scope.manageDropOffs = function() { | ||
manageDropOffs.call($scope, $filter); | ||
}; | ||
setModel.call($scope); | ||
$scope.handleMarkerDrop = function($Event, $Model, $AutoCompScope) { | ||
$Geocode.getNames({ | ||
@@ -28,17 +53,11 @@ coords: $Event.latLng | ||
}; | ||
$scope.setPickup = function($Position, $Model, $CoreModel) { | ||
$scope.location['pickUp'] = $Position; | ||
$scope.manageDropOffs(); | ||
$scope.setLocation(); | ||
}; | ||
$scope.setDropoff1 = function($Position, $Model, $CoreModel) { | ||
$scope.location[$scope.currentDestination] = $Position; | ||
$scope.setLocation(); | ||
}; | ||
$scope.setLocation = function($Position, $Model, $CoreModel) { | ||
@@ -54,3 +73,4 @@ | ||
current: current, | ||
destination: destination | ||
destination: destination, | ||
dropOffs: $scope['waypoints'] | ||
}); | ||
@@ -60,30 +80,114 @@ } | ||
}; | ||
$scope.handleDirectionChange = function($Leg, $parentScope, $Directions) { | ||
$scope.handleDirectionChange = function($Leg, done) { | ||
console.log('Handle on change'); | ||
//$tempScope['pickUp'] = Math.random(1000); | ||
console.log(arguments); | ||
$scope['pickUp'] = $Leg.start_address; | ||
$scope[$scope.currentDestination] = $Leg.end_address; | ||
$scope.location['pickUp'] = $Leg.start_location; | ||
$scope.location[$scope.currentDestination] = $Leg.end_location; | ||
$parentScope['pickUp'] = $scope['pickUp'] = $Leg.current.name; | ||
$parentScope[$scope.currentDestination] = $scope[$scope.currentDestination] = $Leg.destination.name; | ||
$scope.location['pickUp'] = $Leg.current.coords; | ||
$scope.location[$scope.currentDestination] = $Leg.destination.coords; | ||
// To update input fields | ||
done($scope); | ||
$scope.updateWaypoints($parentScope, $Leg.waypoints); | ||
}; | ||
$scope.updateWaypoints = function($parentScope, $WayPoints) { | ||
var reversedWaypoints = $WayPoints.reverse(); | ||
ang.forEach($scope.dropOffs, function(value, key) { | ||
var isNameEqual = $scope.dropOffs[key]['name'] == $scope.currentDestination, | ||
isLastIndex = key + 1 == $scope.dropOffs.length, | ||
name = undefined, | ||
addressName = undefined; | ||
if (!isLastIndex) { | ||
if (isNameEqual) { | ||
console.log("Yes, Gotcha"); | ||
$scope.dropOffs[key+1]['location'] = reversedWaypoints[key]['end_location']; | ||
name = $scope.dropOffs[key+1]['name']; | ||
//console.log($WayPoints[key]); | ||
} else { | ||
console.log("Not Yet"); | ||
console.log($scope.dropOffs[key]); | ||
$scope.dropOffs[key]['location'] = reversedWaypoints[key]['end_location']; | ||
name = $scope.dropOffs[key]['name']; | ||
//console.log($WayPoints[key]); | ||
} | ||
addressName = $WayPoints[key]['end_address']; | ||
} | ||
if(name && addressName) $parentScope[name] = $scope[name] = addressName; | ||
}); | ||
console.log($scope.dropOffs); | ||
console.log($WayPoints); | ||
}; | ||
} | ||
function setModel() { | ||
this.appName = "Google Maps API"; | ||
function reShapeWaypoints($list) { | ||
// Set the model | ||
this.location = { | ||
'pickUp': '', | ||
'dropOff1': '' | ||
var $List = $list || [], | ||
$NewList = []; | ||
for (var index = 0, length = $List.length; index < length; index++) { | ||
$NewList.push(ang.copy($List[index])); | ||
delete $NewList[index]['name']; | ||
} | ||
return $NewList; | ||
} | ||
function manageDropOffs($filter) { | ||
var $scope = this; | ||
$scope.setDropoff = function($Position, $Model, $CoreModel, name) { | ||
$scope.location[name] = $Position; | ||
var index = $filter('getByName')($scope.dropOffs, name), | ||
$WayPoint = { | ||
name: name, | ||
location: $Position | ||
}, | ||
$PointInfo = ang.copy($WayPoint), | ||
$InsertedEle = 0; | ||
if(index == -1) { | ||
$InsertedEle = $scope.dropOffs.push($PointInfo); | ||
} else { | ||
$scope.dropOffs[index] = $PointInfo; | ||
} | ||
$scope.waypoints = reShapeWaypoints($scope.dropOffs); | ||
var currentIndex = (index != -1) ? index : ($InsertedEle == 0) ? 0 : ($InsertedEle - 1); | ||
console.log("currentIndex = " + currentIndex); | ||
console.log($scope); | ||
if ($scope.dropOffs[currentIndex]['name'] == $scope.currentDestination) { | ||
$scope.waypoints.splice(currentIndex, 1); | ||
} | ||
$scope.setLocation(); | ||
}; | ||
} | ||
}(angular)); |
{ | ||
"name": "ang-google-maps", | ||
"version": "1.0.6", | ||
"version": "1.0.8", | ||
"description": "Module to initialize Google Maps API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,3 @@ (function(ang, g) { | ||
.factory('Geocode', function() { return Geocode(); }) | ||
.factory('Direction', ['$q', function($q) { | ||
.factory('Direction', ['$q', '$rootScope', function($q, $rootScope) { | ||
@@ -18,11 +18,12 @@ var $DirectionService = new g.maps.DirectionsService, | ||
$DirectionDisplay.addListener('directions_changed', function(res) { | ||
var $Directions = this.directions, | ||
$Map = this.map, | ||
$Leg = $Directions.routes[0].legs[0]; | ||
$Leg = $Directions.routes[0].legs[0], | ||
$ProcessedLeg = processLegs($Directions); | ||
if (typeof $Map.ondirectionchange == 'function') $Map.ondirectionchange({$Leg: $Leg, done: function($scope) { | ||
if ($scope) $scope.$apply(); | ||
}}); | ||
if (typeof $Map.ondirectionchange == 'function') $Map.ondirectionchange({$Leg: $ProcessedLeg, $parentScope: $rootScope, $Directions: $Directions}); | ||
$rootScope.$digest(); | ||
}); | ||
@@ -37,4 +38,47 @@ | ||
.directive('mapTemp', ['$window', '$document', '$http', mapTempFactory]) | ||
.directive('autoCompleteTemp', ['$window', '$http', autoCompleteTempFactory]); | ||
.directive('autoCompleteTemp', ['$window', '$http', '$rootScope', autoCompleteTempFactory]); | ||
function processLegs($Directions) { | ||
var $Routes = $Directions.routes[0], | ||
$Legs = $Routes.legs, | ||
$Result = {waypoints: []}; | ||
if (!$Legs.length) return $Results; | ||
$Result['current'] = { | ||
coords: $Legs[0]['start_location'], | ||
name: $Legs[0]['start_address'] | ||
}; | ||
if ($Legs.length == 1) { | ||
$Result['destination'] = { | ||
coords: $Legs[0]['end_location'], | ||
name: $Legs[0]['end_address'] | ||
} | ||
} else { | ||
for (var index = 0, length = $Legs.length; index < length; index++) { | ||
if (index + 1 == length) { | ||
$Result['destination'] = { | ||
coords: $Legs[index]['end_location'], | ||
name: $Legs[index]['end_address'] | ||
}; | ||
} else { | ||
$Result['waypoints'].push($Legs[index]); | ||
} | ||
} | ||
$Result['waypoints'] = $Result['waypoints'].reverse(); | ||
} | ||
return $Result; | ||
} | ||
/** | ||
@@ -111,3 +155,3 @@ * Factory of google map's marker | ||
*/ | ||
function autoCompleteTempFactory($window, $http) { | ||
function autoCompleteTempFactory($window, $http, $rootScope) { | ||
@@ -119,3 +163,3 @@ return { | ||
autoCompleteTempLink.call(this, $scope, element, $atts, $ctrls); | ||
autoCompleteTempLink.call(this, $scope, element, $atts, $ctrls, $rootScope); | ||
@@ -125,3 +169,3 @@ }, | ||
map: '=map', | ||
name: '@', | ||
nameofinput: '@', | ||
onfill: '&onfill', | ||
@@ -135,3 +179,3 @@ ondrop: '&ondrop' | ||
autoCompleteTempFactory.$inject = ['$window', '$http']; | ||
autoCompleteTempFactory.$inject = ['$window', '$http', '$rootScope']; | ||
@@ -242,4 +286,4 @@ /** | ||
function autoCompleteTempCtrl($scope) { | ||
$scope.model = { label: '', name: $scope.name, show: 0 }; | ||
$scope.fillInAdress = fillInAdress; | ||
$scope.model = { label: '', name: $scope.nameofinput, show: 0 }; | ||
$scope.fillInAddress = fillInAddress; | ||
} | ||
@@ -257,3 +301,3 @@ | ||
*/ | ||
function autoCompleteTempLink($scope, element, attrs, ctrls) { | ||
function autoCompleteTempLink($scope, element, attrs, ctrls, $rootScope) { | ||
@@ -269,12 +313,13 @@ // Create autocomplete object | ||
$scope.element = element[0]; | ||
$scope.$parent[$scope['name']] = ''; | ||
$scope.$parent.$watch($scope['name'], function(newValue, oldValue) { | ||
console.log("Something is being changed"); | ||
$rootScope[$scope['nameofinput']] = ''; | ||
$rootScope.$watch($scope['nameofinput'], function(newValue, oldValue) { | ||
//console.log("Something is being changed"); | ||
//console.log(arguments); | ||
if(newValue) $scope.element.value = newValue; | ||
return newValue; | ||
}).bind($scope.$parent); | ||
});//.bind($scope.$parent); | ||
// Attach an event into autocomplete | ||
g.maps.event.addListener($scope.autocomplete, 'place_changed', function() { | ||
$scope.fillInAdress(); | ||
$scope.fillInAddress(); | ||
}); | ||
@@ -329,10 +374,10 @@ | ||
function fillInAdress() { | ||
function fillInAddress() { | ||
var place = this.autocomplete.getPlace(), | ||
lat = place.geometry.location.G, | ||
lng = place.geometry.location.K, | ||
lat = place.geometry.location.G || place.geometry.location.H, | ||
lng = place.geometry.location.K || place.geometry.location.L, | ||
$CtrlScope = this.$parent, | ||
$Self = this, | ||
$Position = GetPosition(lat, lng); | ||
$Position = { lat: parseFloat(lat), lng: parseFloat(lng) }; | ||
@@ -400,3 +445,3 @@ console.log($Self.model); | ||
setRoute : function(options) { | ||
if (options['map']) { | ||
@@ -410,5 +455,9 @@ | ||
destination: options['destination'] || 0, | ||
destination: options['destination'] || '', | ||
origin: options['current'] || 0, | ||
travelMode: google.maps.TravelMode.DRIVING | ||
provideRouteAlternatives : false, | ||
optimizeWaypoints : options['optimized'] || true, | ||
waypoints: options['dropOffs'] || [], | ||
travelMode: g.maps.TravelMode.DRIVING, | ||
unitSystem: g.maps.UnitSystem.IMPERIAL | ||
@@ -419,2 +468,4 @@ }, function(response, status) { | ||
// Display the route on the map. | ||
console.log("Line 413"); | ||
console.log(response); | ||
$DirectionDisplay.setDirections(response); | ||
@@ -421,0 +472,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
562439
876