﻿var imageUrl;var imageDirection;var index;var currentTime;Vehicle=function(id,line,direction,type,lat,lng,g,marker,lastStop,currentStop,vehType,name,transportOperator,speed){this.J=id;this.F=line;this.m=direction;this._type=type;this._lat=lat;this._lng=lng;this.t=g;this._marker=marker;this._lastStop=lastStop;this._currentStop=currentStop;this._updateTime=new Date();this._vehType=vehType;this._transportOperator=transportOperator;this._name=name;this._speed=speed;};Vehicle.prototype={B:function(){return this.J;},K:function(){return this.F;},H:function(){return this.m;},getType:function(){return this._type;},getLat:function(){return this._lat;},getLng:function(){return this._lng;},C:function(){return this.t;},j:function(){return this._marker;},getLastStop:function(){return this._lastStop;},getCurrentStop:function(){return this._currentStop;},n:function(){return this._updateTime;},L:function(id){this.J=id;},G:function(line){this.F=line;},r:function(direction){this.m=direction;},setType:function(type){this._type=type;},setLat:function(lat){this._lat=lat;},setLng:function(lng){this._lng=lng;},A:function(g){this.t=g;},setMarker:function(marker){this._marker=marker;},setLastStop:function(lastStop){this._lastStop=lastStop;},setCurrentStop:function(currentStop){if(vehiclePopupVehicle!=null)if(currentStop!=this._currentStop&&vehiclePopupVehicle.B()==this.B())setVehiclePopup();this._currentStop=currentStop;},o:function(updateTime){this._updateTime=updateTime;},setName:function(name){this._name=name;},setOperator:function(transportOperator){this._transportOperator=transportOperator;},setVehType:function(vehType){this._vehType=vehType;},setSpeed:function(speed){this._speed=speed;},getOperator:function(){return this._transportOperator;},getSpeed:function(){return this._speed;},getVehType:function(){return this._vehType;},getName:function(){return this._name;},updateIcon:function(){imageUrl;imageDirection=Math.round(this.C()/45)*45;if(imageDirection>315)imageDirection=0;if(this.getType()=="tram")imageUrl="images/vehicles/tram"+imageDirection;else if(this.getType()=="metro")imageUrl="images/vehicles/metro"+imageDirection;else if(this.getType()=="tuomaalaTnt")imageUrl="images/vehicles/truck"+imageDirection;else if(this.getType()=="jcd")imageUrl="images/vehicles/truck_small";else imageUrl="images/vehicles/bus"+imageDirection;if(vehiclePopupVehicle!=null)if(vehiclePopupVehicle.B()==this.B())imageUrl+="_selected";imageUrl+=".png";try{this.j().setImage(imageUrl);this.j().setPoint(new GLatLng(this.getLat(),this.getLng()));}catch(error){}}};Vehicle.registerClass('Vehicle',null,Sys.IDisposable);Vehicles=function(){this.d=new Array();};Vehicles.prototype={findVehicleByMarker:function(marker){for(index=0;index<this.d.length;index++)if(this.d[index].j()==marker)return this.d[index];return null;},w:function(id){if(this.d.length==0)return 0;for(index=0;index<this.d.length;index++)if(this.d[index].B()==id)return index;return index;},removeOldVehicles:function(){currentTime=new Date();for(index=this.d.length-1;index>=0;index--)if(currentTime.getTime()-this.d[index].n().getTime()>1000){if(vehiclePopupVehicle!=null)if(vehiclePopupVehicle.B==this.d[index].B())onCloseVehiclePopup();map.removeOverlay(this.d[index].j());this.d.splice(index,1);}},removeAllVehicles:function(){for(index=this.d.length-1;index>=0;index--){if(vehiclePopupVehicle!=null)if(vehiclePopupVehicle.B==this.d[index].B())onCloseVehiclePopup();map.removeOverlay(this.d[index].j());this.d.splice(index,1);}this.d=new Array();},addVehicle:function(id,line,direction,type,lat,lng,g,lastStop,currentStop,vehType,name,transportOperator,speed){index=this.w(id);if(index==this.d.length){var icon=new GIcon(false,"images/vehicles/bussi0.png");icon.iconSize=new GSize(55,55);icon.iconAnchor=new GPoint(27,27);icon.shadow="images/vehicles/"+line+".png";icon.shadowSize=new GSize(55,67);var marker=new GMarker(new GLatLng(lat,lng),{icon:icon,draggable:false});map.addOverlay(marker);this.d[index]=new Vehicle(id,line,direction,type,lat,lng,g,marker,lastStop,currentStop,vehType,name,transportOperator,speed);}this.d[index].G(line);this.d[index].r(direction);this.d[index].setLat(lat);this.d[index].setLng(lng);this.d[index].A(g);this.d[index].o(new Date());this.d[index].setLastStop(lastStop);this.d[index].setCurrentStop(currentStop);this.d[index].setName(name);this.d[index].setVehType(vehType);this.d[index].setOperator(transportOperator);this.d[index].setSpeed(speed);this.d[index].updateIcon();},I:function(){return this.d;}};Vehicles.registerClass('Vehicles',null,Sys.IDisposable) 