/** * chk_kiosk_dart * * Contains data items specific to dart under the chk.d namespace. */ var chk = chk || {}; chk.dart = chk.dart || {}; chk.agency = chk.dart; { var AGC = chk.dart; AGC.id = 'DART'; AGC.default_stopid = '29824'; AGC.title = "DART"; AGC.default_heading = null; AGC.default_lonlat = null; AGC.logo = "images/agency_custom/dart/dart-logo.gif"; AGC.logo_top_offset = '1px'; AGC.logo_width = '111px'; AGC.logo_height = '79px'; AGC.sms_example_number = '2145551234'; AGC.places = chk.dart.places || {}; AGC.osm_tile_url_base = "http://portauthority.mytransit.info:8010/"; AGC.osm_tile_urls = [chk.dart.osm_tile_url_base + "${z}/${x}/${y}.png"]; AGC.osm_zooms = {low:11,high:18}; AGC.osm_bounds = [-80.711,40.023,-79.249,40.88]; AGC.mappoints_options = { agency: 2, /*in uat, agency 3 dallas, 2 PAAC*/ /*cpam_url: "http://localhost/cpam/mappoint/server/landmarks/"*/ cpam_url: "http://cpam.mytransit.info/uat/mappoint/server/landmarks/" } } chk.dart.tb_image_base = 'images/agency_custom/paac/WoodStTrailblazers/PAT-woodst-trailblazer_'; chk.dart.static_trailblaze_urls = { 'P02550': chk.dart.tb_image_base + 'liberty-wood.png', 'P02310': chk.dart.tb_image_base + 'liberty-seventh.png', 'P00750': chk.dart.tb_image_base + 'sixth-wood.png', 'P03690': chk.dart.tb_image_base + 'wood-sixth.png', 'P02280': chk.dart.tb_image_base + 'liberty-sixth.png', 'P02320': chk.dart.tb_image_base + 'liberty-tito.png', 'P03693': chk.dart.tb_image_base + 'wood-sixth-fs.png', 'P70020': chk.dart.tb_image_base + 'rail-station.png', 'P70021': chk.dart.tb_image_base + 'rail-station.png', 'P02600': chk.dart.tb_image_base + 'liberty-9th.png', 'P03075': chk.dart.tb_image_base + 'smithfield-fifth.png' } chk.dart.static_trailblaze = function(stopid) { console.log('static_trailblaze',stopid); return chk.dart.static_trailblaze_urls[stopid]; } chk.dart.kiosk_stop_icon_for_route = function(route_data) { return { url: chk.dart.create_route_image(route_data), size: {w:25, h:25} }; /* return route_data.type == 1 ? { url: "/images/agency_custom/paac/stop-train.png", size: {w:25, h:25} } : { url: "/images/agency_custom/paac/stop-bus.png", size: {w:25, h:25} }; */ } var google = google || false; if( google ) // We are trip planning { var P = chk.dart.places; P.place_1 = { name: "Carnegie Mellon University", geometry: {location: new google.maps.LatLng(40.442492,-79.942553)} }; chk.dart.startpoint = chk.dart.places.place_1; chk.dart.endpoint = chk.dart.places.place_1; chk.dart.bounds = new google.maps.LatLngBounds( new google.maps.LatLng(chk.dart.osm_bounds[1],chk.dart.osm_bounds[0]), new google.maps.LatLng(chk.dart.osm_bounds[3],chk.dart.osm_bounds[2]) ); } chk.dart.getAgencyID = function() { return chk.dart.id; } /** * The headsign_map normalizes data from the GTFS file. * In case the headsign does not start with the route number * or in case there is a duplicate way the headsign is stored. */ chk.dart.headsign_map = { // Example -- "Fairview Center" : "7 Fairview Center", }; /** * routes provides to customizable information on each route (by number) * to be displayed on the kiosk. */ chk.dart.custom_routes = {}; chk.dart.realtime_stopidconvert = function(stpid) { var x = chk.dart.stops_by_code && chk.dart.stops_by_code[stpid]; return x || stpid; } chk.dart.realtime_timeconvert = function(prdtm) { var x = prdtm.split(" "); var y = x[0].slice(0,4); var m = x[0].slice(4,6); var d = x[0].slice(6,8); var t = x[1] + " EDT"; var dt = m + " " + d + " " + y + " " + t; //return dt; return Date.parse(dt)/1000; } chk.dart.realtime_success = function( data, status, xhr ) { console.log('chk.dart.realtime_success',data,status,xhr); $.getScript('/js/agency_custom/xml2json.js', function() { var jdata = JSON.parse(xml2json(data,' ')); var prd = jdata && jdata['bustime-response']; prd = prd && prd.prd; if( prd && !Array.isArray(prd) ) prd = [prd]; var realtime_data = []; for( i in prd ) { var p = prd[i]; var d = { direction: p.rtdir, phase: p.typ, route: p.rt, stopid: chk.dart.realtime_stopidconvert(p.stpid), time: chk.dart.realtime_timeconvert(p.prdtm), time_text: p.prdtm, trip: { blockid: p.tablockid, directionId: p.rtdir, id: { id: p.tatripid }, route: { id: {id: p.tablockid}, shortName: p.rt }, routeId: { id: p.tablockid } } }; realtime_data.push(d); } if( chk.dart.realtime_cb ) chk.dart.realtime_cb(realtime_data); }); } chk.dart.realtime_error = function( xhr, status, error ) { console.log('chk.dart.realtime_error',xhr,status,error); if( chk.dart.realtime_cb ) chk.dart.realtime_cb(null); } chk.dart.realtime_request = function(data_callback) { chk.dart.realtime_cb = data_callback || chk.dart.realtime_cb; var stops = chk.requestedStops && chk.requestedStops.byId; if( !stops ) { setTimeout(chk.dart.realtime_request,1000); return; } var URL = "/js/agency_custom/realtime_paac.xml.php"; var out = ""; var keys = Object.keys(stops); for( var i in keys ) { if( i > 0 ) out += ","; if( i > 9 ) break; // No more than 10 allowed on paac request. In the future do multiple requests. out += stops[keys[i]].stopCode; } var query = { stpid: out } var result = $.ajax({type: 'POST', url: URL, data: query, dataType: 'xml', context: query, success: chk.dart.realtime_success, error: chk.dart.realtime_error}); } /** * This is a helper to chk.houston.requestRoutes * it sets the global chk.houston.route_numToId for converting routeShortName to otp_internal_route_id * * I am preferring to access the route by routeShortName (ie: 12X or 11 or 1) * but OTP prefers to access the route by it's own internal id * this helper function create a conversion context. */ /* chk.dart.set_numToId = function( data, status, xhr ) { out = {}; byid = {}; for( i in data.routes ) { r = data.routes[i]; out[r.routeShortName]=r.id.id; byid[r.id.id] = r; } chk.dart.route_numToId = out; chk.dart.routes_by_id = byid; if( this.cb ) this.cb.call(this,data.routes); }*/ chk.dart.getDefaultRoute = function() { return null; var r = chk.dart.routesForStop; if( r ) return r[Object.keys(r)[0]].routeShortName; return "001"; } chk.dart.setDefaultRoute = function(routes) { chk.dart.routesForStop = routes; } /** * This will request the list of routes specific for houston * @param cb - the callback = function(routes) to call when processing is complete * - chk.houston.route_numToId will have been initialized before cb is called. * - */ /* chk.dart.requestRoutes = function(cb) { var url = chk.get_OTP_BASE_URL() + 'routes'; var query = {agency:chk.dart.id , extended:true}; var ctx = {query:query, cb:cb}; var result = $.ajax({url: url, data: query, context: ctx, success: chk.dart.set_numToId}); } */ /** * the ignore field should have three entries * stops - an array of stop_ids to ignore * routes - an array or route_ids to ignore * trips - an array of trip_ids to ignore * * this functionality was added because discrepencies were found in the gtfs data. * rather than modifying the gtfs, this functionality was added. */ chk.dart.ignore = chk.dart.ignore || {}; chk.dart.ignore.stops = []; chk.dart.ignore.routes = []; chk.dart.ignore.trips = []; chk.dart.stop_icon = { "start" : 'images/badges/austin_stop.svg', "upto" : 'images/badges/austin_stop.svg', "at" : 'images/badges/austin_stop.svg', "after" : 'images/badges/austin_stop.svg', "end" : 'images/badges/austin_stop.svg', "multi" : 'images/badges/austin_stop.svg', "start_end" : 'images/badges/austin_stop.svg', "start_end_at" : 'images/badges/austin_stop.svg', "loop" : 'images/badges/austin_stop.svg', "off" : 'images/badges/austin_stop.svg', "selected" : 'images/badges/austin_stop_selected.svg', "selected_start_end" : 'images/badges/austin_stop_selected.svg' } chk.dart.roundRect = function(ctx,x,y,w,h,r) { ctx.beginPath(); ctx.moveTo(x+r,y); ctx.lineTo(x+w-r,y); ctx.quadraticCurveTo(x+w,y,x+w,y+r); ctx.lineTo(x+w,y+h-r); ctx.quadraticCurveTo(x+w,y+h,x+w-r,y+h); ctx.lineTo(x+r,y+h); ctx.quadraticCurveTo(x,y+h,x,y+h-r); ctx.lineTo(x,y+r); ctx.quadraticCurveTo(x,y,x+r,y); ctx.closePath(); } chk.dart.created_images = {} chk.dart.create_route_image = function(route_data) { var color = "#" + (route_data.color || route_data.routeColor || "BBB"); var text = route_data.shortName || route_data.routeShortName || "???"; var index = "" + text + color; var img=chk.dart.created_images[index]; if(img) return img; text = text + ""; fontsize = 24; if(text.length > 4) fontsize = parseInt(24 * 4 / text.length); switch( text.charAt(0) ) { case 'B': text = "Blue"; break; case 'R': text = "Red"; break; } var can = $( '' )[0]; var ctx = can.getContext('2d'); ctx.fillStyle=color; ctx.strokeStyle='white'; ctx.lineWidth = 1; ctx.beginPath(); chk.dart.roundRect(ctx,0,11,70,48,12); ctx.fill(); //ctx.stroke(); ctx.fillStyle = 'white'; ctx.strokeStyle='white'; ctx.lineWidth = 1; ctx.font = 'bold ' + fontsize + 'px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(text, 35, 35); //ctx.strokeText(text, 35, 35); return (chk.dart.created_images[index] = can.toDataURL()); } chk.dart.gtfs_color_switch = function(color) { console.log('color',color); return color; } chk.dart.reformat_stoptimes = function(stopTimes,routes) { var rbyid = {}; for( var i in routes ) { rbyid[routes[i].id.id] = routes[i] }; for(var s in stopTimes) { var st = stopTimes[s]; var rid = st.trip.routeId.id; var r = rbyid[rid]; st.route = r.shortName; st.service = r.longName; st.color = r.color = chk.dart.custom_route_color(r.shortName); st.icon = chk.dart.create_route_image(r,1.0); var t = st.trip.tripHeadsign; t = t.replace(/(-)/g," "); t = t.replace(/^(.*bound\s)/, ""); t = t.replace(r.longName.replace(/(-)/," ").toUpperCase(),""); st.trip.tripHeadsign = t || " "; } stopTimes.sort( function(a,b){return a.time-b.time || a.route.replace(/\D/g,'')-b.route.replace(/\D/g,'') }); } chk.dart.custom_route_color = function(id) { switch(id.charAt(0)) { case 'R': return 'E1221A'; case 'B': return '007CBF'; case 'Y': return 'FBB900'; case 'G': return '00A13A'; case 'P': return '840E65'; case 'O': return 'EF7C00'; default: if( id == '28X' ) return '5DC4E9'; return '8099A9'; } } chk.dart.getTransitLineColor = function(line_data) { return "#" + chk.dart.custom_route_color(line_data.short_name); } chk.dart.isLocalLine = function(line_data) { console.log('local line',line_data); return true || line_data.agencies[0].name.matches(/^Port Authority/); } chk.dart.getRouteCustom = function(route_data) { if(!route_data) return route_data; var id = route_data.routeShortName; route_data.routeColor = chk.dart.custom_route_color(id); if( !route_data.icon ) route_data.icon = chk.dart.create_route_image(route_data,70); //console.log('getRouteCustom',route_data); var h = route_data.headsign; return route_data; } chk.dart.getRouteByShortName = function(route_sn) { var r = chk.dart.routes_by_id[chk.dart.route_numToId[route_sn]]; return chk.dart.getRouteCustom(r); } chk.dart.Camel_Case = function(s) { var l = function(m,u,v) { return u + v.toLowerCase(); } s = s.replace(/(\b\w)(\w{2,})/g, l); s = s.replace(/((\s)*\/(\s)*)/g, " / "); s = s.replace(/(\sAT\s)/g, " at "); s = s.replace(/(\sTO\s)/g, " to "); s = s.replace(/(\sVia\s)/g, " via "); s = s.replace(/(\sCtr)/g, " Center"); s = s.replace(/(\sPgh Int\'L Airport)/g, "PGH International"); s = s.replace(/(Mckee)/g, "McKee"); s = s.replace(/(\sAve\s)/g, " Avenue "); s = s.replace(/(\sAV)/g, " Avenue"); s = s.replace(/(\sST)/g, " Street"); s = s.replace(/(0ak)/g, "Oak"); s = s.replace(/(\sCcac\sBoyce)/g, " CCAC Boyce Campus"); return s; } chk.dart.reformat_route_headsign = function(h) { return chk.dart.Camel_Case(h); } chk.dart.reformat_route_service = function(s) { return chk.dart.Camel_Case(s); } chk.dart.reformat_stop_name = function(s) { return chk.dart.Camel_Case(s); } chk.dart.custom_you_are_here = { width: 76, height: 152, offset_x: -38, offset_y: -152, url: 'images/agency_custom/paac/you_are_here.png' } /** * End of chk_kiosk_austin.js */