﻿var routePolyline;var stops;Stop=function(id,name,type,marker){this.J=id;this._name=name;this._type=type;this._marker=marker;};Stop.prototype={B:function(){return this.J;},getName:function(){return this._name;},getType:function(){return this._type;},j:function(){return this._marker;},L:function(id){this.J=id;},setName:function(name){this._name=name;},setType:function(type){this._type=type;},setMarker:function(marker){this._marker=marker;}};Stop.registerClass('Stop',null,Sys.IDisposable);Stops=function(){this.stopArray=new Array();};Stops.prototype={findStopByMarker:function(marker){for(index=0;index<this.stopArray.length;index++)if(this.stopArray[index].j()==marker)return this.stopArray[index];return null;},findStopById:function(id){for(index=0;index<this.stopArray.length;index++)if(this.stopArray[index].B()==id)return this.stopArray[index];return null;},addStop:function(id,name,type,lat,lng){var stopIcon;if(type=="metro"){stopIcon=new GIcon(false,"images/metro_stop_small.png");stopIcon.iconSize=new GSize(40,46);stopIcon.iconAnchor=new GPoint(8,34);stopIcon.transparent="images/metro_stop_small_transparent.png";stopIcon.imageMap=[10,10,10,24,17,24,17,35,19,35,19,24,24,24,24,10,10,10];}else{if(type=="tram")stopIcon=new GIcon(false,"images/tram_stop_small.png");else stopIcon=new GIcon(false,"images/bus_stop_small.png");stopIcon.iconSize=new GSize(40,46);stopIcon.iconAnchor=new GPoint(8,34);stopIcon.transparent="images/bus_stop_small_transparent.png";stopIcon.imageMap=[8,10,8,34,10,34,10,21,31,21,31,10,8,10];}this.stopArray[this.stopArray.length]=new Stop(id,name,type,new GMarker(new GLatLng(lat,lng),{icon:stopIcon,clickable:true,draggable:false}));map.addOverlay(this.stopArray[this.stopArray.length-1].j());},clearStops:function(){for(var i=this.stopArray.length-1;i>=0;i--){map.removeOverlay(this.stopArray[i].j());this.stopArray[i]=null;}this.stopArray=new Array();stopPopupStop=null;stopPopupMarker=null;stopPopupDiv.style.visibility="hidden";}};Stops.registerClass('Stops',null,Sys.IDisposable);function displayRoute(route,direction){if(routePolyline)try{map.removeOverlay(routePolyline);}catch(error){}GDownloadUrl("Query.aspx?type=route&line="+route+"&direction="+direction,drawRoute);};function displayStops(route,direction){stops.clearStops();GDownloadUrl("Query.aspx?type=stoplocations&line="+route+"&direction="+direction,setStopMarkers);};function drawRoute(text){var strings=text.split("\r\n");routePolyline=new GPolyline.fromEncoded({color:"#ff0000",weight:12,opacity:0.45,points:strings[0],levels:strings[1],zoomFactor:2,numLevels:18});map.addOverlay(routePolyline);};function setStopMarkers(text){var tokens;var stopLines=text.split("\r\n");for(var i=0;i<stopLines.length;i++){tokens=stopLines[i].split(";");if(tokens!=null&&tokens.length>=2){stops.addStop(tokens[0],"","bus",tokens[1],tokens[2]);}}};function onShowRouteClick(){if(checkboxRoute.checked)displayRoute(vehiclePopupVehicle.K(),vehiclePopupVehicle.H());else{if(routePolyline)try{map.removeOverlay(routePolyline);}catch(error){}}};function onShowStopsClick(){if(checkboxStops.checked)displayStops(vehiclePopupVehicle.K(),vehiclePopupVehicle.H());else stops.clearStops();};function onSelectStop(stopId){if(stopPopupStop!=null){if(stopPopupStop.getType()=="tram")stopPopupStop.j().setImage("images/tram_stop_small.png");else if(stopPopupStop.getType()=="metro")stopPopupStop.j().setImage("images/metro_stop_small.png");else stopPopupStop.j().setImage("images/bus_stop_small.png");}if(stops.findStopById(stopId)==null)Services.GetStopById(stopId,onStopsReceived);displayStopPopup(stopId);};function displayStopPopup(stopId){stopPopupStop=stops.findStopById(stopId);if(stopPopupStop==null){stopPopupStop=stopPopupStop;setTimeout("displayStopPopup("+stopId+")",1000);}else{stopPopupMarker=stopPopupStop.j();if(stopPopupStop.getType()=="tram")stopPopupMarker.setImage("images/tram_stop_small_selected.png");else if(stopPopupStop.getType()=="metro")stopPopupMarker.setImage("images/metro_stop_small_selected.png");else stopPopupMarker.setImage("images/bus_stop_small_selected.png");setStopPopup();updateStopPopupLocation();stopPopupDiv.style.visibility="visible";}};function addStopsByName(name){if(name!="")Services.GetStopsByName(name,onStopsReceived);};function onStopsReceived(text){var rows=text.split("\r\n");stops.clearStops();for(var i=0;i<rows.length;i++){tokens=rows[i].split(";");if(tokens.length>=4){stops.addStop(tokens[0],"",tokens[3],tokens[1],tokens[2]);if(i==0)map.setCenter(new GLatLng(tokens[1],tokens[2]),16);}}};function viewLocation(latlng){map.setCenter(latlng,16);addressMarker.setPoint(latlng);var southWest=map.getBounds().getSouthWest();var northEast=map.getBounds().getNorthEast();Services.GetStopsInArea(southWest.lat(),southWest.lng(),northEast.lat(),northEast.lng(),onStopsReceived);}