首页 / 浏览问题 / 三维GIS / 问题详情
三维飞行 出现乱码
cai
7EXP 2020年08月03日

三维飞行 点击开始按钮没反应   不能实现功能   希望大佬能帮我看看  谢谢了!!

<html>
<head>
	<meta http-equiv="content-type" content="text/html"/>
	<meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
   <meta name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> 
   <title>Wbestart</title>
   <link rel="stylesheet" type="text/css" href="./css/pretty.css"/>
   <link href="./css/widgets.css" rel="stylesheet">
   <link href="./css/bootstrap.min.css" rel="stylesheet">
   <script src="./js/jquery.min.js"></script>
   <script src="./js/bootstrap.min.js"></script>
   <script src="./js/bootstrap-select.min.js"></script>
   <script src="./js/config.js"></script>
   <script type="text/javascript" src="./js/require.min.js" data-main="js/main"></script>
   <style>
        #play {
            content: url("./图片/开始.png");
            height: 30px;
            padding: 5px;
        }

        #pause {
            content: url("./图片/暂停.png");
            height: 30px;
            padding: 5px;
        }

        #stop {
            content: url("./图片/停止.png");
            height: 30px;
            padding: 5px;
        }

        .bootstrap-select {
            width: 150px;
        }
    </style>
   <script type="text/javascript">
      function onload(Cesium) {
		  var toolbar =document.getElementById('toolbar');
         var viewer = new Cesium.Viewer('cesiumContainer');
		  var scene=viewer.scene;
		  var url1="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Building@CBD/config";
		  var url2="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Ground@CBD/config";
		  var url3="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Waters@CBD/config";
		  var infoboxContainer=document.getElementById("bubble");
		  viewer.customInfobox=infoboxContainer;
		  var widget =viewer.cesiumWidget;
		  try{
			  var promise =scene.addS3MTilesLayerByScp(url1 ,{name :'Building'});
			  var promise1=scene.addS3MTilesLayerByScp(url2, {name :'Ground'});
			  var promise2=scene.addS3MTilesLayerByScp(url3, {name :'Waters'});
			  Cesium.when(promise,function(layer){scene.camera.setView({destination : Cesium.Cartesian3.fromDegrees(116.4581104772965,39.91229850123048,2500)});
												 },function(e){
				  if (widget._showRenderLoopErrors){
					  var title ='An error';
					  widget.showErrorPanel(title,undefined,e);
				  }
			  });
			  
		  }
		  catch(e){
			  if(widget._showRenderLoopErrors){
				  var title='An error';
				  widget.showErrorPanel(title,undefined,e);
			  }
		  }
      }
   </script>
	<script type="text/javascript">
			var flyManager;
				function onload(Cesium) {
					var routes = new Cesium.RouteCollection(viewer.entities);
					    //添加fpf飞行文件,fpf由SuperMap iDesktop生成
					    var fpfUrl='D:\supermapiserver\webapps\WebStart\飞行.fpf';
					    routes.fromFile(fpfUrl);
						var scene = viewer.scene;
						scene.globe.depthTestAgainstTerrain = false;
					    //初始化飞行管理
					    var flyManager = new Cesium.FlyManager({
					        scene: scene,
					        routes: routes
					    });
					    //注册站点到达事件
					    flyManager.stopArrived.addEventListener(function (routeStop) {
					        routeStop.waitTime = 1.5; // 在每个站点处停留1.5s
					    });
					
					    flyManager.readyPromise.then(function () { // 飞行路线就绪
					        var currentRoute = flyManager.currentRoute;
					        currentRoute.isLineVisible = true;
					        currentRoute.isStopVisible = true;
					        //生成飞行文件中的所有站点列表
					        var allStops = flyManager.getAllRouteStops();
					        var menu = document.getElementById('stopList');
					        for (var i = 0, j = allStops.length; i < j; i++) {
					            var option = document.createElement('option');
					            option.innerHTML = "站点 " + (i + 1);
					            option.value = allStops[i].index;
					            menu.appendChild(option);
					        }
					
					        $('#stopList').change(function () { //注册站点切换事件
					            flyManager && flyManager.stop();
					            var index = parseInt($(this).val()); // 站点的索引
					            var route = flyManager.currentRoute;
					            var stop = route.get(index);
					            flyManager.currentStopIndex = index;
					            flyManager.viewToStop(stop);
					        });
					
					        $('#play').click(function () {
					            flyManager && flyManager.play();
					        });
					        $('#pause').click(function () {
					            flyManager && flyManager.pause();
					        });
					        $('#stop').click(function () {
					            flyManager && flyManager.stop();
					        });
					
					        $('#show-line').change(function(){
					            currentRoute.isLineVisible = $(this).prop('checked');
					        });
					
					        $('#show-stop').change(function(){
					            currentRoute.isStopVisible = $(this).prop('checked');
					        });
					
					        $('#toolbar').show();
					        $('#loadingbar').remove();
					    });
					});
				}
		</script>
   
