//第1步骤:事故模拟 class Sgmn1Sgfx { //========== 构造方法 ========== //创建一个模型编辑对象 constructor(map, options) { this.map = map; this.gaoDePoi = new mars3d.query.GaodePOI({ // key: ['ae29a37307840c7ae4a785ac905927e0'], }); this.ellipseArr = []; //保存事故范围的椭圆 this.interval = -1; this.iNow = 0; //开始时间 this.iALLTime = 60; //总时长时间 this.iALL = 6; //模拟总次数 this.isStartPlay = false; //用于标记是否开始模拟 this.windArg = null; this.affectedPointArr = []; //受影响点的坐标信息 this.affectedYWArr = []; //受影响的业务点 模拟=== this.timelineCallback = null; //用于同步进度轴 this.bootstrapTableCallback = null; // 用于同步查询结果 this.pageNum = 1; //当前页码 this.newPoint = null; //当前查询的中心点 this._radiusX = null; //当前查询的范围 this.lastEllipseData = null; //模拟范围的最后一个椭圆 this.isLoadMore = false; this.graphicLayer = new mars3d.layer.GraphicLayer({ hasEdit: false, }); map.addLayer(this.graphicLayer); this.queryData = []; //当前查询的结果 this.oneQueryEnd = false; //标识一次查询结束 this._setArgAgain = false; } //========== 对外属性 ========== //模拟点 get point() { return this.incidentLnglat; } //获取最后一个椭圆的相关信息 get extentData() { return this.lastEllipseData; } //获取所有受影响的企业点 get pois() { return this.affectedPointArr; } //获取受影响的业务点 get YWpois() { return this.affectedYWArr; } //获取所有受影响的点 get allPois() { return this.affectedPointArr.concat(this.affectedYWArr); } //获取影响的范围 get radiusX() { return this._radiusX; } //获取事故影响点 get sgDatas() { return this.queryData; } //事故模拟是否结束 get state() { return this.iNow > this.iALL && this.oneQueryEnd; } // set _setArgAgain(bool){ // this.argAgain = bool; // } // get argAgain(){ // return this.argAgain; // } //========== 方法 ========== //开始激活(需求的参数通过opts传入) start(arg, opt) { if (this.windArg && arg) { if (this.windArg.windSpeed != arg.windSpeed || this.windArg.windDirection != arg.windDirection || this.windArg.playSpeed != arg.playSpeed) { this.clearRes(); this._setArgAgain = true; } } if (this.isStartPlay && !this._setArgAgain && this.iNow == 0) { //不用分析 opt.noComputeCallback(); return; } if (!this.windArg) { this.windArg = arg; } if (!this.timelineCallback) { this.timelineCallback = opt.timelineCallback; } if (!this.bootstrapTableCallback) { this.bootstrapTableCallback = opt.bootstrapTableCallback; } var _fs = this.windArg.windSpeed; //风速 m/s var _fx = Number(this.windArg.windDirection); //风向 var _sd = Number(this.windArg.playSpeed); //速度 var speed = 15 / _sd; var that = this; this.interval = setInterval(function () { that.isStartPlay = true; that.iNow++; if (that.iNow > that.iALL || that.iNow < 0) { that.stopPlay(); return; } var time = (that.iNow / that.iALL) * that.iALLTime; that._addMnCicles(time, _fs, _fx); if (that.timelineCallback) { that.timelineCallback(that.iNow); } }, speed * 1000); } //开始 图上选择事故点 selectSgd(callback) { var that = this; this.graphicLayer.startDraw({ type: "billboard", style: { image: "img/marker/mark1.png", horizontalOrigin: Cesium.HorizontalOrigin.CENTER, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, }, success: function (graphic) { var point = graphic.point; if (!point) { return; } var data = { x: point.lng, y: point.lat, z: point.alt, }; that.incidentLnglat = [point.lng, point.lat, point.alt]; if (that.sgdGraphic == null) { that.sgdGraphic = graphic; } else { that.clearRes(); //重新选点后 清除之前的结果 graphic.remove(); that.sgdGraphic.position = point; if (that.isStartPlay) { that.argAgain = true; } } callback(data); }, }); } //移除事故点 removeSgd() { if (this.sgdGraphic) { this.sgdGraphic.remove(); this.sgdGraphic = null; } } //事故模拟结束 stopPlay() { if (!this.isStartPlay) { return; } //$("#btn_sgmn_start").html('开始模拟'); clearInterval(this.interval); // this.isStartPlay = false; } //暂停模拟 pausePlay() { //事故模拟暂停 if (!this.isStartPlay) { return; } clearInterval(this.interval); //this.isStartPlay = false; } //添加事故模拟范围 _addMnCicles(_time, _fs, _fx) { //_time时间(分钟),_fs 风速(m/s),_fx风向 //此处加入公式,计算出半径 var distance = (_time * 60 * _fs) / 1000; //公里 var bearing = _fx; if (!this.incidentLnglat || this.incidentLnglat.length == 0) { return; } var point = turf.point([this.incidentLnglat[0], this.incidentLnglat[1]]); var newpoint = turf.destination(point, distance, bearing, { units: "kilometers", }); this.newPoint = { x: newpoint.geometry.coordinates[0], y: newpoint.geometry.coordinates[1], z: this.incidentLnglat[2], }; var radiusX = (this._radiusX = distance); var radiusY = distance * 0.6; var angle = 90 - _fx; //椭圆 var entity = this.graphicLayer.dataSource.entities.add({ position: Cesium.Cartesian3.fromDegrees(this.newPoint.x, this.newPoint.y, this.newPoint.z), ellipse: { show: true, semiMajorAxis: radiusX * 1000, semiMinorAxis: radiusY * 1000, rotation: Cesium.Math.toRadians(angle), classificationType: Cesium.ClassificationType.BOTH, fill: true, material: Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.4), outline: true, outlineColor: Cesium.Color.fromCssColorString("#ffffff").withAlpha(0.7), outlineWidth: 2, }, }); this.ellipseArr.push(entity); this.map.flyTo(entity, { duration: 2, }); this.pausePlay(); //暂停 此时暂停 用于计算范围内的点 //计算椭圆焦点 var temp = (radiusX - radiusY) / 2; var pt1 = turf.destination(point, temp, bearing, { units: "kilometers", }); var pt2 = turf.destination(point, radiusX + radiusY + temp, bearing, { units: "kilometers", }); var item = { center: this.newPoint, //中心点 radiusX: radiusX * 1000, //长半轴(米) radiusY: radiusY * 1000, //短半轴(米) pt1: { x: pt1.geometry.coordinates[0], y: pt1.geometry.coordinates[1], }, //焦点1 pt2: { x: pt2.geometry.coordinates[0], y: pt2.geometry.coordinates[1], }, //焦点2 }; this.pageNum = 1; this.radius = radiusX * 1000; this.oneQueryEnd = false; this.queryPOI({ location: [this.newPoint.x, this.newPoint.y], radius: this.radius, page: this.pageNum, }); //记录最后一个椭圆 用于查询结束后筛选 this.lastEllipseData = item; this.queryYwData(item); } //查询 queryPOI(opts) { var that = this; var arg = {}; arg.location = opts.location; arg.radius = opts.radius; arg.count = 10; //count 每页数量 arg.text = "企业"; arg.page = opts.pageNum; arg.success = function (res) { that.oneQueryEnd = true; var data = res.list; that.queryData = []; that.queryData.concat(data); that.addEntity(data); if (that.bootstrapTableCallback) { that.bootstrapTableCallback(data); } that.start(); }; arg.error = function (msg) { window.toastr.error(msg); }; this.gaoDePoi.queryCircle(arg); } //加载更多 loadMore(callback) { this.isLoadMore = true; this.pageNum++; if (!this.newPoint || !this.pageNum) { return; } var that = this; var arg = {}; arg.location = [this.newPoint.x, this.newPoint.y]; arg.radius = this.radius; arg.count = 10; arg.text = "企业"; arg.page = this.pageNum; arg.success = function (res) { var data = res.list; that.queryData.concat(data); that.addEntity(data); if (callback) { callback(data); } }; arg.error = function (msg) { window.toastr.error(msg); }; this.gaoDePoi.queryCircle(arg); } //添加事故范围内受影响的点 addEntity(data) { if (!this.isLoadMore) { this.clearPointArr(); //椭圆变化时 清除上一次的结果 , 点击加载更多则不清除 this.affectedPointArr = []; //清空之前的数据 } for (var i = 0; i < data.length; i++) { var item = data[i]; //==================构建图上目标单击后显示div================= var inHtml = '