OpenLayers.Layer.TrafficLayer=OpenLayers.Class(OpenLayers.Layer.Vector,{initialize:function(name,options){OpenLayers.Layer.Vector.prototype.initialize.apply(this,arguments);this.INTERVAL=2*60000;this.SERVER_URL='/rtserver/web/GeoRSS';this.MOVE_EVENT_UPDATE_DELAY=2000;this.CHECK_INIT_MAP_INTERVAL=3000;var tl=this;this.init_map_interval=window.setInterval(function(){if(!tl.map||!tl.map.getExtent())
return;window.clearInterval(tl.init_map_interval);tl.map.events.register("moveend",tl,function(evt){window.clearTimeout(this.move_event_timeout);this.move_event_timeout=window.setTimeout(function(){tl._getUpdateTraffic()();},this.MOVE_EVENT_UPDATE_DELAY);});tl._getUpdateTraffic()();window.setInterval(tl._getUpdateTraffic(),tl.INTERVAL);},this.CHECK_INIT_MAP_INTERVAL);},_getUpdateTraffic:function(){var tl=this;return function(){var onTrafficUpdate=function(response){tl.removeFeatures(tl.features);var new_features=[];$("item",response).each(function(){var str=$(":ns(http://www.georss.org/georss,line)",this).text();var coords_str=str.split(" ");var geometry=new OpenLayers.Geometry.LineString();for(var i=0;i<coords_str.length;i+=2){var y=parseFloat(coords_str[i]);var x=parseFloat(coords_str[i+1]);geometry.addPoint(new OpenLayers.Geometry.Point(x=x,y=y));}
var vec=new OpenLayers.Feature.Vector(geometry=geometry);new_features.push(vec);vec.description={};vec.description.from=$(":ns(http://www.linqmap.com,startNode)",this).text();vec.description.to=$(":ns(http://www.linqmap.com,endNode)",this).text();vec.description.at=$(":ns(http://www.linqmap.com,street)",this).text();vec.description.street=$(":ns(http://www.linqmap.com,street)",this).text();vec.description.city=$(":ns(http://www.linqmap.com,city)",this).text();var speed=$(":ns(http://www.linqmap.com,speed)",this).text();vec.description.duration=(speed=="NaN")?5+Math.round((Math.random()*2)):parseInt((parseFloat($(":ns(http://www.linqmap.com,length)",this).text())/parseFloat(speed))/60);var color="#ff631c";var opacity=0.6;if(vec.description.duration<=4){color="#fff21c";}
if(vec.description.duration>=8){color="#b40000";}
vec.style={strokeWidth:10,strokeColor:color,strokeOpacity:opacity};});tl.addFeatures(new_features);}
var extent=tl.map.getExtent();$.get(url=tl.SERVER_URL,data={"types":"traffic",left:extent.left,right:extent.right,bottom:extent.bottom,top:extent.top,sc:parseInt(tl.map.getScale())},callback=onTrafficUpdate,type="xml");}}});