1.onFrame事件 - 移動攝像機:
<
html
>
< head >
< title >onFrame - Move camera </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
var time = 5 * 1000 ; // move for 5 sec.
function Init()
{
SGWorld.AttachEvent( " onFrame " , onFrame);
SGWorld.Navigate.JumpTo(SGWorld.Creator.CreatePosition( - 100.0 , 40.0 , 13000000 , 3 , 0 , - 85 ));
setTimeout( function () { SGWorld.DetachEvent( " onFrame " , onFrame); }, time);
}
function onFrame()
{
var pos = SGWorld.Navigate.GetPosition();
pos.X += 0.5 ;
pos.Y -= 0.2 ;
SGWorld.Navigate.SetPosition(pos);
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
< head >
< title >onFrame - Move camera </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
var time = 5 * 1000 ; // move for 5 sec.
function Init()
{
SGWorld.AttachEvent( " onFrame " , onFrame);
SGWorld.Navigate.JumpTo(SGWorld.Creator.CreatePosition( - 100.0 , 40.0 , 13000000 , 3 , 0 , - 85 ));
setTimeout( function () { SGWorld.DetachEvent( " onFrame " , onFrame); }, time);
}
function onFrame()
{
var pos = SGWorld.Navigate.GetPosition();
pos.X += 0.5 ;
pos.Y -= 0.2 ;
SGWorld.Navigate.SetPosition(pos);
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
2.onFrame事件 - 移動對象:
<
html
>
< head >
< title >onFrame - Move objects </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script src ="abspath.js" type ="text/javascript" ></ script >
< script type ="text/javascript" >
var model = null ;
var time;
function Init()
{
time = new Date();
SGWorld.AttachEvent( " onFrame " , onFrame);
var pos = SGWorld.Creator.CreatePosition( - 122.38050 , // x
37.62331 , // y
40.0 , // height
3 , // height type
297.0 , // yaw
15.0 , // pitch
0 , // roll
0 // dist
);
model = SGWorld.Creator.CreateModel(pos, toAbspath( " data/747.xpc " ), 0.2 );
model.Attachment.AutoDetach = false ;
SGWorld.Navigate.FlyTo(model);
}
function onFrame(elapsedTime)
{
// move object with speed of 400km/h
var distToMove = ( 400 * 1000 / 3600 ) * ( new Date().getTime() - time.getTime()) / 1000 ;
model.Position = model.Position.Move(distToMove, model.Position.Yaw + 0.1 , model.Position.Pitch);
time = new Date();
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
< head >
< title >onFrame - Move objects </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script src ="abspath.js" type ="text/javascript" ></ script >
< script type ="text/javascript" >
var model = null ;
var time;
function Init()
{
time = new Date();
SGWorld.AttachEvent( " onFrame " , onFrame);
var pos = SGWorld.Creator.CreatePosition( - 122.38050 , // x
37.62331 , // y
40.0 , // height
3 , // height type
297.0 , // yaw
15.0 , // pitch
0 , // roll
0 // dist
);
model = SGWorld.Creator.CreateModel(pos, toAbspath( " data/747.xpc " ), 0.2 );
model.Attachment.AutoDetach = false ;
SGWorld.Navigate.FlyTo(model);
}
function onFrame(elapsedTime)
{
// move object with speed of 400km/h
var distToMove = ( 400 * 1000 / 3600 ) * ( new Date().getTime() - time.getTime()) / 1000 ;
model.Position = model.Position.Move(distToMove, model.Position.Yaw + 0.1 , model.Position.Pitch);
time = new Date();
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
3.onLButtonDown事件:
<
html
>
< head >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
var globe = null ;
var pos = null ;
var popup, popup2;
function Init()
{
SGWorld.AttachEvent( " onLButtonDown " , onLButtonDown);
SGWorld.AttachEvent( " onRButtonDown " , onRButtonDown);
popup2 = SGWorld.Creator.CreatePopupMessage()
popup2.InnerText = " Left click on the terrain to get the coordinates at cursor position. Right click to finish. " ;
SGWorld.Window.ShowPopup(popup2);
}
function onLButtonDown(flags, x,y)
{
var ret = SGWorld.Window.PixelToWorld(x, y);
popup = SGWorld.Creator.CreatePopupMessage( " onLButtonDown event " , "" , x, y);
popup.InnerText = (ret == null ) ? " Screen coordinate hit the sky " : " Screen coordinates ( " + x + " , " + y + " ):\nTerrain coordinate:\nX: " + ret.Position.X + " \nY: " + ret.Position.Y;
SGWorld.Window.ShowPopup(popup);
return true ; // event was processed by the client. return false to allow additional processing of the event.
}
function onRButtonDown(flags, x,y)
{
SGWorld.DetachEvent( " onLButtonDown " , onLButtonDown);
SGWorld.DetachEvent( " onRButtonDown " , onRButtonDown);
if (popup)
SGWorld.Window.RemovePopup(popup);
if (popup2)
SGWorld.Window.RemovePopup(popup2);
return true ; // event was processed by the client. return false to allow additional processing of the event.
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
< head >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
var globe = null ;
var pos = null ;
var popup, popup2;
function Init()
{
SGWorld.AttachEvent( " onLButtonDown " , onLButtonDown);
SGWorld.AttachEvent( " onRButtonDown " , onRButtonDown);
popup2 = SGWorld.Creator.CreatePopupMessage()
popup2.InnerText = " Left click on the terrain to get the coordinates at cursor position. Right click to finish. " ;
SGWorld.Window.ShowPopup(popup2);
}
function onLButtonDown(flags, x,y)
{
var ret = SGWorld.Window.PixelToWorld(x, y);
popup = SGWorld.Creator.CreatePopupMessage( " onLButtonDown event " , "" , x, y);
popup.InnerText = (ret == null ) ? " Screen coordinate hit the sky " : " Screen coordinates ( " + x + " , " + y + " ):\nTerrain coordinate:\nX: " + ret.Position.X + " \nY: " + ret.Position.Y;
SGWorld.Window.ShowPopup(popup);
return true ; // event was processed by the client. return false to allow additional processing of the event.
}
function onRButtonDown(flags, x,y)
{
SGWorld.DetachEvent( " onLButtonDown " , onLButtonDown);
SGWorld.DetachEvent( " onRButtonDown " , onRButtonDown);
if (popup)
SGWorld.Window.RemovePopup(popup);
if (popup2)
SGWorld.Window.RemovePopup(popup2);
return true ; // event was processed by the client. return false to allow additional processing of the event.
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
4.屏蔽右鍵彈出菜單:
<
html
>
< head >
< title >Preventing right popup </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
function Init()
{
SGWorld.AttachEvent( " onRButtonDown " , onRButtonDown);
SGWorld.AttachEvent( " onRButtonDblClk " , onRButtonDblClk);
SGWorld.Window.ShowMessageBarText( " This sample shows how to disable the default right context menu. Double right-click to re-enable " , 3 );
}
function onRButtonDown(flags, x,y)
{
return true ; // Tell TE that the OnRButtonDown event was processed by the client
}
function onRButtonDblClk(flags, x,y)
{
SGWorld.DetachEvent( " onRButtonDown " , onRButtonDown);
SGWorld.DetachEvent( " onRButtonDblClk " , onRButtonDblClk);
SGWorld.Window.HideMessageBarText();
alert( " Right click is now enabled " );
return false ;
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
< head >
< title >Preventing right popup </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
function Init()
{
SGWorld.AttachEvent( " onRButtonDown " , onRButtonDown);
SGWorld.AttachEvent( " onRButtonDblClk " , onRButtonDblClk);
SGWorld.Window.ShowMessageBarText( " This sample shows how to disable the default right context menu. Double right-click to re-enable " , 3 );
}
function onRButtonDown(flags, x,y)
{
return true ; // Tell TE that the OnRButtonDown event was processed by the client
}
function onRButtonDblClk(flags, x,y)
{
SGWorld.DetachEvent( " onRButtonDown " , onRButtonDown);
SGWorld.DetachEvent( " onRButtonDblClk " , onRButtonDblClk);
SGWorld.Window.HideMessageBarText();
alert( " Right click is now enabled " );
return false ;
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
5.onTerraExplorerMessage事件:
<
html
>
< head >
< title >onTerraExplorerMessage event </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
function Init()
{
SGWorld.AttachEvent( " onTerraExplorerMessage " , onTerraExplorerMessage);
var label = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition( - 71.00425 , 42.36081 , 100 ),
" Click here to get the name of the airport " ,SGWorld.Creator.CreateLabelStyle());
var msg = SGWorld.Creator.CreateMessage( 0 , " Logan International " , 0 );
label.Message.MessageID = msg.ID;
SGWorld.Navigate.JumpTo(label);
}
function onTerraExplorerMessage(messageId, senderNodeId)
{
var message = SGWorld.Creator.GetObject(messageId);
var senderNode = SGWorld.Creator.GetObject(senderNodeId);
senderNode.Text = message.Text;
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >
< head >
< title >onTerraExplorerMessage event </ title >
< object id ="SGWorld" classid ="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style ="visibility:hidden;height:0 " ></ object >
< script type ="text/javascript" >
function Init()
{
SGWorld.AttachEvent( " onTerraExplorerMessage " , onTerraExplorerMessage);
var label = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition( - 71.00425 , 42.36081 , 100 ),
" Click here to get the name of the airport " ,SGWorld.Creator.CreateLabelStyle());
var msg = SGWorld.Creator.CreateMessage( 0 , " Logan International " , 0 );
label.Message.MessageID = msg.ID;
SGWorld.Navigate.JumpTo(label);
}
function onTerraExplorerMessage(messageId, senderNodeId)
{
var message = SGWorld.Creator.GetObject(messageId);
var senderNode = SGWorld.Creator.GetObject(senderNodeId);
senderNode.Text = message.Text;
}
</ script >
</ head >
< body onload ="Init();" >
</ body >
</ html >