Repository navigation
Expand file tree
/
Copy pathmap.js
More file actions
327 lines (270 loc) · 8.28 KB
/
Copy pathmap.js
File metadata and controls
327 lines (270 loc) · 8.28 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/**
* You must include the dependency on 'ngMaterial'
*/
angular.module('CookAndCode', ['ngMaterial']);
angular
.module('CookAndCode')
.config(function($mdThemingProvider) {
$mdThemingProvider.theme('default')
.primaryPalette('indigo')
.accentPalette('teal')
.dark();
})
.controller('IndexController', IndexController);
function IndexController ($http, $log, $scope, $interval){
var vm = this;
var neCoord = {
lat: 0,
lng: 0
};
var swCoord = {
lat: 1000,
lng: 1000
};
var map;
var json_data;
var end;
var start;
var markers = {};
var all_paths = [];
var team_colors = {};
vm.init = false;
vm.time = 0;
function getRangeMax(start, end) {
start_timestamp = new Date(start).getTime();
end_timestamp = new Date(end).getTime();
var new_end = end_timestamp-start_timestamp;
return new_end;
}
//null to hide, map to show
function toggleMarker(_id, map) {
if(markers[_id])
markers[_id].setMap(map);
}
function clearPaths() {
for(var i=0; i<all_paths.length;i++)
all_paths[i].setMap(null);
}
vm.rebuildMarkers = function(timestamp) {
neCoord = {
lat: 0,
lng: 0
};
swCoord = {
lat: 1000,
lng: 1000
};
if(start) {
var maxTimestamp = new Date(start);
maxTimestamp.setSeconds(start.getSeconds() + Math.floor(timestamp/1000));
setMarkers(maxTimestamp);
var bounds = new google.maps.LatLngBounds(swCoord, neCoord);
map.fitBounds(bounds);
}
};
vm.rebuildMarkers(end);
function generateColor(name) {
return '#'+CryptoJS.SHA1(name).toString(CryptoJS.enc.Hex).substr(0, 4)+50;
}
function pinSymbol(color) {
return {
path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z M -2,-30 a 2,2 0 1,1 4,0 2,2 0 1,1 -4,0',
fillColor: color,
fillOpacity: 1,
strokeColor: '#000',
strokeWeight: 2,
scale: 1
};
}
function getData(callback) {
$http.get('http://mock-backend.break-out.org/posts/location').then(function (data) {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
styles:[
{
"featureType": "administrative",
"stylers": [
{ "visibility": "simplified" }
]
},{
"featureType": "landscape",
"stylers": [
{ "saturation": -100 }
]
},{
"featureType": "poi",
"stylers": [
{ "saturation": -100 }
]
},{
"featureType": "water",
"stylers": [
{ "hue": "#0091ff" },
{ "saturation": -34 },
{ "lightness": 9 }
]
},{
"featureType": "road",
"stylers": [
{ "hue": "#0066ff" },
{ "lightness": -18 },
{ "saturation": -33 },
{ "gamma": 1.38 },
{ "visibility": "simplified" }
]
},{
"featureType": "administrative",
"stylers": [
{ "lightness": -100 }
]
},{
"featureType": "transit.line",
"stylers": [
{ "hue": "#005eff" },
{ "lightness": -30 }
]
}
]
});
var data = data.data;
vm.data = data.data;
$log.debug(data);
map.setCenter(data.data.start);
json_data = data.data;
//calculate end and start date
for(var i=0; i < json_data.teams.length; i++) {
for(var n=0; n<json_data.teams[i].posts.length;n++) {
var date = new Date(json_data.teams[i].posts[n].date);
if(end == null || date > end) {
end = date;
}
if(start == null || date < start)
start = date;
}
}
vm.max = getRangeMax(start, end);
vm.time = getRangeMax(start, end);
callback();
});
}
function setMarkers(maxTimestamps) {
//clearMarkers();
clearPaths();
//set team positions
for(var i=0; i < json_data.teams.length; i++) {
var paths = [json_data.start];
if(team_colors != null && team_colors[json_data.teams[i].name])
var color = team_colors[json_data.teams[i].name];
else {
var color = generateColor(json_data.teams[i].name);
team_colors[json_data.teams[i].name] = color;
}
for(var n=0; n<json_data.teams[i].posts.length;n++) {
var post = json_data.teams[i].posts[n];
if(json_data.teams[i].id != vm.team && vm.team != "false") {
toggleMarker(post.id, null);
delete markers[post.id];
continue;
}
if(new Date(post.date) > new Date(maxTimestamps)) {
toggleMarker(post.id, null);
delete markers[post.id];
continue;
} else if(markers[post.id] && markers[post.id].getMap() != null) {
if(swCoord.lng > post.location.lng)
swCoord.lng = post.location.lng;
if(swCoord.lat > post.location.lat)
swCoord.lat = post.location.lat;
if(neCoord.lng < post.location.lng)
neCoord.lng = post.location.lng;
if(neCoord.lat < post.location.lat)
neCoord.lat = post.location.lat;
paths.push({lat:post.location.lat, lng: post.location.lng});
continue;
}
else {
if(swCoord.lng > post.location.lng)
swCoord.lng = post.location.lng;
if(swCoord.lat > post.location.lat)
swCoord.lat = post.location.lat;
if(neCoord.lng < post.location.lng)
neCoord.lng = post.location.lng;
if(neCoord.lat < post.location.lat)
neCoord.lat = post.location.lat;
paths.push({lat:post.location.lat, lng: post.location.lng});
toggleMarker(post.id, map);
}
if(post.picture) {
var image = "<img src='"+post.picture+"'/>";
} else {
var image = null;
}
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h3>'+json_data.teams[i].name+'</h3>'+
'<div id="bodyContent">'+
'<p>'+post.text+'</p>'+
image +
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var Marker = new google.maps.Marker({
position: new google.maps.LatLng(post.location.lat, post.location.lng),
map: map,
animation: google.maps.Animation.DROP,
icon: pinSymbol(color),
title: post.text
});
Marker.addListener('mouseover', function(event, marker) {
infowindow.open(map, this);
});
Marker.addListener('mouseout', function(event, marker) {
infowindow.close();
});
markers[post.id] = Marker;
}
var flightPath = new google.maps.Polyline({
path: paths,
geodesic: true,
strokeColor: color,
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
all_paths.push(flightPath);
}
}
function initialize() {
getData(function() {
setMarkers();
var directionsDisplay = new google.maps.DirectionsRenderer();// also, constructor can get "DirectionsRendererOptions" object
directionsDisplay.setMap(map); // map should be already initialized.
var request = {
origin : new google.maps.LatLng(48.150639, 11.581024),
destination :new google.maps.LatLng(44.714383, 21.581024),
travelMode : google.maps.TravelMode.DRIVING
};
var directionsService = new google.maps.DirectionsService();
//var route = directionsService.route(request, function(response, status) {
// console.log(response);
// if (status == google.maps.DirectionsStatus.OK) {
// directionsDisplay.setDirections(response);
// }
//});
});
}
initialize();
vm.startTimer = function() {
vm.time = 0;
var rangeMax = getRangeMax(start, end);
var interval = $interval(function() {
vm.time += 100;
if(vm.time > rangeMax)
$interval.cancel(interval);
vm.rebuildMarkers(vm.time);
}, 10);
};
}