Arcgis api for javascript学习笔记-三维地图的飞行效果

Posted Tracine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arcgis api for javascript学习笔记-三维地图的飞行效果相关的知识,希望对你有一定的参考价值。

其实就只是用到了 view.goTo()  函数,再利用 window.setInterval()  函数(定时器)定时执行goTo()。代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Intro to SceneView - Create a 3D map</title>
    <style type="text/css">
        html, body, #viewDiv { height: 100%; width: 100%; }
        #optionsDiv { background-color: white; position: absolute; left: 100px; top: 30px; z-index: 100; }
    </style>
    <link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
    <script type="text/javascript" src="https://js.arcgis.com/4.5/"></script>
    <script>
        require([
            "esri/Map",
            "esri/Basemap",
            "esri/views/MapView",
            "esri/views/SceneView",
            "dojo/domReady!"
        ], function (Map, Basemap, MapView, SceneView) {
            var map = new Map({
                "basemap": "hybrid",
                "ground": "world-elevation"
            });
            var view = new SceneView({
                "map": map,
                "container": "viewDiv"
            });

            view.then(function () {
                /**
                 * ------------------------------------------------------------------------------------------------------------------------------------
                 * 指定两个点之间飞行,并按指定飞行比例的速度进行飞行
                 * ------------------------------------------------------------------------------------------------------------------------------------
                 */
                dojo.connect(dojo.byId("btnFlyTwoPoint"), "onclick", function () {
                    view.goTo({"zoom": 16, "tilt": 75, "center": [111.52, 28.55]})
                        .then(function () {
                            view.goTo(function () {
                                var camera = view.camera.clone();
                                camera.position.latitude += 0.11;
                                camera.position.longitude += 0.02;
                                console.info(camera.position);
                                return camera;
                            }(), {
                                "easing": "linear",
                                "speedFactor": 0.1
                            });
                        });
                });

                /**
                 * ------------------------------------------------------------------------------------------------------------------------------------
                 * 任意点随机飞行
                 * ------------------------------------------------------------------------------------------------------------------------------------
                 */
                var flyInterval = null;
                var flyMoveUnit = 0.0001;
                var flyLatitude = 27.3779;
                var flyLongitude = 111.5332;
                dojo.connect(dojo.byId("chkFlyAnyPoint"), "onclick", function () {
                    if (this.checked) {
                        view.goTo({"zoom": 17, "tilt": 75, "center": [flyLongitude, flyLatitude]})
                            .then(function () {
                                flyInterval = window.setInterval(function () {
                                    flyLongitude = flyLongitude + flyMoveUnit;
                                    flyLatitude = flyLatitude + flyMoveUnit;
                                    view.goTo({
                                        "zoom": 17,
                                        "tilt": 75,
                                        "center": [flyLongitude, flyLatitude]
                                    });
                                }, 80);
                            });

                    }
                    else {
                        window.clearInterval(flyInterval);
                    }
                });
            });
        });
    </script>
</head>
<body>
<div id="optionsDiv">
    <div>飞行模式:任意点飞行<input type="checkbox" id="chkFlyAnyPoint"/></div>
    <div>飞行模式:两点之间飞行<input type="checkbox" id="btnFlyTwoPoint"/></div>
</div>
<div id="viewDiv"></div>
</body>
</html>

 

以上是关于Arcgis api for javascript学习笔记-三维地图的飞行效果的主要内容,如果未能解决你的问题,请参考以下文章

arcgis api for javascript 4.10版本的本地部署

Map学习(arcgis api for javascript3.18)

ArcGIS API for JavaScript学习:第一个地图

ArcGIS API for JavaScript

arcgis api for javascript怎么加载天地图的影像图

如何利用arcgis api for javascript在graphicslayer绘制点线面