zoukankan      html  css  js  c++  java
  • Skyline软件二次开发初级——6如何在WEB页面中的三维地图上进行坐标和方向计算

    1.距离和角度:

    <html>
        <head>
            <title>Coordinates 1</title>
            <object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
            <script type="text/javascript">
            
            
    var popup = null;
            
            
    function Init()
            {
                
                
    // defining two coordinates
                var coord1 = SGWorld.Creator.CreatePosition(-71.0754242.34930232.0); // The Hancock building            
                var coord2 = SGWorld.Creator.CreatePosition(-71.0550742.35561105.0); // Target building
                
                
    // Placing some annotation on the terrain
                SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
                SGWorld.Creator.CreateTextLabel(coord2, 
    "Building 2",SGWorld.Creator.CreateLabelStyle());
                SGWorld.Creator.CreatePolyline(SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([coord1, coord2]), SGWorld.Creator.CreateColor(
    2552550), 00"line");

                
    // Set a good view point for the scene 
                SGWorld.Navigate.SetPosition(SGWorld.Creator.CreatePosition(-71.0780242.33974550.0,034-13));           
                
                
    // Calculating the distance and angles from the Hancock building to building #2
                var distance = coord1.DistanceTo(coord2);

                
    var angles = coord1.AimTo(coord2);
                            
                
    // Display a message to the user
                popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample","",0,0,450,120);            
                popup.InnerText 
    = "The aerial distance between the roofs of the\r\nHancock building and building #2 is " + Math.floor(distance) + " Meters\r\n\r\n" +
                                  
    "The aiming angles from the Hancock building to building #2 are:\r\nyaw: " + angles.Yaw.toFixed(5+ "  pitch: " + angles.Pitch.toFixed(5);                        
                popup.Align 
    = "TopLeft";
                SGWorld.Window.ShowPopup(popup);                        
            }
            
            
    function Uninit()
            {
                
    if(SGWorld.Project.Name == "")
                    
    return;
                
    if(popup)
                    SGWorld.Window.RemovePopup(popup);
            }
            
            
    </script>
        </head>
        <body onload="Init();" onunload="Uninit()">
        </body>
    </html>

    2.位置和方向:

    <html>
        <head>
            <title>Coordinates 1</title>
            <object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
            <script type="text/javascript">
            
            
    var popup = null;
            
            
    function Init()
            {
                
    // defining two coordinates
                var coord1 = SGWorld.Creator.CreatePosition(-71.0754242.34930232.0);
                
    var coord2 = SGWorld.Creator.CreatePosition(-71.0550742.35561105.0);
                
                
    // Placing some annotation on the terrain
                SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
                SGWorld.Creator.CreateTextLabel(coord2, 
    "Building 2",SGWorld.Creator.CreateLabelStyle());

                
    var pos = coord1.AimTo(coord2);

                SGWorld.Navigate.SetPosition(pos);            
                
                
    // Display a message to the user
                popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
                popup.innerText 
    = "This sample shows how to place the camera at a specific position\r\nwhile aiming it to a desired point of interest";
                popup.align 
    = "TopLeft";
                SGWorld.Window.ShowPopup(popup);
            }
            
            
    function Uninit()
            {
                
    if(SGWorld.Project.Name == "")
                    
    return;
                
    if(popup)
                    SGWorld.Window.RemovePopup(popup);
            }
            
            
    </script>
        </head>
        <body onload="Init();" onunload="Uninit()">
        </body>
    </html>

    3.移动指向位置:

    <html>
        <head>
            <title>Coordinates 1</title>
            <object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
            <script type="text/javascript">
            
            
    var popup = null;
            
            
    var coord1, coord2, pos, distance;
            
    var time;
            
    function Init()
            {
                
                SGWorld.AttachEvent(
    "OnFrame", onFrame);
                time 
    = new Date().getTime();
                
    // defining two coordinates
                coord1 = SGWorld.Creator.CreatePosition(-71.0754242.34930232.0);
                coord2 
    = SGWorld.Creator.CreatePosition(-71.0550742.35561105.0);
                
                
    // Placing some annotation on the terrain
                SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
                SGWorld.Creator.CreateTextLabel(coord2, 
    "Building 2",SGWorld.Creator.CreateLabelStyle());

                distance 
    = coord1.DistanceTo(coord2);
                pos 
    = coord1.AimTo(coord2);

                
    // Set the start position at the top of the Hancock building
                SGWorld.Navigate.SetPosition(pos);            
                
                
    // Display a message to the user
                popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
                popup.InnerText 
    = "This sample shows how to move a coordinate toward another coordinate";
                popup.Align 
    = "TopLeft";
                SGWorld.Window.ShowPopup(popup);                             
            }
            
            
            
            
    function onFrame()
            {
                
    var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
                time = new Date().getTime();
                pos 
    = pos.MoveToward(coord2, 200*elapsedTime);   // 200 meters/sec
                
                
    var newDist = pos.DistanceTo(coord2);
                
                
    if (newDist > distance)
                {
                    
    // Stop condition. if we are here, then we have passed building 2
                    SGWorld.DetachEvent("OnFrame", onFrame);
                    
    return;
                }

                SGWorld.Navigate.SetPosition(pos);         
                distance 
    = newDist;
            }
            
            
            
            
            
    function Uninit()
            {
                
    if(SGWorld.Project.Name == "")
                    
    return;
                
    if(popup)
                    SGWorld.Window.RemovePopup(popup);

            }
            
            
    </script>
        </head>
        <body onload="Init();" onunload="Uninit()">
        </body>
    </html>

    4.朝着某个对象移动:

    <html>
        <head>
            <title>Coordinates 1</title>
            <object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
            <script type="text/javascript">
            
            
    var popup = null;
            
            
    var coordHancock, pos;
            
            
    var time;
            
    function Init()
            {

                SGWorld.AttachEvent(
    "OnFrame", onFrame);

                setTimeout(
    function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 15000);

                time 
    = new Date().getTime();

                coordHancock 
    = SGWorld.Creator.CreatePosition(-71.0754242.34930232.0);

                SGWorld.Creator.CreateTextLabel(coordHancock, 
    "Hancock Building",SGWorld.Creator.CreateLabelStyle());

                pos 
    = SGWorld.Creator.CreatePosition(-71.1005542.31624350.0,015.0); // x,y,height,height_type,yaw

                SGWorld.Navigate.SetPosition(pos);       
                
                
    // Display a message to the user
                popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
                popup.InnerText 
    = "This sample shows how you can move a coordinate in one direction while aiming to another";
                popup.Align 
    = "TopLeft";
                SGWorld.Window.ShowPopup(popup);                                
            }
                            
            
    function onFrame()
            {
                
    var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
                time = new Date().getTime();
                pos 
    = pos.Move(400*elapsedTime, 15.00.0).AimTo(coordHancock);   // 400 meters/sec

                SGWorld.Navigate.SetPosition(pos);
            }                        
            
            
    function Uninit()
            {
                
    if(SGWorld.Project.Name == "")
                    
    return;
                
    if(popup)
                    SGWorld.Window.RemovePopup(popup);
            }
            
            
    </script>
        </head>
        <body onload="Init();" onunload="Uninit()">
        </body>
    </html>

    5.以上效果叠加:

    <html>
        <head>
            <title>Coordinates 5</title>
            <object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
            <script type="text/javascript" src="abspath.js"></script>
            <script type="text/javascript">
            
            
    var popup = null;        
            
            
    var model     = null;
            
    var labelF16  = null;
            
            
    var yaw = 45.0;
            
    var totalTime = 0;
            
    function Init()
            {
                SGWorld.AttachEvent(
    "OnFrame", onFrame);
                setTimeout(
    function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 10000); // remove event handler after 10 seconds
                time = new Date().getTime();

                model 
    = SGWorld.Creator.CreateModel(SGWorld.Creator.CreatePosition(-71.1005542.31624125.0,028), toAbspath("data/f16.xpc"), 1);

                labelF16 
    = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(00), "F-16",SGWorld.Creator.CreateLabelStyle());                        
               
                
    // Display a message to the user
                popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
                popup.InnerText 
    = "This sample shows how, by manipulating coordinates, you can create a complex scene\r\n" +
                                  
    "In this sample you can see how to:\r\n" +
                                  
    "1. Move an object (F16)\r\n" +
                                  
    "2. Make another object, a label in this case, to follow the first object\r\n" +
                                  
    "3. Make the camera follow the first object while circling it";
                popup.Align 
    = "TopLeft";
                SGWorld.Window.ShowPopup(popup);      
            }
           
                    
            
    function onFrame()   // elapsedTime is the time in seconds elapsed from the previous frame
            {
                
    var elapsedTime = (new Date().getTime() - time) / 1000 // elapsedTime is the time in seconds elapsed from the previous frame
                time = new Date().getTime();

                
    var modelPos = model.Position;
                
                modelPos.Roll 
    = modelPos.Roll + 4.5;
                modelPos 
    = modelPos.Move(700 * elapsedTime, modelPos.Yaw, modelPos.Pitch); // move the object in its current direction at a speed of 700 m/s                                                              

                
    if (totalTime > 6
                    modelPos.Pitch 
    += 20*elapsedTime; // increase pitch by 20 degree per sec

                model.Position 
    = modelPos;
                
                
    // Make the label object to be positioned 40 meters above (pitch = 90) the first object            
                labelF16.Position = modelPos.Move(40.00.090.0);            
                
                
    // Move the camera in relation to the first object while looking at it.
                yaw += 40.0*elapsedTime; // increase yaw by 40 degree per sec
                var cameraPos = modelPos.Move(700, yaw, 5).AimTo(modelPos);
                cameraPos.Roll 
    = 0// plane is rolling, but we do not want the camera to use this roll, so we zero it.
                SGWorld.Navigate.SetPosition(cameraPos);
                totalTime 
    += elapsedTime;
            }                        
            
            
    function Uninit()
            {
                
    if(SGWorld.Project.Name == "")
                    
    return;
                
    if(popup)
                    SGWorld.Window.RemovePopup(popup);
      
            }
            
            
    </script>
        </head>
        <body onload="Init();" onunload="Uninit()">
        </body>
    </html>
  • 相关阅读:
    操作系统介绍
    python 面向对象 公有属性 用在哪里
    python 类 __module__ __class__
    操作系统发展史
    python 面向对象 字典 有序字典
    python 面向对象 私有属性
    python 面向对象 类 __doc__
    saltstack 部署
    【SQL】MySQL之使用mysqlbinlog进行增量备份及恢复详解
    [SOA] Mule ESB 3.x 入门(二)—— 配置(spring, properties, log4j)
  • 原文地址:https://www.cnblogs.com/yitianhe/p/2699632.html
Copyright © 2011-2022 走看看