</head>

<body>
	 <div id="cesiumContainer" style="width=100%;height=100%" ></div>
	<div id="loadingbar" class="spinner">
	    <div class="spinner-container container1">
	        <div class="circle1"></div>
	        <div class="circle2"></div>
	        <div class="circle3"></div>
	        <div class="circle4"></div>
	    </div>
	    <div class="spinner-container container2">
	        <div class="circle1"></div>
	        <div class="circle2"></div>
	        <div class="circle3"></div>
	        <div class="circle4"></div>
	    </div>
	    <div class="spinner-container container3">
	        <div class="circle1"></div>
	        <div class="circle2"></div>
	        <div class="circle3"></div>
	        <div class="circle4"></div>
	    </div>
	</div>
	<div id="toolbar" class="param-container tool-bar">
	    <span type="button" id="play" class="button black" title="开始"></span>
	    <span type="button" id="pause" class="button black" title="暂停"></span>
	    <span type="button" id="stop" class="button black" title="停止"></span>
	    <div style="width: 150px;">
	        <select id="stopList" class="form-control" style="width: 100%;">
	        </select>
	    </div>
	    <div class="checkbox">
	        <label>
	            <input type="checkbox" id="show-line" checked> 显示飞行路线
	        </label>
	    </div>
	    <div class="checkbox">
	        <label>
	            <input type="checkbox" id="show-stop" checked> 显示飞行站点
	        </label>
	    </div>
	</div>	
		
	
</body>
</html>

1个回答

您好,您的飞行文件不能以这种绝对路径的方式添加,建议您以以下这种相对路径的方式添加。

1,545EXP 2020年08月04日

改了 还是不行

我在两个script标签里 都加了这个

但是运行后模型都不出来了

是不是在每个一个script 标签里 都要 添加s3m图层啊

这个部分不懂sad

能截图看看您的相对路径是怎么写的吗,html和fpf的路径关系是否正确。您加载两个viewer想想添加两个s3m图层吗?添加多个s3m图层可以参考示例http://support.supermap.com.cn:8090/webgl/examples/editor.html#serviceAreaAnalysis

我现在他们写在一个script标签里了  能成功加载模型了(这个部分我能懂了)  

但是这个飞行管理按钮不能起作用了。。。

这是加载模型和飞行的代码。

