index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div
  3. class="sm-panel sm-function-module-content ghzc modelStretch"
  4. v-if="modelStretchShow"
  5. v-drag
  6. >
  7. <div class="sm-panel-header">
  8. <span>模型拉伸</span>
  9. <span class="closeBtn" @click="toggleVisibility">&times;</span>
  10. </div>
  11. <div class="xz_box">
  12. <el-form :model="form" ref="form" label-width="80px" :rules="rules">
  13. <el-form-item label="平面范围:" prop="xzmj">
  14. <range type="hgxfx" :keys="['hx', 'sc']" class="range" ref="range" />
  15. </el-form-item>
  16. <el-row :gutter="10">
  17. <el-col :span="14" style="text-align: center">
  18. <!-- 楼体高度:
  19. <el-input-number
  20. size="mini"
  21. step="1"
  22. v-model="form.BuildingHeight"
  23. @change="XYChange"
  24. ></el-input-number> -->
  25. <el-form-item label="模型高度:" prop="BuildingHeight">
  26. <el-input
  27. class="inputwidth"
  28. v-model.number="form.BuildingHeight"
  29. size="mini"
  30. type="number"
  31. ></el-input>
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="10" style="text-align: center">
  35. <el-form-item label="层高:" prop="FLOORH" label-width="45px">
  36. <el-input
  37. class="inputwidth"
  38. v-model.number="form.FLOORH"
  39. size="mini"
  40. type="number"
  41. ></el-input>
  42. </el-form-item>
  43. <!-- 层高:
  44. <el-input-number
  45. size="mini"
  46. step="0.1"
  47. v-model="form.FLOORH"
  48. @change="XYChange"
  49. ></el-input-number> -->
  50. </el-col>
  51. </el-row>
  52. <el-form-item label="模型名称:" prop="mxmc">
  53. <el-input
  54. v-model="form.mxmc"
  55. size="mini"
  56. placeholder="请输入模型名称"
  57. ></el-input>
  58. </el-form-item>
  59. <!-- <div class="SaveCenter">
  60. <el-button size="mini" type="primary" @click="onSubmit"
  61. >开始调整</el-button
  62. >
  63. <el-button size="mini" @click="removeEntities">清除</el-button>
  64. </div> -->
  65. </el-form>
  66. <div class="Btns">
  67. <el-button size="mini" @click="clear">清 除</el-button>
  68. <el-button type="primary" size="mini" @click="submit">确 定</el-button>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import range from "@/components/mapview/range.vue"; ///mapview/range
  75. import {} from "@/api/map";
  76. import parse from "wellknown";
  77. let polygonids = [];
  78. let dataSources = {};
  79. export default {
  80. name: "modelStretch",
  81. components: {
  82. range,
  83. },
  84. data() {
  85. return { form: { BuildingHeight: 50, FLOORH: 5 } };
  86. },
  87. created() {},
  88. mounted() {},
  89. computed: {
  90. modelStretchShow() {
  91. return store.state.toolBar[13];
  92. },
  93. },
  94. methods: {
  95. toggleVisibility() {
  96. store.setToolBarAction(13);
  97. this.clear();
  98. },
  99. pullUp(item, height) {
  100. let upid = "up" + item.id;
  101. if (!dataSources[upid])
  102. this.loadGeoJSON(parse(item.geom), "#000000", upid, height, item.dkbm);
  103. else {
  104. let entities = dataSources[upid].entities.values;
  105. entities.forEach((entity, ei) => {
  106. if (height && entity.polygon) {
  107. entity.polygon.extrudedHeight = height;
  108. let center = this.getCentroid(parse(item.geom), ei);
  109. entity.position = Cesium.Cartesian3.fromDegrees(
  110. center[0],
  111. center[1],
  112. height
  113. );
  114. }
  115. });
  116. viewer.flyTo(dataSources[upid], {
  117. offset: new Cesium.HeadingPitchRange(0, -0.8),
  118. });
  119. }
  120. },
  121. pullClear(item) {
  122. let upid = "up" + item.id;
  123. if (dataSources[upid]) {
  124. viewer.dataSources.remove(dataSources[upid]);
  125. dataSources[upid] = null;
  126. }
  127. },
  128. // 加载GeoJSON数据
  129. loadGeoJSON(geojson, yanse, id, height, name) {
  130. let _this = this;
  131. let fcolor =
  132. id && id != "all"
  133. ? Cesium.Color.fromCssColorString(yanse)
  134. : Cesium.Color.WHITE;
  135. const dataSource = new Cesium.GeoJsonDataSource();
  136. dataSource
  137. .load(geojson, {
  138. clampToGround: true,
  139. stroke: Cesium.Color.fromCssColorString(yanse),
  140. fill: fcolor.withAlpha(0.4), //注意:颜色必须大写,即不能为blue
  141. strokeWidth: 5,
  142. // markerSymbol: "", //点图钉的默认符号
  143. })
  144. .then((data) => {
  145. viewer.dataSources.add(data);
  146. let entities = data.entities.values;
  147. // let addlabel = false;
  148. if (!geojson.type.includes("Polygon") || height) {
  149. entities.forEach((entity, ei) => {
  150. if (entity.billboard) {
  151. entity.billboard = undefined;
  152. entity.point = {
  153. pixelsize: 20,
  154. color: Cesium.Color.fromCssColorString(yanse),
  155. };
  156. }
  157. if (height && entity.polygon) {
  158. entity.polygon.extrudedHeight = height;
  159. entity.polygon.material =
  160. Cesium.Color.fromCssColorString("#cdcdcd");
  161. entity.polygon.outlineColor = Cesium.Color.BLACK;
  162. entity.polygon.outlineWidth = 1.0;
  163. // if (!addlabel) {
  164. let center = this.getCentroid(geojson, ei);
  165. var polycenter = Cesium.Cartesian3.fromDegrees(
  166. center[0],
  167. center[1],
  168. height
  169. );
  170. entity.position = polycenter;
  171. entity.label = {
  172. font: "bolder 18px sans-serif",
  173. style: Cesium.LabelStyle.FILL_AND_OUTLINE,
  174. text: name, //图标名称
  175. fillColor: Cesium.Color.fromCssColorString("#fff000"),
  176. pixelOffset: new Cesium.Cartesian2(0, -20),
  177. zIndex: 3,
  178. };
  179. // addlabel = true;
  180. // }
  181. }
  182. });
  183. }
  184. var pitch = height ? -0.8 : -45; // Cesium.Math.toRadians(-45.0);-0.7853981633974483
  185. let range = height ? 3000 : 5000;
  186. viewer.flyTo(data, {
  187. offset: new Cesium.HeadingPitchRange(0, pitch),
  188. });
  189. // viewer.zoomTo(data);
  190. if (id) {
  191. dataSources[id] = data;
  192. }
  193. if (id == "all") _this.isshowAll = true;
  194. });
  195. },
  196. clear() {
  197. this.$refs.range.reset();
  198. // this.pullClear();
  199. this.removeEntities();
  200. },
  201. submit() {
  202. var _temp = this.$refs.range.getRange();
  203. _temp.geojson = parse(_temp.geom);
  204. // this.pullUp(_temp, this.form.BuildingHeight);
  205. this.onSubmit(_temp.geojson);
  206. },
  207. onSubmit(geojson) {
  208. let that = this;
  209. that.removeEntities();
  210. // if (!that.loutiInfo) {
  211. // that.$message({
  212. // message: "未查询到模型数据,请重试加载模型",
  213. // type: "warning",
  214. // });
  215. // return;
  216. // }
  217. // const element = that.loutiInfo;
  218. // //基础高度(地形高度)加入地形后可删除
  219. let jcgd = 0;
  220. // //地块编码
  221. // let bm = element.data.find((c) => c.label == "LANDNO");
  222. // if (bm && bm.value) {
  223. // //获取模型信息
  224. // let queryBySQLParameters = {
  225. // getFeatureMode: "SQL",
  226. // datasetNames: [that.info.Minfo.datasourcename + ":项目范围"],
  227. // queryParameter: {
  228. // attributeFilter: " DKBM = '" + bm.value + "'",
  229. // },
  230. // hasGeometry: true,
  231. // };
  232. // let e = await mapQuery(
  233. // that.info.Minfo.dataurl + "/featureResults.json?returnContent=true",
  234. // queryBySQLParameters
  235. // );
  236. // debugger;
  237. // if (e && e.totalCount > 0) {
  238. // e.features.forEach((feature) => {
  239. // feature.fieldNames.forEach((fieldName, i) => {
  240. // if (
  241. // fieldName == "BASEH" &&
  242. // Number(feature.fieldValues[i]) > jcgd
  243. // ) {
  244. // jcgd = Number(feature.fieldValues[i]);
  245. // }
  246. // });
  247. // });
  248. // }
  249. // } else {
  250. // that.$message({
  251. // message: "未找到模型基础高度,默认高程为0",
  252. // type: "warning",
  253. // });
  254. // }
  255. //顶部高度,底部高度
  256. let maxH = jcgd,
  257. minH = jcgd;
  258. for (
  259. let FLOORindex = 1;
  260. FLOORindex <= Math.ceil(that.form.BuildingHeight / that.form.FLOORH);
  261. FLOORindex++
  262. ) {
  263. // debugger;
  264. maxH += that.form.FLOORH;
  265. minH = maxH - that.form.FLOORH;
  266. console.log("maxH:" + maxH + "----minH:" + minH);
  267. let ps = [];
  268. // for (let index = 0; index < element.geometry.points.length; index++) {
  269. // const point = element.geometry.points[index];
  270. // ps.push(point.x);
  271. // ps.push(point.y);
  272. // // ps.push(minH);
  273. // }
  274. geojson.coordinates[0].forEach((gom) => {
  275. ps.push(gom[0]);
  276. ps.push(gom[1]);
  277. });
  278. // let id = uuidv4();
  279. // 定义多边形的顶点(经纬度)
  280. var polygonHierarchy = new Cesium.PolygonHierarchy(
  281. Cesium.Cartesian3.fromDegreesArray(ps)
  282. );
  283. // 创建带有高度的多边形
  284. var extrudedPolygon = new Cesium.GeometryInstance({
  285. geometry: new Cesium.PolygonGeometry({
  286. polygonHierarchy: polygonHierarchy,
  287. height: minH, // 多边形底面的高度
  288. extrudedHeight: maxH, // 拉伸到的高度
  289. }),
  290. attributes: {
  291. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  292. Cesium.Color.CHARTREUSE.withAlpha(0.1)
  293. ),
  294. },
  295. });
  296. // 添加到场景中
  297. let Primitive = new Cesium.Primitive({
  298. geometryInstances: [extrudedPolygon],
  299. appearance: new Cesium.PerInstanceColorAppearance({
  300. flat: true,
  301. }),
  302. shadows: Cesium.ShadowMode.ENABLED, // 开启阴影
  303. });
  304. viewer.scene.primitives.add(Primitive);
  305. polygonids.push(Primitive);
  306. // 创建多边形的边界线
  307. let pss = [];
  308. // for (let index = 0; index < element.geometry.points.length; index++) {
  309. // const point = element.geometry.points[index];
  310. // pss.push(point.x);
  311. // pss.push(point.y);
  312. // pss.push(maxH);
  313. // }
  314. geojson.coordinates[0].forEach((gom) => {
  315. pss.push(gom[0]);
  316. pss.push(gom[1]);
  317. pss.push(maxH);
  318. });
  319. var boundaryPolyline = new Cesium.GeometryInstance({
  320. geometry: new Cesium.PolylineGeometry({
  321. positions: Cesium.Cartesian3.fromDegreesArrayHeights(pss), // 注意这里需要处理高度为0的情况,因为边界线通常在地表
  322. width: 1, // 边界线的宽度
  323. }),
  324. attributes: {
  325. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  326. Cesium.Color.CHARTREUSE.withAlpha(0.8)
  327. ),
  328. },
  329. });
  330. let boundaryPolylinePrimitive = new Cesium.Primitive({
  331. geometryInstances: [boundaryPolyline],
  332. appearance: new Cesium.PolylineColorAppearance({
  333. edgeWidth: 1,
  334. // vertexFormat: Cesium.PolylineVertexFormat.POSITION_AND_COLOR,
  335. vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
  336. }),
  337. });
  338. viewer.scene.primitives.add(boundaryPolylinePrimitive);
  339. polygonids.push(boundaryPolylinePrimitive);
  340. // viewer.entities.add({
  341. // id: id,
  342. // polygon: {
  343. // hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(ps),
  344. // extrudedHeight: Number(maxH),
  345. // perPositionHeight: true,
  346. // material: Cesium.Color.CHARTREUSE.withAlpha(0.1),
  347. // outline: true,
  348. // outlineColor: Cesium.Color.MEDIUMSPRINGGREEN,
  349. // outlineWidth: 1.0,
  350. // shadows: Cesium.ShadowMode.ENABLED,
  351. // },
  352. // });
  353. }
  354. },
  355. removeEntities() {
  356. for (let index = 0; index < polygonids.length; index++) {
  357. const element = polygonids[index];
  358. viewer.scene.primitives.remove(element);
  359. // viewer.entities.removeById(element);
  360. }
  361. polygonids = [];
  362. },
  363. },
  364. watch: { modelStretchShow(newVal) {} },
  365. };
  366. </script>
  367. <style scoped lang="scss">
  368. .sm-panel {
  369. max-width: 500px;
  370. }
  371. .modelStretch {
  372. width: 400px;
  373. height: 600px;
  374. .range {
  375. // flex: 1;
  376. text-align: left;
  377. width: 80%;
  378. }
  379. .xz_box {
  380. padding: 0;
  381. }
  382. .inputwidth {
  383. width: calc(100% - 20px);
  384. }
  385. .Btns {
  386. width: 100%;
  387. // display: -webkit-box;
  388. // display: -ms-flexbox;
  389. display: flex;
  390. padding: 20px 30px;
  391. // -webkit-box-pack: justify;
  392. // -ms-flex-pack: justify;
  393. justify-content: space-between;
  394. // text-align: center;
  395. // position: absolute;
  396. // bottom: 0px;
  397. }
  398. }
  399. </style>
  400. <style lang="scss">
  401. @import "../complianceAnalysis//ghzc.scss";
  402. </style>