a0fba7c8
David Beech
david
|
1
|
(function (angular) {
|
ec938bf0
Tarpit Grover
first commit
|
2
3
|
var app = angular.module('batmanDelivers');
app.directive("addressSearch", addressSearch);
|
a0fba7c8
David Beech
david
|
4
|
addressSearch.$inject = ['$parse', '$rootScope', '$http', '$timeout', '$sce', '$rootScope']
|
ec938bf0
Tarpit Grover
first commit
|
5
|
|
a0fba7c8
David Beech
david
|
6
|
function addressSearch($parse, $rootScope, $http, $timeout, $sce, $rootScope) {
|
ec938bf0
Tarpit Grover
first commit
|
7
8
|
return {
templateUrl: '/src/js/directives/address-search/partial.html',
|
a0fba7c8
David Beech
david
|
9
10
11
12
|
scope: {
address: '=model'
},
link: function (scope, elm, attrs) {
|
ec938bf0
Tarpit Grover
first commit
|
13
|
scope.placeholder = attrs["placeholder"];
|
a0fba7c8
David Beech
david
|
14
15
16
17
|
scope.selected = {
address: null
};
|
484036e0
Tarpit Grover
WIP
|
18
19
20
|
scope.order = $parse(attrs['order'])(scope);
scope.lbl = $parse(attrs['lbl'])(scope);
|
a0fba7c8
David Beech
david
|
21
22
|
var autocompleteService = new google.maps.places.AutocompleteService();
var placesService = new google.maps.places.PlacesService($rootScope.map);
|
484036e0
Tarpit Grover
WIP
|
23
|
|
a0fba7c8
David Beech
david
|
24
25
26
27
28
29
30
31
32
|
scope.request = function (value) {
if (value && value.length > 3) {
autocompleteService.getPlacePredictions({
input: value
}, function (results) {
scope.addresses = results;
scope.$apply();
});
}
|
a668a573
Sean Wills
new
|
33
|
}
|
ec938bf0
Tarpit Grover
first commit
|
34
|
|
a0fba7c8
David Beech
david
|
35
36
37
38
39
40
41
42
43
44
45
46
47
|
scope.$watch('selected.address', function (newvalue) {
if (newvalue && newvalue.place_id) {
placesService.getDetails({
placeId: newvalue.place_id
}, function (result) {
scope.result = result;
scope.address.AddressLine1 = scope.result.address_components[1].long_name;
scope.address.AddressLine2 = scope.result.address_components[2].long_name;
scope.address.City = scope.result.address_components[3].long_name;
scope.address.PostCode = scope.result.address_components[0].long_name;
scope.address.Latitude = scope.result.geometry.location.lat();
scope.address.Longitude = scope.result.geometry.location.lng();
scope.address.Description = newvalue.description;
|
a0fba7c8
David Beech
david
|
48
|
scope.address.valid = true;
|
ec938bf0
Tarpit Grover
first commit
|
49
|
|
ec938bf0
Tarpit Grover
first commit
|
50
|
|
a0fba7c8
David Beech
david
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
if (!scope.address.$marker) {
scope.address.$marker = new google.maps.Marker({
map: $rootScope.map,
position: scope.result.geometry.location,
icon: '.././includes/images/c1.png'
});
} else {
scope.address.$marker.setPosition({ lat: scope.result.geometry.location.lat(), lng: scope.result.geometry.location.lng() });
}
scope.$apply();
scope.$emit('StopChanged');
});
}
});
|
ec938bf0
Tarpit Grover
first commit
|
65
66
67
|
}
}
}
|
a668a573
Sean Wills
new
|
68
|
})(angular);
|