在用webgl方式调用场景的时候,场景无法打开,报错:scene.open is not a function
请问这个是什么原因?
这是我的代码,初学很多不明白,请多指教
<!DOCTYPE html> <html lang="en"> <head> <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>洪门湖智慧湿地场景</title> <link href="Build/Cesium/Widgets/widgets.css" rel="stylesheet"> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/pretty.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 type="text/javascript" src="js/require.min.js" data-main="js/main"></script> <style> html, body, #cesiumContainer { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;background-color: #000000; } </style> </head> <body> <div id="cesiumContainer"></div> <div id='loadingbar' class="spinner"></div> <div id='toolbar' style="position : absolute;left : 5px; top : 5px;display: none;" > </div> <script> function onload(Cesium) { var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.scene; scene.globe.depthTestAgainstTerrain = false; var camera = scene.camera; var widget = viewer.cesiumWidget; //添加S3M图层服务 <!--StartFragment --> //移除logo var credit=viewer.scene.frameState.creditDisplay; credit.container.removeChild(credit._imageContainer); try{ var promise = scene.open('http://localhost:8090/iserver/services/3D-HMHSD2/rest/realspace') } catch(e){ if (widget._showRenderLoopErrors) { var title = '渲染时发生错误,已停止渲染。'; widget.showErrorPanel(title, undefined, e); } } } </script> </body> </html>
我按照范例写代码如下:
<!DOCTYPE html> <html lang="en"> <head> <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>洪门湖智慧湿地场景</title> <link href="../Build/Cesium/Widgets/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 type="text/javascript" src="./js/require.min.js" data-main="js/main"></script> <style> html, body, #cesiumContainer { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;background-color: #000000; } </style> </head> <body> <div id="cesiumContainer"></div> <div id='loadingbar' class="spinner"></div> <div id='toolbar' style="position : absolute;left : 5px; top : 5px;display: none;" > </div> <script> function onload(Cesium) { var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.scene; scene.globe.depthTestAgainstTerrain = false; var camera = scene.camera; var widget = viewer.cesiumWidget; //添加S3M图层服务 <!--StartFragment --> //移除logo var credit=viewer.scene.frameState.creditDisplay; credit.container.removeChild(credit._imageContainer); try{ var promise = scene.open('http://localhost:8090/iserver/services/3D-HMHSD2/rest/realspace'); promise.then(function(layers){ }); } catch(e){ if (widget._showRenderLoopErrors) { var title = '渲染时发生错误,已停止渲染。'; widget.showErrorPanel(title, undefined, e); } } } </script> </body> </html>
结果如下图:不知道什么原因。并且scene.open仍然是报错
已经替换过,但场景无法显示。
刚刚用IE测试,报错对象不支持open属性方法
http://support.supermap.com.cn:8090/webgl/examples/editor.html#S3MTiles_jingmo你直接在这里改,替换url和相机位置即可,右下角可以查看源码,在线改。
一把url换掉就变成了这个样子
也有报错
我的意思是你修改在线范例显示不出来场景是不是有啥报错,你本地的范例我估计依赖包的路径都不对。建议你下载最新webgl包,重新解压一下,先看看原始范例有无问题,然后再替换数据试试有无问题。http://support.supermap.com.cn:8090/webgl/download.html
浏览器报错指定的前缀未进行声明,这怎么办?