function GEHelpers(ge){
this.ge=ge;
};
GEHelpers.prototype.createPointPlacemark=function(_2,_3){
var _4=this.ge.createPlacemark(_3.id?_3.id:"");
if(_3.name){
_4.setName(_3.name);
}
if(_3.description){
_4.setDescription(_3.description);
}
if(_3.standardIcon&&!_3.icon){
_3.icon="http://maps.google.com/mapfiles/kml/paddle/"+_3.standardIcon+".png";
}
if(_3.icon){
var _5=this.ge.createIcon("");
_5.setHref(_3.icon);
var _6=this.ge.createStyle("");
_6.getIconStyle().setIcon(_5);
var _7=this.ge.createStyleMap("");
_7.setNormalStyle(_6);
_7.setHighlightStyle(_6);
_4.setStyleSelector(_7);
}
var _8=this.ge.createPoint("");
_8.setLatitude(_2.lat());
_8.setLongitude(_2.lng());
_4.setGeometry(_8);
this.ge.getFeatures().appendChild(_4);
return _4;
};
GEHelpers.prototype.clearFeatures=function(){
var _9=this.ge.getFeatures();
var c;
while(c=_9.getLastChild()){
_9.removeChild(c);
}
};
GEHelpers.prototype.removeFeature=function(id){
var _c=this.ge.getFeatures();
var c=_c.getFirstChild();
while(c){
if(c.getId()==id){
_c.removeChild(c);
break;
}
c=c.getNextSibling();
}
};
GEHelpers.prototype.createLineStyle=function(_e){
var _f=this.ge.createStyle("");
var _10=_f.getLineStyle();
if(_e.width){
_10.setWidth(_e.width);
}
if(_e.color){
_10.getColor().set(_e.color);
}
return _f;
};
GEHelpers.prototype.getHeading=function(_11,_12){
lat1=this.deg2rad(_11.lat());
lon1=this.deg2rad(_11.lng());
lat2=this.deg2rad(_12.lat());
lon2=this.deg2rad(_12.lng());
var _13=this.fixAngle(this.rad2deg(Math.atan2(Math.sin(lon2-lon1)*Math.cos(lat2),Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))));
return _13;
};
GEHelpers.prototype.rad2deg=function(r){
return r*180/Math.PI;
};
GEHelpers.prototype.deg2rad=function(d){
return d*Math.PI/180;
};
GEHelpers.prototype.fixAngle=function(a){
while(a<-180){
a+=360;
}
while(a>180){
a-=360;
}
return a;
};
GEHelpers.prototype.interpolateLoc=function(_17,_18,f){
return new GLatLng(_17.lat()+f*(_18.lat()-_17.lat()),_17.lng()+f*(_18.lng()-_17.lng()));
};
GEHelpers.prototype.distance=function(_1a,_1b){
p1=V3.latLonAltToCartesian([_1a.lat(),_1a.lng(),this.ge.getGlobe().getGroundAltitude(_1a.lat(),_1a.lng())]);
p2=V3.latLonAltToCartesian([_1b.lat(),_1b.lng(),this.ge.getGlobe().getGroundAltitude(_1b.lat(),_1b.lng())]);
return V3.earthDistance(p1,p2);
};
DDSimulator.MODEL_URL="http://earth-api-samples.googlecode.com/svn/trunk/"+"demos/drive-simulator/smart.kmz";
DDSimulator.TICK_SIM_MS=66;
DDSimulator.prototype.totalTime=0;
DDSimulator.prototype.totalDistance=0;
DDSimulator.prototype.currentSpeed=0;
DDSimulator.prototype.currentLoc=null;
function DDSimulator(ge,_1d,_1e){
this.ge=ge;
this.path=_1d;
this.options=_1e||{};
if(!this.options.speed){
this.options.speed=1;
}
this.currentLoc=this.path[0].loc;
this.geHelpers_=new GEHelpers(ge);
this.doTick_=false;
this.pathIndex_=0;
this.currentStep_=-1;
this.segmentTime_=0;
this.segmentDistance_=0;
};
DDSimulator.prototype.initUI=function(_1f){
var me=this;
var me=this;
this.tickListener=function(){
if(me.doTick_){
me.tick_();
}
};
window.google.earth.addEventListener(this.ge,"frameend",this.tickListener);
};
DDSimulator.prototype.finishInitUI_=function(kml,_22){
var me=this;
this.tickListener=function(){
if(me.doTick_){
me.tick_();
}
};
window.google.earth.addEventListener(this.ge,"frameend",this.tickListener);
if(_22){
_22();
}
};
DDSimulator.prototype.destroy=function(){
this.stop();
window.google.earth.removeEventListener(this.ge,"frameend",this.tickListener);
};
DDSimulator.prototype.start=function(){
if(this.doTick_){
return;
}
this.oldFlyToSpeed=this.ge.getOptions().getFlyToSpeed();
this.ge.getOptions().setFlyToSpeed(this.ge.SPEED_TELEPORT);
this.doTick_=true;
this.tick_();
};
DDSimulator.prototype.stop=function(){
if(!this.doTick_){
return;
}
this.ge.getOptions().setFlyToSpeed(this.oldFlyToSpeed);
this.doTick_=false;
};
DDSimulator.prototype.drive_=function(loc,_25){
this.moveToPointDriving_(loc,_25);
};
DDSimulator.prototype.getTurnToDirection_=function(_26,_27){
if(Math.abs((_26)-(_27))<1){
return _27-_26;
}
return (this.geHelpers_.fixAngle(_27-_26)<0)?-1:1;
};
DDSimulator.prototype.moveToPointDriving_=function(loc,_29){
var _2a=this.ge.getView().copyAsLookAt(this.ge.ALTITUDE_RELATIVE_TO_GROUND);
var _2b=_2a.getHeading();
var _2c=_29;
var _2d=_2a.getRange();
var _2e=Math.max(20,this.currentSpeed*10);
var la=this.ge.createLookAt("");
la.set(loc.lat(),loc.lng(),0,this.ge.ALTITUDE_RELATIVE_TO_GROUND,_2b+this.getTurnToDirection_(_2b,_2c),75,_2d+(_2e-_2d)*0.1+25);
this.ge.getView().setAbstractView(la);
};
DDSimulator.prototype.tick_=function(){
if(this.pathIndex_>=this.path.length-1){
this.doTick_=false;
return;
}
if(this.path[this.pathIndex_].step!=this.currentStep_){
this.currentStep_=this.path[this.pathIndex_].step;
if(this.options.on_changeStep){
this.options.on_changeStep(this.currentStep_);
}
}
this.totalTime+=DDSimulator.TICK_SIM_MS*this.options.speed/1000;
this.segmentTime_+=DDSimulator.TICK_SIM_MS*this.options.speed/1000;
var _30=this.path[this.pathIndex_].duration;
if(!this.beforeSegmentDistance_){
this.beforeSegmentDistance_=0;
}
while(this.pathIndex_<this.path.length-1&&this.segmentTime_>=_30){
this.segmentTime_-=_30;
this.beforeSegmentDistance_+=this.path[this.pathIndex_].distance;
this.segmentDistance_=0;
this.pathIndex_++;
_30=this.path[this.pathIndex_].duration;
}
if(_30){
this.segmentDistance_=this.path[this.pathIndex_].distance*Math.min(1,this.segmentTime_/_30);
this.currentSpeed=this.path[this.pathIndex_].distance/_30;
}else{
this.segmentDistance_=0;
this.currentSpeed=0;
}
this.totalDistance=this.beforeSegmentDistance_+this.segmentDistance_;
if(this.pathIndex_>=this.path.length-1){
this.doTick_=false;
return;
}
this.currentLoc=this.geHelpers_.interpolateLoc(this.path[this.pathIndex_].loc,this.path[this.pathIndex_+1].loc,this.segmentTime_/this.path[this.pathIndex_].duration);
this.drive_(this.currentLoc,this.geHelpers_.getHeading(this.path[this.pathIndex_].loc,this.path[this.pathIndex_+1].loc));
if(this.options.on_tick){
this.options.on_tick();
}
};


