使用ScanEffect扫描线效果时,viewer.scene.scanEffect.show = true;报错如下图:
您好,我的代码如下:
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>扫描效果</title> <link href="../Build/Cesium/Widgets/widgets.css" rel="stylesheet"> <link href="./css/pretty.css" rel="stylesheet"> <script type="text/javascript" src="./js/jquery.min.js"></script> <script src="./js/config.js"></script> <script src="./js/tooltip.js"></script> <script src="./js/spectrum.js"></script> <script type="text/javascript" src="./js/require.min.js" data-main="js/main"></script> </head> <body> <div id="cesiumContainer"></div> <script> function onload(Cesium) { $(".params-setting-anchor").click(function(){ $(".params-setting").toggleClass("params-setting-hide"); }); var viewer = new Cesium.Viewer('cesiumContainer',{ infobox:false }); viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({ url : 'https://dev.virtualearth.net', mapStyle : Cesium.BingMapsStyle.AERIAL, key : URL_CONFIG.BING_MAP_KEY })); var scene = viewer.scene; scene.fxaa = true; scene.skyAtmosphere.show = false; var promise = scene.open(URL_CONFIG.SCENE_CBD); Cesium.when(promise,function(layers){ var tooltip = createTooltip(document.body); var tooltipMsg = ""; var clickCount = 0; var refLayer = layers[0]; viewer.scene.scanEffect.show = true; var pos = new Cesium.Cartesian3.fromDegrees(refLayer.lon,refLayer.lat,10.0); viewer.scene.scanEffect.centerPostion = pos; viewer.scene.scanEffect.mode = Cesium.ScanEffectMode.CIRCLE; viewer.scene.scanEffect.period = 5; viewer.scene.scanEffect.speed = 100; //设置相机位置,定位至模型 scene.camera.setView({ destination : new Cesium.Cartesian3(-2180733.097675902, 4379639.149392802, 4092613.146140101), orientation:{ heading: 4.419871112141432, pitch: -0.40767078314183536, roll: 1.0658141036401503e-14 } }); // 初始化颜色选择控件 var initialScanColor = "#2263e6"; viewer.scene.scanEffect.color = Cesium.Color.fromCssColorString(initialScanColor); $("#scan-color").spectrum({ color: initialScanColor, chooseText: "确定", cancelText: "取消", showAlpha: true, change: function(color){ var colorObj = color.toRgb(); viewer.scene.scanEffect.color = new Cesium.Color(colorObj.r / 255, colorObj.g / 255, colorObj.b /255, colorObj.a); } }); }); } </script> </body>
您好,您看一下您的这段代码:
reflayer这个是您获取到的一个图层,您这边通过reflayer.lon来获取的经度吗,你可以打印一下看一下reflayer.lon是否是经度值
您这边可以参考一下下面的来设置扫描线的中心点
您好,打印了refLayer.lon和refLayer.lat,确实是经纬度,然后我用您上面说的那样设置中心位置,代码如下:
viewer.scene.scanEffect.show = true; var startPosition = new Cesium.Cartesian3.fromDegrees(116.45811047729649,39.91229850123048,10.0); viewer.scene.scanEffect.centerPostion = startPosition; viewer.scene.scanEffect.mode = Cesium.ScanEffectMode.CIRCLE; viewer.scene.scanEffect.period = 5; viewer.scene.scanEffect.speed = 100;
还是会报错:
而且,并不是每次运行代码都会报错,有时会报错,有时可以运行。
我这边测试的自动开始的扫描线是没有报错的,不知您这边的webgl包是多久下载下来的呢,能否压一个webgl包以网盘的形式发给我验证一下呢
您好,我这边用您上面的代码,删除一些,只留下关键性的代码是没有任何报错的,建议您这边再检查一下您这边的是否是其他的代码的问题
https://pan.baidu.com/s/1ky6w8fO0cnofajvXnlYGNA
问题解决了么?我也碰到了这个问题