XWWitPark/witpark_jzzs/xw_jzzs_web/public/widgets/queryRoute/widget.js
2024-09-12 08:10:00 +08:00

2 lines
7.6 KiB
JavaScript

/* 2020-9-24 14:48:24 | 版权所有 军懋国兴 */
mars3d.widget.bindClass(mars3d.widget.BaseWidget.extend({options:{resources:["./lib/cesiumjs/plugins/class/GaodeRoute.js","./lib/cesiumjs/plugins/class/GaodePOI.js"],view:{type:"window",url:"view.html",windowOptions:{width:350}}},create:function(){},viewWindow:null,winCreateOK:function(t,e){this.viewWindow=e},gaodeRoute:null,gaodePOI:null,activate:function(){this.gaodeRoute=new GaodeRoute,this.gaodePOI=new GaodePOI},disable:function(){this.gaodeRoute=null,this.startLnglat=null,this.endLnglat=null,this.startPoint&&(this.viewer.mars.draw.deleteEntity(this.startPoint),this.viewer.entities.remove(this.startPoint),this.startPoint=null),this.endPoint&&(this.viewer.mars.draw.deleteEntity(this.endPoint),this.viewer.entities.remove(this.endPoint),this.endPoint=null),this.alreadyCompute=!1,this.gaodePOI=null,this.gaodeRoute=null,this.startLnglat=null,this.startPoint=null,this.endLnglat=null,this.endPoint=null,this.clearCoumpute()},queryPOI:function(t,e){var i;t&&e&&((i={success:function(t){this.viewWindow.setHtmlInMCXD(t,e)},error:function(t){window.toastr.error(t),haoutil.loading.close()}}).text=t,this.gaodePOI&&this.gaodePOI.queryText(i))},startLnglat:null,startPoint:null,drawStartPoint:function(o){var a=this;a.viewer.mars.draw.startDraw({type:"billboard",style:{image:this.path+"img/start.png"},success:function(t){var e=a.viewer.clock.currentTime,i=t.position.getValue(e),r=Cesium.Cartographic.fromCartesian(i),n=Number(Cesium.Math.toDegrees(r.longitude).toFixed(6)),s=Number(Cesium.Math.toDegrees(r.latitude).toFixed(6));o&&o(n+","+s),a.startLnglat=[n,s],a.startPoint?(a.viewer.mars.draw.deleteEntity(t),a.startPoint.position.setValue(i)):a.startPoint=t,a.startCompute()}})},inputStartPoint:function(t,e){var i,r;t&&e&&(this.startPoint&&(this.viewer.mars.draw.deleteEntity(this.startPoint),this.viewer.entities.remove(this.startPoint)),this.startLnglat=[t,e],i=Cesium.Cartesian3.fromDegrees(t,e),r=this.viewer.entities.add({position:i,billboard:{image:this.path+"img/start.png",horizontalOrigin:Cesium.HorizontalOrigin.CENTER,verticalOrigin:Cesium.VerticalOrigin.BOTTOM,scale:1,heightReference:Cesium.HeightReference.CLAMP_TO_GROUND}}),this.startPoint=r,this.locateByJWD({jd:t,wd:e}),this.startCompute())},queryStartPoint:function(t){t?this.queryPOI(t,"start"):window.toastr.error("请输入查询条件!")},endPoint:null,endLnglat:null,drawEndPoint:function(o){var a=this;a.viewer.mars.draw.startDraw({type:"billboard",style:{image:this.path+"img/end.png"},success:function(t){var e=a.viewer.clock.currentTime,i=t.position.getValue(e),r=Cesium.Cartographic.fromCartesian(i),n=Number(Cesium.Math.toDegrees(r.longitude).toFixed(6)),s=Number(Cesium.Math.toDegrees(r.latitude).toFixed(6));o&&o(n+","+s),a.endLnglat=[n,s],a.endPoint?(a.viewer.mars.draw.deleteEntity(t),a.endPoint.position.setValue(i)):a.endPoint=t,a.startCompute()}})},inputEndPoint:function(t,e){var i,r;t&&e&&(this.endPoint&&(this.viewer.mars.draw.deleteEntity(this.endPoint),this.viewer.entities.remove(this.endPoint)),this.endLnglat=[t,e],i=Cesium.Cartesian3.fromDegrees(t,e),r=this.viewer.entities.add({position:i,billboard:{image:this.path+"img/end.png",horizontalOrigin:Cesium.HorizontalOrigin.CENTER,verticalOrigin:Cesium.VerticalOrigin.BOTTOM,scale:1,heightReference:Cesium.HeightReference.CLAMP_TO_GROUND}}),this.endPoint=r,this.locateByJWD({jd:t,wd:e}),this.startCompute())},queryEndPoint:function(t){t?this.queryPOI(t,"end"):window.toastr.error("请输入查询条件!")},clearCoumpute:function(){for(var t=this.colorStep=0;t<this.routeArr.length;t++){var e=this.routeArr[t];e&&this.viewer.entities.remove(e)}this.routeArr=[],this.viewWindow.clearRouteContent();for(var i=0;i<this.flyLineArr.length;i++){var r=this.flyLineArr[i];r&&r.destroy()}this.flyLineArr=[],this.removeTrack(),this.nowFline&&(this.nowFline.destroy(),this.nowFline=null),$("#mapDH_speed").remove()},alreadyCompute:!1,startCompute:function(){var r;this.startLnglat&&0!=this.startLnglat.length&&this.endLnglat&&0!=this.endLnglat.length&&(this.alreadyCompute&&this.clearCoumpute(),(r=this).gaodeRoute.query({type:3,points:[this.startLnglat,this.endLnglat],extensions:"all",strategy:11,success:function(t){if(r.alreadyCompute=!0,r.viewWindow.startCompute(),t&&!(t.paths.length<1)){r.viewWindow.showRouteBox(!0);for(var e=0;e<t.paths.length;e++){var i=r.addRouteLine(t.paths[e]);if(!i)return;r.routeArr.push(i),r.viewWindow.showRouteInfo(i),r.computeFlyline(i)}}}}))},randomColor:[new Cesium.Color.fromCssColorString("#eaf731").withAlpha(.8),new Cesium.Color.fromCssColorString("#57f72e").withAlpha(.8),new Cesium.Color.fromCssColorString("#2effd2").withAlpha(.8),new Cesium.Color.fromCssColorString("#cc6e26").withAlpha(.8),new Cesium.Color.fromCssColorString("#ff2ec7").withAlpha(.8)],colorStep:0,routeArr:[],addRouteLine:function(t){var e=t.steps,i=t.points;if(!(!e||e.length<1||!i||i.length<1)){this.colorStep>this.randomColor.length-1&&(this.colorStep=0);var r=this.randomColor[this.colorStep],n=mars3d.pointconvert.lonlats2cartesians(i),s=this.viewer.entities.add({polyline:{positions:n,clampToGround:!0,material:r,width:3}});return s.attr=t,this.colorStep++,s}},flyLineArr:[],computeFlyline:function(t){var e,i;t&&t.attr&&(e={name:"贴地路线",camera:{type:""},points:t.attr.points,speed:200,model:{uri:serverURL_gltf+"/mars/qiche.gltf",scale:.3,minimumPixelSize:30,clampToGround:!0,show:!0}},(i=new mars3d.FlyLine(this.viewer,e)).lineId=t.id,this.flyLineArr.push(i))},getFlylineById:function(t){if(t){for(var e,i=0;i<this.flyLineArr.length;i++)if(this.flyLineArr[i].lineId==t){e=this.flyLineArr[i];break}return e}},nowFline:null,roamOneById:function(t){for(var e,i=0;i<this.flyLineArr.length;i++)this.flyLineArr[i].stop(),this.flyLineArr[i].lineId==t&&(e=this.flyLineArr[i]);this.nowFline=e,this.viewer.mars.popup.close(),this.viewer.mars.popup.show(e,e.property);var r=this;e.start(function(){r.reset(),r.cameraView&&r.viewer.mars.centerAt(r.cameraView)})},reset:function(){this.resetBtn(),this.removeTrack(),this.nowFline&&(this.nowFline.entity.show=!1,this.nowFline=null),this.viewer.clock.multiplier=1,this.highLightLine()},resetBtn:function(){this.viewWindow.resetButton(),this.viewer.mars.popup.close()},removeTrack:function(){this.nowFline&&this.nowFline.updateStyle({camera:{type:""}}),this.viewer.trackedEntity=void 0},startDH:function(t,e){this.reset(),t&&(this.roamOneById(t),e&&this.nowFline.updateStyle({camera:{type:"gs"}}))},startGS:function(t,e){if(this.nowFline){if(this.nowFline.lineId!=t)return window.toastr.error("当前路径无车辆运行!"),void(e&&e.prop("checked",!1));this.nowFline.updateStyle({camera:{type:"gs"}})}},highLightLine:function(t){for(var e,i,r=this.viewer.clock.currentTime,n=0;n<this.routeArr.length;n++){var s=this.routeArr[n].polyline.material.color.getValue(r);this.routeArr[n].polyline.material=new Cesium.Color(s.red,s.green,s.blue,.3),this.routeArr[n].polyline.width=3}t&&(i=(e=this.viewer.entities.getById(t)).polyline.material.color.valueOf(),e.polyline.material=new Cesium.Color(i.red,i.green,i.blue,1),e.polyline.width=5)},locateByJWD:function(t){var e,i,r,n,s,o;t&&t.jd&&t.wd&&(e=Cesium.Cartesian3.fromDegrees(t.jd,t.wd,t.gd||0),i=Cesium.Math.toRadians(t.heading||0),r=Cesium.Math.toRadians(t.pitch||-90),n=Cesium.Math.toRadians(t.roll||0),s=new Cesium.HeadingPitchRange(i,r,n),o=new Cesium.BoundingSphere(e,t.cameraHeight||2e3),this.viewer.camera.viewBoundingSphere(o,s),this.viewer.scene.camera.lookAtTransform(Cesium.Matrix4.IDENTITY))},getCameraView:function(){this.cameraView=mars3d.point.getCameraView(this.viewer,!1)},setCameraView:function(){this.cameraView&&this.viewer.mars.centerAt(this.cameraView)},resetSpeed:function(t){null!=t&&(this.viewer.clock.multiplier=t/120)}}));