From 8f85627f215bd0ee61db7a35ca9a83eaca1e892c Mon Sep 17 00:00:00 2001 From: surprise <15810472099@163.com> Date: 星期三, 10 一月 2024 15:42:34 +0800 Subject: [PATCH] 代码更新 --- src/assets/js/Layer/drawGrid.js | 87 +++++++++++++++++++++++++++++++++---------- 1 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src/assets/js/Layer/drawGrid.js b/src/assets/js/Layer/drawGrid.js index eb27f5a..40fb77e 100644 --- a/src/assets/js/Layer/drawGrid.js +++ b/src/assets/js/Layer/drawGrid.js @@ -140,11 +140,11 @@ var start_hest = turf.destination(start_west, hStep * i, hAngle, op).geometry.coordinates; var end_hest = turf.destination(end_west, hStep * i, hAngle, op).geometry.coordinates; var val = [ - [start_west[0], start_west[1],18], - [end_west[0], end_west[1],18], - [end_hest[0], end_hest[1],18], - [start_hest[0], start_hest[1],18], - [start_west[0], start_west[1],18] + [start_west[0], start_west[1], 18], + [end_west[0], end_west[1], 18], + [end_hest[0], end_hest[1], 18], + [start_hest[0], start_hest[1], 18], + [start_west[0], start_west[1], 18] ] this.setInsertGridData(val, (i * j)) } @@ -154,15 +154,62 @@ store.state.isshowGrid = false; - this.drawPoint(res); + // this.drawPoint(res); + this.drawRects(res) + }, + + drawRects: function (res) { + this.cc = 0; + var rect = viewer.entities.getById(this.id); + if (!rect) return; + var points = rect.polygon.hierarchy.getValue().positions; + viewer.entities.removeAll(); // viewer.entities.remove(rect); + + var r0 = Cesium.Cartographic.fromCartesian(points[0]); + var r1 = Cesium.Cartographic.fromCartesian(points[1]); + var r2 = Cesium.Cartographic.fromCartesian(points[2]); + + var p0 = turf.point([(r0.longitude * 180) / Math.PI, (r0.latitude * 180) / Math.PI]); + var p1 = turf.point([(r1.longitude * 180) / Math.PI, (r1.latitude * 180) / Math.PI]); + var p2 = turf.point([(r2.longitude * 180) / Math.PI, (r2.latitude * 180) / Math.PI]); + + // 鍋氭垚 3 * 4 鐨勭綉鏍� + // var wCount = 3, hCount = 4; + var wCount = res.col, hCount = res.row; + this.flag = parseInt(wCount) * parseInt(hCount); + var op = { units: "meters", }; + var wStep = turf.distance(p0, p1, op) / wCount; + var hStep = turf.distance(p1, p2, op) / hCount; + var wAngle = turf.bearing(p0, p1); + var hAngle = turf.bearing(p1, p2); + this.removeRect(); + for (var i = 0; i < wCount; i++) { + var ds = turf.destination(p0, wStep * i, wAngle, op); + for (var j = 0; j < hCount; j++) { + var d1 = turf.destination(ds.geometry.coordinates, hStep * j, hAngle, op); + var d2 = turf.destination(d1.geometry.coordinates, wStep, wAngle, op); + var d3 = turf.destination(d2.geometry.coordinates, hStep, hAngle, op); + var d4 = turf.destination(d1.geometry.coordinates, hStep, hAngle, op); + + // var arr = [d1.geometry.coordinates, d2.geometry.coordinates, d3.geometry.coordinates, d4.geometry.coordinates]; + var arr = [ + [d1.geometry.coordinates[0], d1.geometry.coordinates[1], 18], + [d2.geometry.coordinates[0], d2.geometry.coordinates[1], 18], + [d3.geometry.coordinates[0], d3.geometry.coordinates[1], 18], + [d4.geometry.coordinates[0], d4.geometry.coordinates[1], 18], + [d1.geometry.coordinates[0], d1.geometry.coordinates[1], 18] + ] + this.setInsertGridData(arr, ((i + 1) * (j + 1))); + } + } }, async setInsertGridData(res, num) { var obj = { "type": "Feature", "properties": - { "ID": num, "NAME": "Area8", "REMARK": "" }, + { "ID": num, "NAME": "Area" + num, "REMARK": "", "TYPE": 'DrawGrid' }, "geometry": { "type": "Polygon", @@ -171,24 +218,24 @@ ] } } - const data = await Grid_Insert({ json: JSON.stringify(obj) }) if (data.status == 200) { this.ids.push(data.data) + if (this.ids.length == this.flag) { + var obj = { + id: new Date().getTime(), + sourceType: 'DrawGrid', + name: "鏂板缓鏍肩綉", + style: { + ids: this.ids, + sourceType: 'DrawGrid', + } + } + Bus.$emit("addOtherData", "瀵硅薄", obj); + } } - if (this.flag == num) { - var obj = { - id: new Date().getTime(), - sourceType: 'DrawGrid', - name: "鏂板缓鏍肩綉", - style: { - ids: this.ids, - sourceType: 'DrawGrid', - } - } - Bus.$emit("addOtherData", "瀵硅薄", obj); - } + } }; export default drawGrid -- Gitblit v1.9.3