<script type="text/javascript">
			var flyManager;
				function onload(Cesium) {
					    var toolbar =document.getElementById('toolbar');
					    var viewer = new Cesium.Viewer('cesiumContainer');
					    var routes = new Cesium.RouteCollection(viewer.entities);
					    var scene = viewer.scene;
						var url1="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Building@CBD/config";
								  var url2="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Ground@CBD/config";
								  var url3="http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/datas/Waters@CBD/config";
								  var infoboxContainer=document.getElementById("bubble");
								  viewer.customInfobox=infoboxContainer;
								  var widget =viewer.cesiumWidget;
								  try{
									  var promise =scene.addS3MTilesLayerByScp(url1 ,{name :'Building'});
									  var promise1=scene.addS3MTilesLayerByScp(url2, {name :'Ground'});
									  var promise2=scene.addS3MTilesLayerByScp(url3, {name :'Waters'});
									  Cesium.when(promise,function(layer){scene.camera.setView({destination : Cesium.Cartesian3.fromDegrees(116.4581104772965,39.91229850123048,2500)});
																		 },function(e){
										  if (widget._showRenderLoopErrors){
											  var title ='An error';
											  widget.showErrorPanel(title,undefined,e);
										  }
									  });
									  
								  }
								  catch(e){
									  if(widget._showRenderLoopErrors){
										  var title='An error';
										  widget.showErrorPanel(title,undefined,e);
									  }
								  }
						//添加fpf飞行文件,fpf由SuperMap iDesktop生成
					    var fpfUrl='./fpf/飞行.fpf';
					    routes.fromFile(fpfUrl);
					    var promise =scene.open("http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace/scenes/CBD");
				        promise.then(function(layers){});
						
						scene.globe.depthTestAgainstTerrain = false;
					    //初始化飞行管理
					    var flyManager = new Cesium.FlyManager({
					        scene: scene,
					        routes: routes
					    });
					    //注册站点到达事件
					    flyManager.stopArrived.addEventListener(function (routeStop) {
					        routeStop.waitTime = 1.5; // 在每个站点处停留1.5s
					    });
					
					    flyManager.readyPromise.then(function (){ // 飞行路线就绪
					        var currentRoute = flyManager.currentRoute;
					        currentRoute.isLineVisible = true;
					        currentRoute.isStopVisible = true;
					        //生成飞行文件中的所有站点列表
					        var allStops = flyManager.getAllRouteStops();
					        var menu = document.getElementById('stopList');
					        for (var i = 0, j = allStops.length; i < j; i++) {
					            var option = document.createElement('option');
					            option.innerHTML = "站点 " + (i + 1);
					            option.value = allStops[i].index;
					            menu.appendChild(option);
					        }
					
					        $('#stopList').change(function () { //注册站点切换事件
					            flyManager && flyManager.stop();
					            var index = parseInt($(this).val()); // 站点的索引
					            var route = flyManager.currentRoute;
					            var stop = route.get(index);
					            flyManager.currentStopIndex = index;
					            flyManager.viewToStop(stop);
					        });
					
					        $('#play').click(function () {
					            flyManager && flyManager.play();
					        });
					        $('#pause').click(function () {
					            flyManager && flyManager.pause();
					        });
					        $('#stop').click(function () {
					            flyManager && flyManager.stop();
					        });
					
					        $('#show-line').change(function(){
					            currentRoute.isLineVisible = $(this).prop('checked');
					        });
					
					        $('#show-stop').change(function(){
					            currentRoute.isStopVisible = $(this).prop('checked');
					        });
					
					        $('#toolbar').show();
					        $('#loadingbar').remove();
					    });
				}
		</script>

您好,飞行管理不起作用吗?我这边运行您的代码是可行的,您看看您那里控制台有报什么错。

这样的报错

打开场景的时候出错,我把您发的两个代码整理了一下发到您的私信里,您看看运行可行不。

我改了一下fpf文件地址   可以了   谢谢大佬了

为什么不能这样加载模型数据   而要你那样写var promise = scene.open(URL_CONFIG.SCENE_CBD);      open()这个括号里的是地址嘛   你能告诉我这个相关的知识嘛

scene.open()是打开缓存场景,scene.addS3MTilesLayerByScp是添加S3M缓存,这两种方式都是可以的,但您在一个文件里两种方式都写了,而且还有重复命名,打开的时候就会出现冲突报错。
偶 知道了   谢谢了

你好,我又来了 。我想在这个框内  加按钮

