forked from monsooncollective/yatayat
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
555 lines (518 loc) · 31.1 KB
/
index.html
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<html>
<head>
<title>
Kathmandu Public Transport
</title>
<!--link rel="stylesheet" href="lib/leaflet/leaflet.css" /-->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="lib/yatayat.css" />
<link rel="stylesheet" href="lib/autocomplete_styles.css">
<!--[if lte IE 8]>
<link rel="stylesheet" href="lib/leaflet/leaflet.ie.css" />
<![endif] -->
<!--script src="lib/jquery-1.7.2.min.js"> </script-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<!--<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> -->
<script type="text/javascript" src="lib/jquery.autocomplete.min.js"></script>
<script src="lib/underscore-min.js"> </script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<!--script src="lib/leaflet/leaflet-src.js"> </script-->
<script src="lib/leaflet/spin.min.js"> </script>
<script src="lib/leaflet/leaflet.spin.js"> </script>
<script src="lib\leaflet\Leaflet.PolylineDecorator\leaflet.polylineDecorator.min.js"></script>
<script src="lib/wax.leaf.min.js"> </script>
<script src="lib/kdtree/src/web/kdTree.js"> </script>
<script src="lib/bootstrap/js/bootstrap.min.js"> </script>
<script src="yatayat.js"> </script>
<script src="lib/routeinfopanel.js"> </script>
</head>
<body>
<div id="Title">
Kathmandu Valley Public Transport App
</div>
<div class="alert" id="routedisplay" style="position:absolute;top:60;left:60;z-index:999;width:60%;background-color:rgb(228, 237, 249)">
</div>
<div id="publicTransportMap" style="width:80%; height: 100%">
Loading ...
</div>
<div class="modal hide" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
X
</button>
</div>
<br/>
</div>
<div id="Attribution" style="width:37%; height:3%; position:absolute; bottom:0px; right:20%">
Powered By <a href="http://leaflet.cloudmade.com">Leaflet</a>,
Data © <a href="http://www.openstreetmap.org/copyright/en">OpenStreetMap</a> contributors,
Imagery and bus icon from <a href="http://mapbox.com/">MapBox</a>
</div>
<div class="accordion" id="accordion2" position="absolute" style="width:20%; height: 75%" >
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne"><b>Get Direction</b>
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
<div id="textboxes">
<b style="color: green;">
Start
</b>
<input type="text" id="startstop" class="typeahead" data-provide="typeahead" style="color: green;">
<b style="color: rgb(0,57,166);">
End
</b>
<input type="text" id="endstop" class="typeahead" data-provide="typeahead" style="color:rgb(0,57,166)" /><br>
<a class="btn" id="go"> GO </a>
<a class="btn" id="swap">Swap</a>
<a class="btn" onclick="$('.typeahead').val(''); $('#routedisplay').hide(); YY._routeGroup.clearLayers();YY.render_(system,map);"> Clear </a>
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Routes
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
<div id="routename">
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#accordion2" href="bhadadar.html" target="_blank">
Bus Fare
</a>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2"
href="#collapse3">
About Us
</a>
</div>
<div id="collapse3" class="accordion-body collapse">
<div class="accordion-inner">
<b>Designed By:</b> <br/>
<a href="http://ku.edu.np/dcge/mission.htm">Kathmandu University Geomatics</a> and <a href="http://Monsooncollective.org"> Monsoon Collective </a> <br/>
<b>KU contributors:</b> <a href="https://twitter.com/neogeomat" target="_blank">Amrit Karmacharya</a>,<a href="https://twitter.com/SureshSuress" target="_blank">Suresh Shrestha</a>, Prabesh Shrestha, <a href="https://twitter.com/Ghimire07" target="_blank">Prakash Ghimire</a>, Amrit Gautam, <a href="https://twitter.com/_shashish_" target="_blank">Shashish Maharjan</a>, Subash Ghimire. <br/>
<b>Monsoon Collective contributors:</b> <a href="https://twitter.com/prabhasp" target="_blank">Prabhas Pokharel</a>, Robert Ochshorn, Sakar Pudasaini, Suveg Pandey, Shirish Pokharel, Anshu Khadka. <br/>
<b>KathmanduLivingLabs contributors:</b> <a href="https://twitter.com/neogeomat" target="_blank">Amrit Karmacharya</a>,<a href="https:twitter.com/https://twitter.com/PoshanNiraula1">Poshan Niraula</a>
<b>Coordinated By:</b> <a href="https://twitter.com/neogeomat" target="_blank">Amrit Karmacharya</a> and <a href="https://twitter.com/prabhasp" target="_blank">Prabhas Pokharel</a><br/><br/>
The project was started by the Monsoon Collective; KU students have futher developed it. Currently KathmanduLivingLabs is maintaining it.<br>
Refer to this <a href="http://wiki.openstreetmap.org/wiki/Nepal/Yatayat" target="_blank">wiki</a> for more information
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse4">
How to use
</a>
</div>
<div id="collapse4" class="accordion-body collapse">
<div class="accordion-inner">
<h2>
For ROUTING
</h2>
<h4>
One Option :
</h4>
<p>
You can generally write the start stop name and then end stop name.This
gives you the route from the start point to end point through the public
transport route available. It can be clearly viewed on the map along with
the different stops and its name in going through the route.
</p>
<h4>
Next Option :
</h4>
<p>
You can directly click at the stop and choose it as start stop and the
required end stop in the map which can also show the route on map. You
can also set the another start or end stop directly on the map.
</p>
<h2>
For Specific Route Viewing
</h2>
<p>
You can first click on the link ROutes Of Kathmandu. Then click on the
respective route which you want to see. You can view it on the map with
the selected route zoomed in.
</p>
<p>
You can again click on the next route to see the next route.
</p>
<h2>
For Finding Location
</h2>
<p>
You can search the place by clicking the search bar on the top right corner
next to the zoom bar.
</p>
<p>
There you can write the place of the name to search.
</p>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2"
href="#collapse5">
Help us Improve
</a>
</div>
<div id="collapse5" class="accordion-body collapse">
<div class="accordion-inner">
<iframe src="https://docs.google.com/forms/d/1HKyiRd_6WbKv8xOW243-0J9HRzOT7muQsC8nG30llJw/viewform?embedded=true" width="250" height="500" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
</div>
</div>
</div>
</div>
<div id="mydiv">
<div id="myCarousel" class="carousel slide" >
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item"><img src="s-bus.jpg" width="262 px" height="182"></div>
<div class="item"><img src="tempo.jpg"width="262 px" height="182"></div>
<div class="item"><img src="micro.jpg"width="262 px" height="182"></div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</div>
<script type="text/javascript" language="javascript">
// UI HACK
$('#textboxes').hide();
$('#routedisplay').hide();
// initialize the map
var map = new L.Map('publicTransportMap');
//var ktmBB = "85.2885,27.6839,85.3368,27.7299";
var system;
var osmdata;
var routed;
var routed_route;
YY.fromConfig("config.stable.json", function(sys) {
system = sys;
YY.render_(system, map, undefined, //includeIDObject; try {"2269045": true} for an example
undefined // leafletBaseOptions
);
//ROUTING
var stopNames = _.compact(_.pluck(system.allStops(), 'name'));
// var delay = 200;
var stopnamesdict = [];
var i = 0;
_.each(stopNames, function(stopNames) {
stopnamesdict.push({data:stopNames,value:stopNames})
i=i+1;
});
var stopNames = _.compact(_.pluck(system.allStops(), 'name'));
$('.typeahead').typeahead({
source: stopNames,
minLength: 3,
items: 5
});
$('#textboxes').show();
// $('input.typeahead').change(function(f) {
$('#swap').click(function(){
// console.log("last ramailo");
temp = $('#startstop')[0].value;
$('#startstop')[0].value = $('#endstop')[0].value;
$('#endstop')[0].value = temp;
$('#go').click();
})
$('#go').click(function(){
map.spin(true);
var start = $('#startstop')[0].value;
var end = $('#endstop')[0].value;
var dist = 0;
if (start && end) {
if (!YY._routeGroup) {
YY._routeGroup = new L.LayerGroup().addTo(map);
}
YY._routeGroup.clearLayers();
if (!YY._routeGroupDirection) {
YY._routeGroupDirection = new L.LayerGroup().addTo(map);
}
YY._routeGroupDirection.clearLayers();
var gettingThereRoutes = system.takeMeThereByName(start, end);
routed = gettingThereRoutes;
var bounds = new L.LatLngBounds();
if (gettingThereRoutes === 'FAIL') alert('cannot find a route from ', start, ' to ', end);
else {
var inclusionDict = {};
var overrideDict = {};
var outputHTML = "";
_(system.routes).each(function(r) {
inclusionDict[r.id] = true;
}); // render everything
counter = 0;
_(gettingThereRoutes).each(function(eachroute, idx) {
//show routed route
var endseg = [];
// find the direction of eachroute compared to original route direction
originalroute = system.routeDict[eachroute.id];
var direction;
if(originalroute.stops.indexOf(eachroute.stops[0])<originalroute.stops.indexOf(_.last(eachroute.stops))){
direction = 1;
}else{
direction = -1;
}
var startsegid, endsegid;
var startsegindex,endsegindex;
// finding index of first and last segment in list of segment
segmentorderindex = _.map(eachroute.segments,function(r){return r.id});
startsegidnew = system.stopToSegDict[eachroute.stops[0].id]; //list of osmid
if(direction == -1){
for(startsegindex = segmentorderindex.indexOf(_.min(startsegidnew));startsegindex == -1;){
startsegidnew.splice(startsegidnew.indexOf(_.min(startsegidnew)),1);
startsegindex = segmentorderindex.indexOf(_.min(startsegidnew));
}}else if (direction == 1) {for(startsegindex = segmentorderindex.indexOf(_.max(startsegidnew));startsegindex == -1;){
startsegidnew.splice(startsegidnew.indexOf(_.max(startsegidnew)),1);
startsegindex = segmentorderindex.indexOf(_.max(startsegidnew));
}};
endsegidnew = system.stopToSegDict[_.last(eachroute.stops).id]; //list of osmid
if(direction == -1){
for(endsegindex = segmentorderindex.indexOf(_.max(endsegidnew));endsegindex == -1;){
endsegidnew.splice(endsegidnew.indexOf(_.max(endsegidnew)),1);
endsegindex = segmentorderindex.indexOf(_.max(endsegidnew));
}}
else if(direction == 1){
for(endsegindex = segmentorderindex.indexOf(_.min(endsegidnew));endsegindex == -1;){
endsegidnew.splice(endsegidnew.indexOf(_.min(endsegidnew)),1);
endsegindex = segmentorderindex.indexOf(_.min(endsegidnew));
}}
// console.log("startsegindex",startsegindex,"endsegindex",endsegindex);
// debugger;
// swap if startsegindex is greater
//actually drawing the route
var defaultOptions = {
"route": function(idx) {
if(idx == 0){
color = "rgb(0,155,58)";
}else if(idx == 1){
color = "rgb(255,99,25)";
}else if(idx == 2){
color = "rgb(0,57,166)";
}else{
color = get_random_color();
}
return {
color:color,
opacity: 1,
weight: 10
};
},
"stop": {
color: '#378AAD',
fillOpacity: 0.5,
radius: 5
}
};
var eachroutestyleoption = function(idx){return defaultOptions.route(idx)};
dist = 0;
var endsegmentrender = function (enddirection , segindex , station) {
var insert, shift, thisSeg, nextSeg;
if(enddirection=="first"){
thisSeg = eachroute.segments[segindex], nextSeg = eachroute.segments[segindex + direction];
if(typeof nextSeg === "undefined"){
// debugger;
nextSeg = eachroute.segments[segindex - direction];
}
} else if (enddirection == "last") {
thisSeg = eachroute.segments[segindex], nextSeg = eachroute.segments[segindex - direction];
if(typeof nextSeg === "undefined"){
// debugger;
nextSeg = eachroute.segments[segindex + direction];
}
};
// debugger;
var thisSegFirst = thisSeg.listofnodeids[0];
var thisSegLast = _.last(thisSeg.listofnodeids);
var nextSegFirst = nextSeg.listofnodeids[0];
var nextSegLast = _.last(nextSeg.listofnodeids);
// finding the common node in joined segments
var commonNode;
if(thisSegFirst == nextSegFirst){
commonNode = thisSegFirst;
}else if (thisSegFirst == nextSegLast) {
commonNode = thisSegFirst;
}else if (thisSegLast == nextSegFirst) {
commonNode = thisSegLast;
}else if (thisSegLast == nextSegLast) {
commonNode = thisSegLast;
};
console.log("thisSeg",'http://www.openstreetmap.org/browse/way/'+thisSeg.id,"nextSeg",'http://www.openstreetmap.org/browse/way/'+nextSeg.id,"commonNode",'http://www.openstreetmap.org/browse/node/'+commonNode);
insert = thisSeg.listofnodeids.indexOf(station.id)<thisSeg.listofnodeids.indexOf(commonNode);
insert?shift=1:shift=-1;
partofsegment = [];
for(i=thisSeg.listofnodeids.indexOf(station.id);i !== thisSeg.listofnodeids.indexOf(commonNode);i=i+shift){
partofsegment.push(thisSeg.dictofnodes[thisSeg.listofnodeids[i]]);
}
// debugger;
// return _.union(partofsegment);
if(insert){
return _.union(partofsegment,_.map(nextSeg.listofnodeids,function(n){return nextSeg.dictofnodes[n]}));}else{
return _.union(_.map(nextSeg.listofnodeids,function(n){return nextSeg.dictofnodes[n]}),partofsegment);
}
};
firstsegmentpart = endsegmentrender("first",startsegindex,eachroute.stops[0]);
if(firstsegmentpart.length){
var segMPLfirst = new L.Polyline(firstsegmentpart, eachroutestyleoption(idx));
segMPLfirst.bindPopup("<a href='http://www.openstreetmap.org/browse/way/" + startsegid + "' target='_blank'>");
var arrow = new L.polylineDecorator(segMPLfirst, {
patterns: [{
offset: 25,
repeat: 50,
symbol: L.Symbol.arrowHead({
pixelSize: 15,
pathOptions: {
fillOpacity: 1,
weight: 0
}
})
}]
});
YY._routeGroupDirection.addLayer(arrow);
YY._routeGroup.addLayer(segMPLfirst);
// map.addLayer(YY._routeGroup);
}
lastsegmentpart = endsegmentrender("last",endsegindex,_.last(eachroute.stops));
if(lastsegmentpart.length){
var segMPLlast = new L.Polyline(lastsegmentpart, eachroutestyleoption(idx));
segMPLlast.bindPopup("<a href='http://www.openstreetmap.org/browse/way/" + startsegid + "' target='_blank'>");
var arrow = new L.polylineDecorator(segMPLlast, {
patterns: [{
offset: 25,
repeat: 50,
symbol: L.Symbol.arrowHead({
pixelSize: 15,
pathOptions: {
fillOpacity: 1,
weight: 0
}
})
}]
});
YY._routeGroupDirection.addLayer(arrow);
YY._routeGroup.addLayer(segMPLlast);
// map.addLayer(YY._routeGroup);
}
var segment_direction;
startsegindex < endsegindex ? segment_direction = 1 : segment_direction = -1;
for (var segid = startsegindex + segment_direction; segid != endsegindex; segid+=segment_direction) {
// console.log("segid",segid);
seg = eachroute.segments[segid];
if(typeof seg === "undefined"){}else{
if(seg.listOfLatLng.length){
var segMPL = new L.Polyline(_.map(seg.listOfLatLng,function(arr){return {lat:parseFloat(arr[0]),lon:parseFloat(arr[1])}}), eachroutestyleoption(idx));
segMPL.bindPopup("<a href='http://www.openstreetmap.org/browse/way/" + seg.id + "' target='_blank'>" + seg.id + "</a>," + segid + "");
var arrow = new L.polylineDecorator(segMPL, {
patterns: [{
offset: 25,
repeat: 50,
symbol: L.Symbol.arrowHead({
pixelSize: 15,
pathOptions: {
fillOpacity: 1,
weight: 0
}
})
}]
});
YY._routeGroupDirection.addLayer(arrow);
YY._routeGroup.addLayer(segMPL);
// map.addLayer(YY._routeGroup);
}
// debugger;
// console.log(YY._routeGroup);
for (i = 0; i < (seg.listOfLatLng.length) - 1; i++) {
dist += distanc(seg.listOfLatLng[i][0], seg.listOfLatLng[i][1], seg.listOfLatLng[i + 1][0], seg.listOfLatLng[i + 1][1]);
}
}
}
map.removeLayer(YY._routeGroup);
map.addLayer(YY._routeGroup);
if(dist>200){
outputHTML += "<div style=\"color:"+eachroutestyleoption(idx).color+"; width=65%; top:60; font-family:cursive;\">Get on " + toTitleCase(eachroute.transport) + " " + removeundefinedstrings(eachroute.ref) + " (" + eachroute.name + ") at " + eachroute.stops[0].name + " and ride till " + _.last(eachroute.stops).name + " with distance of " + Math.round(dist)/1000 + " km" + "</div>";}
else{
outputHTML += "<div style=\"color:"+eachroutestyleoption(idx).color+"; width=65%; top:60; font-family:cursive;\">Walk from " + eachroute.stops[0].name + " to " + _.last(eachroute.stops).name + " with distance of " + Math.round(dist) + " m" + "</div>";
}
}
);
YY._routeGroup.eachLayer(function(el){
for (var i = 0; i <= el._latlngs.length; i++) {
bounds.extend(el._latlngs[i]);
};
});
map.fitBounds(bounds);
//sures
YY.render_(system, map, inclusionDict, {
route: {
color: '#378AAD',
opacity: 1,
weight: 1
}
// stop: {color: '#378AAD', fillOpacity: 0.5, radius: 5}
}, overrideDict);
$('#routedisplay').show();
$('#routedisplay').html(outputHTML);
map.spin(false);
}
}
else {
YY.render_(system, map);
$('#routedisplay').hide()
map.spin(false);
}
});
routeinfopanel(system.routeDict);
if (YY.TILE_SOURCE) {
if (YY.WAX) {
wax.tilejson(YY.TILE_SOURCE, function(tilejson) {
map.addLayer(new wax.leaf.connector(tilejson));
});
} else {
var tiles = new L.TileLayer(YY.TILE_SOURCE, {
attribution: YY.ATTRIBUTION
});
map.addLayer(tiles);
}
}
map.setView(new L.LatLng(YY.LAT, YY.LNG), 13);
L.control.scale().addTo(map);
//auto init routing at start
// document.getElementById("startstop").value ="Thimi";
// document.getElementById("endstop").value ="Chardobato";
// $('#go').click();
});
function get_random_color() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.round(Math.random() * 15)];
}
return color;
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
function removeundefinedstrings(str){
return str?str:"";
}
</script>
</body>
</html>