Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
client.js.otp.widgets.transit.TripViewerWidget.js Maven / Gradle / Ivy
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
otp.namespace("otp.widgets.transit");
otp.widgets.transit.TripViewerWidget =
otp.Class(otp.widgets.transit.RouteBasedWidget, {
module : null,
agency_id : null,
activeLeg : null,
timeIndex : null,
routeLookup : [], // for retrieving route obj from numerical index in element
lastSize : null,
//variantIndexLookup : null,
initialize : function(id, module) {
otp.widgets.transit.RouteBasedWidget.prototype.initialize.call(this, id, module, {
title : _tr('Trip Viewer'),
cssClass : 'otp-tripViewer',
closeable : true,
openInitially : false,
persistOnClose : true,
});
this.module = module;
var this_ = this;
this.stopList = $('
').appendTo(this.mainDiv);
this.scheduleLink = $('
').appendTo(this.mainDiv);
console.log("added sched link");
this.mainDiv.resizable({
minWidth: 200,
alsoResize: this.stopList,
});
},
clear : function() {
this.stopList.empty();
},
variantSelected : function(variantData) {
//console.log("var sel");
//console.log(variantData);
var this_ = this;
this.stopList.empty();
var selectedStopIndex = 0;
for(var i=0; i ').appendTo(this.stopList);
var stopIcon = $('
').appendTo(row);
// use the appropriate line/stop graphic
var lineImg;
if(i == 0) {
lineImg = $(' ');
}
else if(i == this.activeVariant.stops.length - 1) {
lineImg = $(' ');
}
else {
lineImg = $(' ');
}
// append the arrow for the board/alight stop, if applicable
if(this.activeLeg && i == this.activeLeg.from.stopIndex) {
$(' ').appendTo(stopIcon);
}
else if(this.activeLeg && i == this.activeLeg.to.stopIndex) {
$(' ').appendTo(stopIcon);
}
else {
lineImg.css({ marginLeft : 12 });
}
lineImg.appendTo(stopIcon);
// set up the stop name and id/links content
var stopText = $('
').appendTo(row);
$(''+(i+1)+'. '+stop.name+'
').appendTo(stopText);
var idLine = $('
').appendTo(stopText);
var idHtml = '';
if(stop.url) idHtml += '';
idHtml += stop.id; //.agencyId+' #'+stop.id.id;
if(stop.url) idHtml += ' ';
idHtml += ' '
$(idHtml).appendTo(idLine);
//TRANSLATORS: Recenter map on this stop (Shown at each stop in
//Trip viewer
$(' [' + _tr('Recenter') + ' ] ').appendTo(idLine)
.data("stop", stop)
.click(function(evt) {
var stop = $(this).data("stop");
this_.module.webapp.map.lmap.panTo(new L.LatLng(stop.lat, stop.lon));
});
//TRANSLATORS: Link to Stop viewer (Shown at each stop in Trip
//viewer)
$(' [' + _tr('Viewer') + ' ] ').appendTo(idLine)
.data("stop", stop)
.click(function(evt) {
var stop = $(this).data("stop");
if(!this_.module.stopViewerWidget) {
this_.module.stopViewerWidget = new otp.widgets.transit.StopViewerWidget("otp-"+this_.module.id+"-stopViewerWidget", this_.module);
this_.module.stopViewerWidget.mainDiv.offset({top: evt.clientY, left: evt.clientX});
}
this_.module.stopViewerWidget.show();
//this_.module.stopViewerWidget.activeTime = leg.startTime;
this_.module.stopViewerWidget.setStop(stop.id, stop.name);
this_.module.stopViewerWidget.bringToFront();
});
// highlight the boarded stops
if(this.activeLeg && i >= this.activeLeg.from.stopIndex && i <= this.activeLeg.to.stopIndex) {
stopIcon.css({ background : '#bbb' });
}
// set up hover functionality (open popup over stop)
row.data("stop", stop).hover(function(evt) {
var stop = $(this).data("stop");
var latLng = new L.LatLng(stop.lat, stop.lon);
if(!this_.module.webapp.map.lmap.getBounds().contains(latLng)) return;
var popup = L.popup()
.setLatLng(latLng)
.setContent(stop.name)
.openOn(this_.module.webapp.map.lmap);
}, function(evt) {
this_.module.webapp.map.lmap.closePopup();
});
}
// scroll to the boarded segment, if applicable
if(this.activeLeg) {
var scrollY = this.stopList[0].scrollHeight * this.activeLeg.from.stopIndex / (this.activeVariant.stops.length - 1);
this.stopList.scrollTop(scrollY);
}
// update the route link
var url = variantData.route.url;
var html = "";
if(url) html += 'Link to: Route Info ';
// TriMet-specific code
if(url.indexOf('http://trimet.org') === 0) {
var day = "w";
if(this.activeLeg) {
var dow = moment(this.activeLeg.startTime).add("h", -3).day();
if(dow === 0) day = "h";
if(dow === 6) day = "s";
}
var rte = url.substring(29, 32);
var direction = variantData.id.split(':')[2];
html += ' | Timetable ';
}
this.scheduleLink.html(html);
},
});