运行范例

描述

FlyManager 对象负责管理飞行路径的启动、停止、暂停等操作,同时可通过该对象获取飞行路径的状态,时间等。

FlyRoutes 对象是一组飞行路线的集合,通过该对象可获取集合中的任意 FlyRoute 对象,通过 get_currentRoute() 获取当前飞行路径的对象实例。该对象无法被实例化,只能通过 FlyManager 的 get_routes() 获取。

通过调用 FlyRoutes 对象上的 fromFile() 方法实现从文件加载三维飞行路径(fpf 文件)。

FlyRoute 对象包含了飞行路径的相关内容,主要包括路径可见性、飞行速度、循环状态等。该对象无法被实例化,只能通过 FlyRoutes 的 get_currentRoute() 获取。

代码 (文件格式为 UTF-8)


<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=8" />	
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>沿线飞行</title>
    <script type="text/javascript" src="SuperMap.Include.js"></script>
    <script type="text/javascript">
        var htmlUrl = document.location.host;
        var scene = null;
        var sceneControl = null;
        var flyManager = null;
        var flyRoutes = null;
        var flyRoute = null;
        var routeLoaded = true;

        //判断网页的打开方式是本地打开还是通过网络打开
        //不同的打开方式url赋值不同
        if (htmlUrl == "") {
            htmlUrl = "http://localhost:8090";
        }
        else {
            htmlUrl = "http://" + htmlUrl;
        }
        var sceneUrl = htmlUrl + "/iserver/services/3D-sample/rest/realspace";

        function onPageLoad() {
            //初始化三维场景控件
            try {
                //初始化三维场景控件实例,参数为包含控件的HTML元素
                sceneControl = new SuperMap.Web.UI.Controls.SceneControl($get("sceneControlDiv"), initCallback, failedCallback);
            }
            catch (e) {
                //若没有安装插件,则抛出该异常
                if (e.name == SuperMap.Web.Realspace.ExceptionName.PlugInNotInstalled) {
                    var url = htmlUrl + "/iserver/iClient/for3D/plugin/Setup.exe";
                    document.write("<a href='" + url + "'>未检测到 SuperMap iClient3D for  Plugin 插件,请单击此处下载并安装插件。</a>");
                    return;
                }
                //若使用非IE浏览器,则抛出该异常
                else if (e.name == SuperMap.Web.Realspace.ExceptionName.BrowserNotSupport) {
                    document.write("<p>SuperMap iClient3D for  Plugin 目前仅支持 InternetExplorer 浏览器,请更换浏览器后重新尝试加载本页面。</p>");
                    return;
                }
                //抛出其他异常
                else {
                    alert(e.message);
                }

            }

        }

        //控件初始化完成后的回调函数,初始化完成之后才能进行数据加载
        function initCallback() {
            //获取Realspace控件的场景,控件和场景是一对一的捆绑关系
            scene = sceneControl.get_scene();

            //获取FlyManager对象
            flyManager = scene.get_flyManager();

            scene.open(sceneUrl,"scene_olympicgreen");
			var layer3D = scene.get_layer3Ds().get_item(0);

            if (layer3D != null) {
                //获取图层的地理范围,并飞行到该范围
                var geobound = layer3D.get_bounds();
                scene.get_flyingOperator().flyToBounds(geobound);
            }

            var filePathSelect = document.getElementById("filePath");
            var filePathOptions = filePathSelect.options;
            var option1 = new Option("鸟巢道路飞行路线", htmlUrl + "/RealspaceSample/FlyRoutes.fpf");
            var option2 = new Option("会议中心飞行路线", htmlUrl + "/RealspaceSample/NewSceneRoutes.fpf");
            filePathOptions.add(option1);
            filePathOptions.add(option2);
        }

        //控件初始化失败后的回调函数
        function failedCallback() {
            alert("Realspace initialized failed!");
        }

        //获取数据信息
        function getDataName(strLayerName) {
            var sceneservicelist = sceneControl.get_sceneServicesList();
            sceneservicelist.load(sceneUrl);
            var scenecount = sceneControl.get_sceneServicesList().get_count();

            for (var i = 0; i < scenecount; i++) {
                //获取指定的场景信息
                var sceneinfor = sceneservicelist.get_item(i);
                var scenename = sceneinfor.get_name();

                layer3DServicesList = sceneControl.get_layer3DServicesList();
                layer3DServicesList.load(sceneUrl, scenename);

                var count = layer3DServicesList.get_count();
                for (var j = 0; j < count; j++) {
                    //获取指定的图层信息,包括图层名称、数据名称
                    var layer3DServiceInfo = layer3DServicesList.get_item(j);
                    var layerName = layer3DServiceInfo.get_name();
                    var dataName = layer3DServiceInfo.get_dataName();
                    if (layerName == strLayerName) {
                        return dataName;
                    }
                }
            }

        }

        //获取飞行文件路径
        function getFilePath() {
            return document.getElementById("filePath").value;
        }

        function setFilePath() {
            if (flyManager != null) {
                if (flyManager.get_flyStatus() == SuperMap.Web.Realspace.FlyStatus.FSTOP) {
                    //获取飞行路线
                    flyRoutes = flyManager.get_routes();
                    if (flyRoutes != null) {
                        var filePath = getFilePath();
                        if (flyRoutes.fromFile(filePath) == false) {
                            return false;
                        }

                        flyRoute = flyRoutes.get_currentRoute();

                        document.getElementById("speed").value = flyRoute.get_speed();
                        document.getElementById("time").value = flyManager.get_duration();
                        document.getElementById("altitudeFixed").checked = flyRoute.get_isAltitudeFixed();
                        document.getElementById("headingFixed").checked = flyRoute.get_isHeadingFixed();
                        document.getElementById("tiltFixed").checked = flyRoute.get_isTiltFixed();
                        document.getElementById("flyingLoop").checked = flyRoute.get_isFlyingLoop();
                        document.getElementById("flyAlongTheRoute").checked = flyRoute.get_isFlyAlongTheRoute();
                        document.getElementById("linesVisible").checked = flyRoute.get_isLinesVisible();
                        document.getElementById("stopsVisible").checked = flyRoute.get_isStopsVisible();
                        routeLoaded = true;
                    }
                }
            }
            else {
                return false;
            }
        }

        function play() {
            //判断路径是否已加载。
            if (routeLoaded) {
                //重新获取速度和时长
                document.getElementById("speed").value = flyRoute.get_speed();
                document.getElementById("time").value = flyManager.get_duration();

                if (flyManager == null && flyRoutes == null &&
		flyManager.get_flyStatus() == SuperMap.Web.Realspace.FlyStatus.FPLAY) {
                    return;
                }
                else {
                    scene.set_type(SuperMap.Web.Realspace.SceneType.Flat);
                    flyManager.play();
                    //scene.set_type(SuperMap.Web.Realspace.SceneType.Flat);
                }
            }
        }

        //暂停飞行
        function pause() {
            if (flyManager == null)
                return;

            flyManager.pause();
        }

        //停止飞行
        function stop() {
            if (flyManager == null)
                return;

            flyManager.stop();
        }

        function resetSpeed() {
            if (routeLoaded) {
                var speed = document.getElementById("speed").value;
                flyRoute.set_speed(speed);

                document.getElementById("time").value = flyManager.get_duration();
            }
        }

        function resetTime() {
            if (routeLoaded) {
                var duration = document.getElementById("time").value;
                flyManager.set_duration(duration);

                document.getElementById("speed").value = flyRoute.get_speed();
            }
        }

        function resetAltitudeFixed() {
            var altitudeFixed = document.getElementById("altitudeFixed").checked;
            flyRoute.set_isAltitudeFixed(altitudeFixed);
        }

        function resetHeadingFixed() {
            var headingFixed = document.getElementById("headingFixed").checked;
            flyRoute.set_isHeadingFixed(headingFixed);
        }

        function resetTiltFixed() {
            var tiltFixed = document.getElementById("tiltFixed").checked;
            flyRoute.set_isTiltFixed(tiltFixed);
        }

        function resetFlyingLoop() {
            var flyingLoop = document.getElementById("flyingLoop").checked;
            flyRoute.set_isFlyingLoop(flyingLoop);
        }

        function resetFlyAlongTheRoute() {
            var flyAlongTheRoute = document.getElementById("flyAlongTheRoute").checked;
            flyRoute.set_isFlyAlongTheRoute(flyAlongTheRoute);

            if (flyAlongTheRoute == true && document.getElementById("headingFixed").checked == false) {
                document.getElementById("headingFixed").checked = true;
                flyRoute.set_isHeadingFixed(true);
            }
        }

        function resetLinesVisible() {
            var linesVisible = document.getElementById("linesVisible").checked;
            flyRoute.set_isLinesVisible(linesVisible);
        }

        function resetStopsVisible() {
            var stopsVisible = document.getElementById("stopsVisible").checked;
            flyRoute.set_isStopsVisible(stopsVisible);
        }
        function gethtmlUrl() {
            return htmlUrl;
        }
	function playRate() {
            var playratevalue=document.getElementById("playrate").value;
	   flyManager.set_playRate(playratevalue);
        }
    </script>