然后实现收起  展开的功能    为什么实现不了    而且这个收起的div一定要写在那个框内 没写就看不见 这是为什么啊。。。。。

这是我的代码

<div id="toolbar" class="param-container tool-bar">
			<div class="buttonblack">	
			<span type="button" id="play" class="button black" title="开始"></span>
			<span type="button" id="pause" class="button black" title="暂停"></span>
			<span type="button" id="stop" class="button black" title="停止"></span>
		
			</div>
			<div style="width: 150px;">
				<select id="stopList" class="form-control" style="width: 100%;">
				</select>
			</div>
			<div class="checkbox">
				<label>
					<input type="checkbox" id="show-line" checked> 显示飞行路线
				</label>
			</div>
			<div class="checkbox">
				<label>
					<input type="checkbox" id="show-stop" checked> 显示飞行站点
				</label>
			</div>
		
		<div class="spana">
			<span type="button" class="spanb">收起</span>
		</div>	
		</div> 
<script type="text/javascript">
var flyManager;
		  function onload(Cesium) {
			var toolbar =document.getElementById('toolbar');
			var viewer = new Cesium.Viewer('cesiumContainer');
			var routes = new Cesium.RouteCollection(viewer.entities);
			var scene = viewer.scene;
			var camera =viewer.camera;
var promise = scene.open("http://localhost:8090/iserver/services/3D-CBD-2/rest/realspace");
		      promise.then(function (layers) {
				  camera.setView({
				      destination: Cesium.Cartesian3.fromDegrees(116.4581, 39.9122, 2000)
					  });
			  });
		       scene.globe.depthTestAgainstTerrain = false;
			    //添加fpf飞行文件,fpf由SuperMap iDesktop生成
			   var fpfUrl='./fpf/飞行.fpf';
			   routes.fromFile(fpfUrl);
			    //初始化飞行管理
			    var flyManager = new Cesium.FlyManager({
				   scene: scene,
				   routes: routes
			    });
			  //注册站点到达事件
			    flyManager.stopArrived.addEventListener(function (routeStop) {
				routeStop.waitTime = 0.6; // 在每个站点处停留1.5s
			     });

			    flyManager.readyPromise.then(function (){ // 飞行路线就绪
				    var currentRoute = flyManager.currentRoute;
				    currentRoute.isLineVisible = true;
				    currentRoute.isStopVisible = true;
				     //生成飞行文件中的所有站点列表
				    var allStops = flyManager.getAllRouteStops();
				    var menu = document.getElementById('stopList');
				   for (var i = 0, j = allStops.length; i < j; i++) {
					var option = document.createElement('option');
					option.innerHTML = "站点 " + (i + 1);
					option.value = allStops[i].index;
					menu.appendChild(option);
				    }

				$('#stopList').change(function () { //注册站点切换事件
					flyManager && flyManager.stop();
					var index = parseInt($(this).val()); // 站点的索引
					var route = flyManager.currentRoute;
					var stop = route.get(index);
					flyManager.currentStopIndex = index;
					flyManager.viewToStop(stop);
				});

				$('#play').click(function () {
					flyManager && flyManager.play();
				});
				$('#pause').click(function () {
					flyManager && flyManager.pause();
				});
				$('#stop').click(function () {
					flyManager && flyManager.stop();
				});

				$('#show-line').change(function(){
					currentRoute.isLineVisible = $(this).prop('checked');
				});

				$('#show-stop').change(function(){
					currentRoute.isStopVisible = $(this).prop('checked');
				});

				$('#toolbar').show();
				$('#loadingbar').remove();
			 });
			 
		}
		//展开和收起
		$(document).ready(function(){
						 $('spanb').click(function(){
							 if($(this).text()=='展开')
							 {
								 $('#toolbox').show();
								 $(this).text('收起');
							 }
							 else
							 {
								 $('#toolbox').hide();
								 $(this).text('展开');
							 }
						 });
		});
</script>

...