-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
141 lines (131 loc) · 4.49 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Config constants TODO: NON-GLOBAL?*/
var BUILDING_DEFAULT_OUTLINE_WEIGHT = 1;
var BUILDING_DEFAULT_FILL_OPACITY = 0.1;
var BUILDING_HIGHLIGHT_OUTLINE_WEIGHT_WEAK = 2;
var BUILDING_HIGHLIGHT_FILL_OPACITY_WEAK = 0.15;
var BUILDING_HIGHLIGHT_OUTLINE_WEIGHT_STRONG = 3;
var BUILDING_HIGHLIGHT_FILL_OPACITY_STRONG = 0.25;
var OBJECT_HIGHLIGHT_OUTLINE_WEIGHT_STRONG = 3;
var OBJECT_HIGHLIGHT_FILL_OPACITY_STRONG = .25;
var LANG = "en";
angular.module('usefulAaltoMap', ['ui-leaflet', 'ui.router', 'ngMaterial'])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/')
$stateProvider
.state('app', {
abstract: true,
views: {
'main': {
templateUrl: 'main/main.html',
controller: 'main',
resolve: {
initApp: function($http, mapService, utils) {
function addBuilding(d) {
if (d.outline) {
message = utils.get_lang(d, "name")
if (d.aliases && d.aliases.length > 0)
message += "\n<br> <span class=aliases>(" + d.aliases.join(", ") + ")</span>";
mapService.map.paths[d.id] = {
id: d.id,
data: d,
type: "polygon",
clickable: true,
weight: BUILDING_DEFAULT_OUTLINE_WEIGHT,
fill: true,
fillColor: 'red',
fillOpacity: BUILDING_DEFAULT_FILL_OPACITY,
latlngs: d.outline.map(function(coords) {
return {
lat: coords[0],
lng: coords[1]
}
}),
mouseoverMessage: message
}
mapService.resetColors(mapService.map.paths[d.id]);
}
}
return $http.get('data.json')
.then(function(res) {
// All data: id -> {data}
mapService.data = { };
// Object IDs which should be displayed by default: id -> true
mapService.defaultObjects = { };
angular.forEach(res.data.locations, function(d) {
mapService.data[d.id] = d;
})
// Redirections
mapService.redirects = res.data.redirects;
// Add objects to map
angular.forEach(mapService.data, function(d) {
switch (d.type) {
case 'building':
case 'auxbuilding':
case 'studenthousing':
case 'otherbuilding':
addBuilding(d);
mapService.defaultObjects[d.id] = true;
break;
default:
// do nothing
}
})
mapService.clearHighlights();
})
.catch(console.log)
}
}
},
'': {
template: '<div ui-view></div>'
}
}
})
.state('app.map', {
template: '',
url: '/',
resolve: {
clearHighlights: function(mapService) {
// Following line resets view when you leave sidenav.
//mapService.clearHighlights();
}
}
})
.state('app.selectedObject', {
templateUrl: 'sidenav/sidenav.html',
controller: 'sidenavController',
url: '/select/:objectId',
resolve: {
object: function($stateParams, mapService, $q, $state, $timeout) {
var objId = $stateParams.objectId;
function waitForInit() {
var deferred = $q.defer();
if (mapService.data) { return $q.resolve(mapService.data) }
else {
return $timeout(waitForInit, 100);
}
}
return waitForInit()
.then(function(data) {
var obj = mapService.data[objId];
if (obj) {
return $q.resolve(obj);
}
// Use the "redirects" data to see if our ID has been changed.
if (mapService.redirects && objId in mapService.redirects) {
var obj = mapService.data[mapService.redirects[objId]];
if (obj) {
$state.go("app.selectedObject", { objectId: mapService.redirects[objId] });
return $q.resolve(obj); // unreachable, hopefully (but backup display)
} else {
console.log("Tried to remap object, but failed: " + objId)
}
}
console.log("No object found with id " + objId)
$state.go('app.map')
})
.catch(console.log)
}
}
})
})