</head>
<body onload="onPageLoad()" style="font-size: 13.5px">
    <div id="flySet" style="position:absolute;left:5px;top:5px;bottom:5px;width:210px;">
        飞行路线:
        <br />
        <select id="filePath" name="filePath" style="width: 150px">
        </select>
        <a id="linkAction" href="javascript:setFilePath()">设置</a></br> 速度(千米/时):
        <br />
        <input id="speed" type="text" style="width: 150px">
        <a id="linkAction" href="javascript:resetSpeed()">设置</a></br> 时长(秒):
        <br />
        <input id="time" type="text" style="width: 150px">
        <a id="linkAction" href="javascript:resetTime()">设置</a>
		<a id="linkAction" href="javascript:resetTime()">设置</a></br> 当前速率设置(0-100):
		<br />
        <input id="playrate" type="text" style="width: 150px">
        <a id="linkAction" href="javascript:playRate()">设置 </a>
        <p>
            <input id="altitudeFixed" type="checkbox" onclick="resetAltitudeFixed()">高度锁定</p>
        <p>
            <input id="headingFixed" type="checkbox" onclick="resetHeadingFixed()">方位角锁定</p>
        <p>
            <input id="tiltFixed" type="checkbox" onclick="resetTiltFixed()">倾斜角锁定</p>
        <p>
            <input id="flyingLoop" type="checkbox" onclick="resetFlyingLoop()">循环飞行</p>
        <p>
            <input id="flyAlongTheRoute" type="checkbox" onclick="resetFlyAlongTheRoute()">沿线飞行</p>
        <p>
            <input id="linesVisible" type="checkbox" onclick="resetLinesVisible()">显示路线</p>
        <p>
            <input id="stopsVisible" type="checkbox" onclick="resetStopsVisible()">显示站点</p>
        <input id="play" type="button" value="开始" onclick="play()" />
        <input id="pause" type="button" value="暂停" onclick="pause()" />
        <input id="stop" type="button" value="停止" onclick="stop()" />
        <p> <a id="A1" >备注:当沿线飞行时根据需要想</br>加快或者减慢飞行速度时,可通过</br>当前速率设置(即当前速度的几</br>倍),速率取值为【0-100】当速</br>率小于1时是减速,大于1时是加</br>速。</a>
    </div>
    <div id="sceneControlDiv" style="position:absolute;top:5px;left:220px;bottom:5px;right:5px;border:3px solid #cfcfcf;">
		
    </div>
</body>
</html>