Skyline软件二次开发初级——5如何在WEB页面中的三维地图上使用事件函数

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 >

 

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 >

 

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 >

 

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 >

 

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 >

 

转载于:https://www.cnblogs.com/yitianhe/archive/2012/09/22/2697857.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值