-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaptest.js
74 lines (68 loc) · 2.08 KB
/
maptest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var app = angular.module("mobiliteitsapp", ["ngAnimate", "ngMaterial", "ui-leaflet"]);
//Controllers
app.controller("MainCtrl", ["$rootScope", "$scope", "$timeout", "$q", "$log", "locationService", function($rootScope, $scope, $timeout, $q, $log, locationService) {
var self = this;
self.simulateQuery = false;
self.isDisabled = false;
// list of `state` value/display objects
self.locations = loadAll();
self.querySearch = querySearch;
self.selectedItemChange = selectedItemChange;
self.searchTextChange = searchTextChange;
self.newState = newState;
function newState() {
$log("test");
}
// ******************************
// Internal methods
// ******************************
/**
* Search for locations... use $timeout to simulate
* remote dataservice call.
*/
function querySearch(query) {
var results = query ? self.locations.filter(createFilterFor(query)) : self.locations,
deferred;
if (self.simulateQuery) {
deferred = $q.defer();
$timeout(function() {
deferred.resolve(results);
}, Math.random() * 1000, false);
return deferred.promise;
} else {
return results;
}
}
function searchTextChange(text) {
$log.info("Text changed to " + text);
}
function selectedItemChange(item, id) {
if (id === 1) {
console.log("origin changed");
$rootScope.$emit("originChanged", item);
} else if (id === 2) {
console.log("destination changed");
$rootScope.$emit("destinationChanged", item);
}
$log.info("Item changed to " + JSON.stringify(item));
}
/**
* Build `locations` list of key/value pairs
*/
function loadAll() {
var locations = locationService.getLocations();
return locations.map(function(location) {
location.value = location.name.toLowerCase();
return location;
});
}
/**
* Create filter function for a query string
*/
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(state) {
return (state.value.indexOf(lowercaseQuery) === 0);
};
}
}]);