BuildingStretchingAnalysis.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <div
  3. class="ZTGlobal"
  4. style="width: 100%; padding: 1rem 1rem 0rem 1rem; color: white"
  5. >
  6. <el-row :gutter="10">
  7. <el-col :span="24">
  8. <el-row :gutter="10">
  9. <el-col :span="12" style="text-align: center">
  10. 楼体高度:
  11. <el-input-number
  12. size="mini"
  13. step="1"
  14. :min="1"
  15. v-model="form.BuildingHeight"
  16. @change="XYChange"
  17. ></el-input-number>
  18. </el-col>
  19. <el-col :span="12" style="text-align: center">
  20. 层高:
  21. <el-input-number
  22. size="mini"
  23. step="0.1"
  24. :min="1"
  25. v-model="form.FLOORH"
  26. @change="XYChange"
  27. ></el-input-number>
  28. </el-col>
  29. </el-row>
  30. <div class="SaveCenter">
  31. <el-button size="mini" type="primary" @click="onSubmit"
  32. >开始调整</el-button
  33. >
  34. <el-button size="mini" @click="removeEntities">清除</el-button>
  35. </div>
  36. </el-col>
  37. </el-row>
  38. </div>
  39. </template>
  40. <script>
  41. import { v4 as uuidv4 } from "uuid";
  42. import {
  43. cartesian3ToWGS84,
  44. mapQuery,
  45. flatten,
  46. mercator2lonLat,
  47. undergroundMode,
  48. } from "@/utils/MapHelper/MapHelper.js";
  49. import {
  50. point,
  51. buffer,
  52. bboxPolygon,
  53. square,
  54. destination,
  55. polygon,
  56. booleanPointInPolygon,
  57. } from "@turf/turf";
  58. let polygonids = [];
  59. export default {
  60. data() {
  61. return {
  62. form: { FLOORH: 3, BuildingHeight: 0 },
  63. loutiInfo: null,
  64. };
  65. },
  66. props: {
  67. info: {
  68. type: Object,
  69. default: () => {
  70. return {};
  71. },
  72. },
  73. layerid: {
  74. type: String,
  75. default: "",
  76. },
  77. lydata: {
  78. type: Object,
  79. default: () => {
  80. return {};
  81. },
  82. },
  83. lyoption: {
  84. type: Object,
  85. default: () => {
  86. return {};
  87. },
  88. },
  89. },
  90. computed: {},
  91. mounted() {
  92. this.init();
  93. },
  94. methods: {
  95. async init() {
  96. debugger;
  97. let that = this;
  98. var pt = point([that.info.xyz.lng, that.info.xyz.lat]);
  99. this.info.layerDataList.forEach((element) => {
  100. let ps = [];
  101. element.geometry.points.forEach((points) => {
  102. ps.push([points.x, points.y]);
  103. });
  104. var poly = polygon([ps]);
  105. let isInclude = booleanPointInPolygon(pt, poly);
  106. if (isInclude) {
  107. debugger;
  108. that.loutiInfo = element;
  109. let FLOORH = element.data.find((c) => c.label == "FLOORH");
  110. if (FLOORH && FLOORH.value) {
  111. that.form.FLOORH = Number(FLOORH.value);
  112. }
  113. }
  114. });
  115. that.removeEntities();
  116. debugger;
  117. if (!that.loutiInfo) {
  118. that.$message({
  119. message: "未查询到模型数据,请重试加载模型",
  120. type: "warning",
  121. });
  122. return;
  123. }
  124. const element = that.loutiInfo;
  125. //基础高度(地形高度)加入地形后可删除
  126. let jcgd = 0;
  127. let bm = element.data.find((c) => c.label == "LANDNO");
  128. if (bm && bm.value) {
  129. //获取模型信息
  130. let queryBySQLParameters = {
  131. getFeatureMode: "SQL",
  132. datasetNames: [that.info.Minfo.datasourcename + ":项目范围"],
  133. queryParameter: {
  134. attributeFilter: " DKBM = '" + bm.value + "'",
  135. },
  136. hasGeometry: true,
  137. };
  138. let e = await mapQuery(
  139. that.info.Minfo.dataurl + "/featureResults.json?returnContent=true",
  140. queryBySQLParameters
  141. );
  142. debugger;
  143. if (e && e.totalCount > 0) {
  144. e.features.forEach((feature) => {
  145. feature.fieldNames.forEach((fieldName, i) => {
  146. if (
  147. fieldName == "BASEH" &&
  148. Number(feature.fieldValues[i]) >= jcgd
  149. ) {
  150. jcgd = Number(feature.fieldValues[i]);
  151. }
  152. });
  153. });
  154. }
  155. } else {
  156. that.$message({
  157. message: "未找到模型基础高度,默认高程为0",
  158. type: "warning",
  159. });
  160. }
  161. let HEIGHT = element.data.find((c) => c.label == "HEIGHT");
  162. if (HEIGHT && HEIGHT.value) {
  163. HEIGHT = HEIGHT.value;
  164. }
  165. that.form.BuildingHeight = HEIGHT;
  166. //顶部高度,底部高度
  167. let maxH = jcgd,
  168. minH = jcgd;
  169. for (
  170. let FLOORindex = 1;
  171. FLOORindex <= Math.ceil(that.form.BuildingHeight / that.form.FLOORH);
  172. FLOORindex++
  173. ) {
  174. debugger;
  175. maxH += that.form.FLOORH;
  176. minH = maxH - that.form.FLOORH;
  177. // console.log("maxH:" + maxH + "----minH:" + minH);
  178. let ps = [];
  179. for (let index = 0; index < element.geometry.points.length; index++) {
  180. const point = element.geometry.points[index];
  181. ps.push(point.x);
  182. ps.push(point.y);
  183. // ps.push(minH);
  184. }
  185. // let id = uuidv4();
  186. // 定义多边形的顶点(经纬度)
  187. var polygonHierarchy = new Cesium.PolygonHierarchy(
  188. Cesium.Cartesian3.fromDegreesArray(ps)
  189. );
  190. // 创建带有高度的多边形
  191. var extrudedPolygon = new Cesium.GeometryInstance({
  192. geometry: new Cesium.PolygonGeometry({
  193. polygonHierarchy: polygonHierarchy,
  194. height: minH, // 多边形底面的高度
  195. extrudedHeight: maxH, // 拉伸到的高度
  196. }),
  197. attributes: {
  198. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  199. Cesium.Color.CHARTREUSE.withAlpha(0.1)
  200. ),
  201. },
  202. });
  203. // 添加到场景中
  204. let Primitive = new Cesium.Primitive({
  205. geometryInstances: [extrudedPolygon],
  206. appearance: new Cesium.PerInstanceColorAppearance({
  207. flat: true,
  208. }),
  209. shadows: Cesium.ShadowMode.ENABLED, // 开启阴影
  210. });
  211. viewer.scene.primitives.add(Primitive);
  212. polygonids.push(Primitive);
  213. // 创建多边形的边界线
  214. let pss = [];
  215. for (let index = 0; index < element.geometry.points.length; index++) {
  216. const point = element.geometry.points[index];
  217. pss.push(point.x);
  218. pss.push(point.y);
  219. pss.push(maxH);
  220. }
  221. var boundaryPolyline = new Cesium.GeometryInstance({
  222. geometry: new Cesium.PolylineGeometry({
  223. positions: Cesium.Cartesian3.fromDegreesArrayHeights(pss), // 注意这里需要处理高度为0的情况,因为边界线通常在地表
  224. width: 1, // 边界线的宽度
  225. }),
  226. attributes: {
  227. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  228. Cesium.Color.CHARTREUSE.withAlpha(0.8)
  229. ),
  230. },
  231. });
  232. let boundaryPolylinePrimitive = new Cesium.Primitive({
  233. geometryInstances: [boundaryPolyline],
  234. appearance: new Cesium.PolylineColorAppearance({
  235. edgeWidth: 1,
  236. // vertexFormat: Cesium.PolylineVertexFormat.POSITION_AND_COLOR,
  237. vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
  238. }),
  239. });
  240. viewer.scene.primitives.add(boundaryPolylinePrimitive);
  241. polygonids.push(boundaryPolylinePrimitive);
  242. // viewer.entities.add({
  243. // id: id,
  244. // polygon: {
  245. // hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(ps),
  246. // extrudedHeight: Number(maxH),
  247. // perPositionHeight: true,
  248. // material: Cesium.Color.CHARTREUSE.withAlpha(0.1),
  249. // outline: true,
  250. // outlineColor: Cesium.Color.MEDIUMSPRINGGREEN,
  251. // outlineWidth: 1.0,
  252. // shadows: Cesium.ShadowMode.ENABLED,
  253. // },
  254. // });
  255. }
  256. },
  257. async onSubmit() {
  258. let that = this;
  259. that.removeEntities();
  260. if (!that.loutiInfo) {
  261. that.$message({
  262. message: "未查询到模型数据,请重试加载模型",
  263. type: "warning",
  264. });
  265. return;
  266. }
  267. const element = that.loutiInfo;
  268. //基础高度(地形高度)加入地形后可删除
  269. let jcgd = 0;
  270. //地块编码
  271. let bm = element.data.find((c) => c.label == "LANDNO");
  272. if (bm && bm.value) {
  273. //获取模型信息
  274. let queryBySQLParameters = {
  275. getFeatureMode: "SQL",
  276. datasetNames: [that.info.Minfo.datasourcename + ":项目范围"],
  277. queryParameter: {
  278. attributeFilter: " DKBM = '" + bm.value + "'",
  279. },
  280. hasGeometry: true,
  281. };
  282. let e = await mapQuery(
  283. that.info.Minfo.dataurl + "/featureResults.json?returnContent=true",
  284. queryBySQLParameters
  285. );
  286. debugger;
  287. if (e && e.totalCount > 0) {
  288. e.features.forEach((feature) => {
  289. feature.fieldNames.forEach((fieldName, i) => {
  290. if (
  291. fieldName == "BASEH" &&
  292. Number(feature.fieldValues[i]) > jcgd
  293. ) {
  294. jcgd = Number(feature.fieldValues[i]);
  295. }
  296. });
  297. });
  298. }
  299. } else {
  300. that.$message({
  301. message: "未找到模型基础高度,默认高程为0",
  302. type: "warning",
  303. });
  304. }
  305. //顶部高度,底部高度
  306. let maxH = jcgd,
  307. minH = jcgd;
  308. for (
  309. let FLOORindex = 1;
  310. FLOORindex <= Math.ceil(that.form.BuildingHeight / that.form.FLOORH);
  311. FLOORindex++
  312. ) {
  313. debugger;
  314. maxH += that.form.FLOORH;
  315. minH = maxH - that.form.FLOORH;
  316. // console.log("maxH:" + maxH + "----minH:" + minH);
  317. let ps = [];
  318. for (let index = 0; index < element.geometry.points.length; index++) {
  319. const point = element.geometry.points[index];
  320. ps.push(point.x);
  321. ps.push(point.y);
  322. // ps.push(minH);
  323. }
  324. // let id = uuidv4();
  325. // 定义多边形的顶点(经纬度)
  326. var polygonHierarchy = new Cesium.PolygonHierarchy(
  327. Cesium.Cartesian3.fromDegreesArray(ps)
  328. );
  329. // 创建带有高度的多边形
  330. var extrudedPolygon = new Cesium.GeometryInstance({
  331. geometry: new Cesium.PolygonGeometry({
  332. polygonHierarchy: polygonHierarchy,
  333. height: minH, // 多边形底面的高度
  334. extrudedHeight: maxH, // 拉伸到的高度
  335. }),
  336. attributes: {
  337. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  338. Cesium.Color.CHARTREUSE.withAlpha(0.1)
  339. ),
  340. },
  341. });
  342. // 添加到场景中
  343. let Primitive = new Cesium.Primitive({
  344. geometryInstances: [extrudedPolygon],
  345. appearance: new Cesium.PerInstanceColorAppearance({
  346. flat: true,
  347. }),
  348. shadows: Cesium.ShadowMode.ENABLED, // 开启阴影
  349. });
  350. viewer.scene.primitives.add(Primitive);
  351. polygonids.push(Primitive);
  352. // 创建多边形的边界线
  353. let pss = [];
  354. for (let index = 0; index < element.geometry.points.length; index++) {
  355. const point = element.geometry.points[index];
  356. pss.push(point.x);
  357. pss.push(point.y);
  358. pss.push(maxH);
  359. }
  360. var boundaryPolyline = new Cesium.GeometryInstance({
  361. geometry: new Cesium.PolylineGeometry({
  362. positions: Cesium.Cartesian3.fromDegreesArrayHeights(pss), // 注意这里需要处理高度为0的情况,因为边界线通常在地表
  363. width: 1, // 边界线的宽度
  364. }),
  365. attributes: {
  366. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  367. Cesium.Color.CHARTREUSE.withAlpha(0.8)
  368. ),
  369. },
  370. });
  371. let boundaryPolylinePrimitive = new Cesium.Primitive({
  372. geometryInstances: [boundaryPolyline],
  373. appearance: new Cesium.PolylineColorAppearance({
  374. edgeWidth: 1,
  375. // vertexFormat: Cesium.PolylineVertexFormat.POSITION_AND_COLOR,
  376. vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
  377. }),
  378. });
  379. viewer.scene.primitives.add(boundaryPolylinePrimitive);
  380. polygonids.push(boundaryPolylinePrimitive);
  381. // viewer.entities.add({
  382. // id: id,
  383. // polygon: {
  384. // hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(ps),
  385. // extrudedHeight: Number(maxH),
  386. // perPositionHeight: true,
  387. // material: Cesium.Color.CHARTREUSE.withAlpha(0.1),
  388. // outline: true,
  389. // outlineColor: Cesium.Color.MEDIUMSPRINGGREEN,
  390. // outlineWidth: 1.0,
  391. // shadows: Cesium.ShadowMode.ENABLED,
  392. // },
  393. // });
  394. }
  395. },
  396. removeEntities() {
  397. for (let index = 0; index < polygonids.length; index++) {
  398. const element = polygonids[index];
  399. viewer.scene.primitives.remove(element);
  400. // viewer.entities.removeById(element);
  401. }
  402. polygonids = [];
  403. },
  404. },
  405. beforeDestroy() {
  406. this.removeEntities();
  407. },
  408. };
  409. </script>
  410. <style lang="scss">
  411. @import "@/../../zt.scss";
  412. </style>
  413. <style lang="scss" scoped>
  414. .el-card {
  415. border: 0px solid #02a7f0;
  416. }
  417. .el-form-item {
  418. margin-bottom: 0;
  419. }
  420. .grid-content {
  421. display: flex;
  422. justify-content: center;
  423. align-items: center;
  424. }
  425. </style>