addBiillboardModel.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <div class="ZTGlobal" style="height: 100%; padding: 10px; color: white">
  3. <el-row>
  4. <span>模型名称:</span
  5. ><el-input
  6. size="mini"
  7. type="text"
  8. placeholder="请输入模型名称"
  9. v-model="billboardModel.billboardName"
  10. ></el-input>
  11. </el-row>
  12. <el-row>
  13. <el-col :span="9"> <span>广告类型:</span></el-col>
  14. <el-col :span="15">
  15. <el-cascader
  16. size="mini"
  17. placeholder="请选择广告类型"
  18. v-model="billboardModel.billboardType"
  19. :options="options"
  20. :show-all-levels="false"
  21. :props="{
  22. value: 'billboardType',
  23. label: 'billboardType',
  24. children: 'children',
  25. emitPath: false,
  26. }"
  27. ></el-cascader>
  28. <!-- <el-select
  29. placeholder="请选择广告类型"
  30. v-model="billboardModel.billboardType"
  31. >
  32. <el-option
  33. v-for="item in options"
  34. :key="item.value"
  35. :value="item.value"
  36. :label="item.label"
  37. >{{ item.label }}</el-option
  38. >
  39. </el-select> -->
  40. </el-col>
  41. </el-row>
  42. <el-row>
  43. <el-col :span="9"><span>X坐标(度) </span></el-col>
  44. <el-col :span="15">
  45. <el-input-number
  46. name="x"
  47. v-model="billboardModel.x"
  48. size="mini"
  49. precision="6"
  50. :min="108.6"
  51. :max="110.5"
  52. @change="handleChange"
  53. step="0.000001"
  54. label="X坐标(度)"
  55. ></el-input-number
  56. ></el-col>
  57. </el-row>
  58. <el-row>
  59. <el-col :span="9"><span>Y坐标(度):</span></el-col>
  60. <el-col :span="15">
  61. <el-input-number
  62. name="y"
  63. v-model="billboardModel.y"
  64. size="mini"
  65. precision="6"
  66. :min="18.16"
  67. :max="18.7"
  68. @change="handleChange"
  69. step="0.000001"
  70. label="Y坐标(度)"
  71. ></el-input-number>
  72. </el-col>
  73. </el-row>
  74. <el-row>
  75. <el-col :span="9"> <span>Z坐标(米):</span></el-col>
  76. <el-col :span="15">
  77. <el-input-number
  78. name="z"
  79. v-model="billboardModel.z"
  80. size="mini"
  81. precision="2"
  82. :min="0"
  83. :max="100"
  84. step="0.1"
  85. @change="handleChange"
  86. label="Z坐标(米)"
  87. ></el-input-number>
  88. </el-col>
  89. </el-row>
  90. <el-row>
  91. <el-col :span="9"> <span>长(米):</span></el-col>
  92. <el-col :span="15">
  93. <el-input-number
  94. name="xL"
  95. v-model="billboardModel.xL"
  96. size="mini"
  97. precision="2"
  98. :min="0"
  99. :max="100"
  100. step="0.01"
  101. @change="handleChange"
  102. label="长(米)"
  103. ></el-input-number>
  104. </el-col>
  105. </el-row>
  106. <el-row>
  107. <el-col :span="9"> <span>宽/高(米):</span></el-col>
  108. <el-col :span="15">
  109. <el-input-number
  110. name="yL"
  111. v-model="billboardModel.yL"
  112. size="mini"
  113. precision="2"
  114. :min="0"
  115. :max="50"
  116. step="0.01"
  117. @change="handleChange"
  118. label=""
  119. >宽/高(米)</el-input-number
  120. >
  121. </el-col>
  122. </el-row>
  123. <el-row>
  124. <el-col :span="9"><span>厚度(米):</span></el-col>
  125. <el-col :span="15">
  126. <el-input-number
  127. name="zL"
  128. v-model="billboardModel.zL"
  129. size="mini"
  130. precision="2"
  131. :min="0"
  132. :max="100"
  133. step="0.01"
  134. @change="handleChange"
  135. label="厚度(米)"
  136. ></el-input-number>
  137. </el-col>
  138. </el-row>
  139. <el-row>
  140. <el-col :span="9"><span>X轴旋转角(度):</span></el-col>
  141. <el-col :span="15">
  142. <el-input-number
  143. name="rotateX"
  144. v-model="billboardModel.rotateX"
  145. size="mini"
  146. precision="1"
  147. :min="0"
  148. :max="360"
  149. step="0.1"
  150. @change="handleChange"
  151. label="X轴旋转角(度)"
  152. ></el-input-number
  153. ></el-col>
  154. </el-row>
  155. <el-row>
  156. <el-col :span="9"><span>Y轴旋转角(度):</span></el-col>
  157. <el-col :span="15">
  158. <el-input-number
  159. name="rotateY"
  160. v-model="billboardModel.rotateY"
  161. size="mini"
  162. precision="1"
  163. :min="0"
  164. :max="360"
  165. step="0.1"
  166. @change="handleChange"
  167. label="Y轴旋转角(度)"
  168. ></el-input-number
  169. ></el-col>
  170. </el-row>
  171. <el-row>
  172. <el-col :span="9"><span>Z轴旋转角(度):</span></el-col>
  173. <el-col :span="15">
  174. <el-input-number
  175. name="rotateZ"
  176. v-model="billboardModel.rotateZ"
  177. size="mini"
  178. precision="1"
  179. :min="0"
  180. :max="360"
  181. step="0.1"
  182. @change="handleChange"
  183. label="Z轴旋转角(度)"
  184. ></el-input-number
  185. ></el-col>
  186. </el-row>
  187. <el-row>
  188. <el-col :span="9"><span>是否添加模型:</span></el-col>
  189. <el-col :span="8">
  190. <el-switch
  191. size="mini"
  192. v-model="billboardModel.isAddModel"
  193. active-text="是"
  194. inactive-text="否"
  195. >
  196. </el-switch>
  197. </el-col>
  198. <el-col :span="6">
  199. <el-button
  200. size="mini"
  201. v-show="billboardModel.isAddModel"
  202. type="primary"
  203. @click="addModel()"
  204. >添加广告牌</el-button
  205. >
  206. </el-col>
  207. </el-row>
  208. <el-row>
  209. <div style="display: inline-flex">
  210. <el-button size="mini" type="primary" @click="saveMode()"
  211. >保存</el-button
  212. >
  213. <el-button size="mini" @click="cancle()">取消</el-button>
  214. </div>
  215. </el-row>
  216. </div>
  217. </template>
  218. <script>
  219. import { Image } from "element-ui";
  220. import { watch } from "vue";
  221. import { v4 as uuidv4 } from "uuid";
  222. /**
  223. * 添加的模型集合
  224. */
  225. let modelList = [];
  226. export default {
  227. props: {
  228. layerid: {
  229. type: String,
  230. default: "",
  231. },
  232. projectId: {
  233. type: String,
  234. default: "",
  235. },
  236. info: {
  237. type: Object,
  238. default: () => {
  239. return {};
  240. },
  241. },
  242. lydata: {
  243. type: Object,
  244. default: () => {
  245. return {};
  246. },
  247. },
  248. lyoption: {
  249. type: Object,
  250. default: () => {
  251. return {};
  252. },
  253. },
  254. },
  255. data() {
  256. return {
  257. billboardModel: {
  258. id: "",
  259. billboardInfoId: "",
  260. billboardName: "",
  261. billboardType: "",
  262. x: 109.56047,
  263. y: 18.36254,
  264. z: 3,
  265. xL: 1,
  266. yL: 1,
  267. zL: 0.1, //厚度
  268. rotateX: 90,
  269. rotateY: 0,
  270. rotateZ: 0,
  271. ReviewStatus: "",
  272. ReviewComments: "",
  273. isAddModel: false,
  274. },
  275. options: window.billboardReviewList,
  276. /**
  277. * 编辑句柄
  278. */
  279. handlerPoint: null,
  280. /**
  281. * 当前编辑模型
  282. */
  283. currentEntity: null,
  284. point3D: null,
  285. GUID: "",
  286. };
  287. },
  288. watch: {
  289. // point3D() {
  290. // this.billboardModel.x = parseFloat(this.point3D.longitude).toFixed(5);
  291. // this.billboardModel.y = parseFloat(this.point3D.latitude).toFixed(5);
  292. // this.billboardModel.z = parseFloat(this.point3D.height).toFixed(2);
  293. // this.billboardModel.xL = parseFloat(this.point3D.height).toFixed(2);
  294. // }
  295. // "billboardModel"(value) {
  296. // console.log(343)
  297. // this.currentEntity.box.dimensions = new Cesium.Cartesian3(
  298. // value.xL,
  299. // value.yL,
  300. // value.zL
  301. // );
  302. // this.currentEntity.orientation = Cesium.Transforms.headingPitchRollQuaternion(this.currentEntity.position,
  303. // new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(value.rotateX),
  304. // Cesium.Math.toRadians(0), Cesium.Math.toRadians(0)));
  305. // }
  306. },
  307. methods: {
  308. /**
  309. * 点击添加位置
  310. */
  311. addModel() {
  312. var that = this;
  313. if (modelList.length > 0) {
  314. for (let index = 0; index < modelList.length; index++) {
  315. const element = modelList[index];
  316. viewer.entities.removeById(element.id);
  317. }
  318. modelList = [];
  319. }
  320. viewer._container.style.cursor = "pointer";
  321. that.GUID = new Date().getTime().toString();
  322. that.handlerPoint = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
  323. //todo:在显示地形情况下点击创建点
  324. var imageurl = "../../../../static/images/cesiumStyleImages/1.jpg";
  325. var modelurl = "../../../../static/ModelData/billboard/box.gltf";
  326. that.handlerPoint.setInputAction(function (event) {
  327. // // 使用场景的pick方法获取点击位置的实体
  328. // var pickedObject = viewer.scene.pick(event.position);
  329. // // 检查是否点击到了实体
  330. // if (
  331. // scene.pickPositionSupported &&
  332. // Cesium.defined(pickedObject) &&
  333. // pickedObject.primitive
  334. // ) {
  335. // debugger;
  336. // }
  337. var newposition = viewer.scene.pickPosition(event.position); //获取到地形图上面的坐标
  338. var orientation = Cesium.Transforms.headingPitchRollQuaternion(
  339. newposition,
  340. new Cesium.HeadingPitchRoll(
  341. Cesium.Math.toRadians(that.billboardModel.rotateX),
  342. Cesium.Math.toRadians(0),
  343. Cesium.Math.toRadians(0)
  344. )
  345. );
  346. var coordinate = Cesium.Cartographic.fromCartesian(newposition);
  347. var longitude = Cesium.Math.toDegrees(coordinate.longitude);
  348. var latitude = Cesium.Math.toDegrees(coordinate.latitude);
  349. var height = coordinate.height;
  350. that.billboardModel.x = longitude;
  351. that.billboardModel.y = latitude;
  352. that.billboardModel.z = height;
  353. // var newPosition = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
  354. var entity = viewer.entities.add({
  355. id: "billboard_" + that.GUID,
  356. name: "gltf",
  357. show: true,
  358. position: newposition,
  359. /**
  360. * 长方体
  361. */
  362. box: {
  363. dimensions: new Cesium.Cartesian3(
  364. that.billboardModel.xL,
  365. that.billboardModel.zL,
  366. that.billboardModel.yL
  367. ),
  368. show: true,
  369. material: Cesium.Color.LIGHTGREEN,
  370. // outline: false,
  371. // outlineColor: Cesium.Color.SPRINGGREEN,
  372. // outlineWidth: 1,
  373. },
  374. /**
  375. * 模型
  376. */
  377. // model: {
  378. // uri: modelurl,
  379. // scale: that.billboardModel.xL,
  380. // },
  381. /**
  382. * 广告牌
  383. */
  384. // billboard: {
  385. // image: imageurl,
  386. // width: that.billboardModel.xL,
  387. // height: that.billboardModel.zL,
  388. // rotation: 0,
  389. // },
  390. orientation: orientation,
  391. });
  392. debugger;
  393. modelList.push(entity);
  394. if (that.handlerPoint)
  395. that.handlerPoint.removeInputAction(
  396. Cesium.ScreenSpaceEventType.LEFT_CLICK
  397. );
  398. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  399. // var colorStr = color.toCssColorString();
  400. // viewModel.boxMaterial = colorStr;
  401. },
  402. /**
  403. * 动态调整模型
  404. */
  405. handleChange() {
  406. var that = this;
  407. var currentEntity = viewer.entities.getById("billboard_" + that.GUID);
  408. /**
  409. * box
  410. */
  411. currentEntity.box.dimensions = new Cesium.Cartesian3(
  412. that.billboardModel.xL,
  413. that.billboardModel.zL,
  414. that.billboardModel.yL
  415. );
  416. /**
  417. * model
  418. */
  419. // currentEntity.model.scale = that.billboardModel.xL;
  420. /**
  421. * billoard
  422. */
  423. // debugger
  424. // that.currentEntity.billboard.width = that.billboardModel.x;
  425. // that.currentEntity.billboard.height = that.billboardModel.y;
  426. // that.currentEntity.billboard.rotation =that.billboardModel.rotateX
  427. /**
  428. * 更新位置
  429. */
  430. var newposition = Cesium.Cartesian3.fromDegrees(
  431. parseFloat(that.billboardModel.x),
  432. parseFloat(that.billboardModel.y),
  433. parseFloat(that.billboardModel.z)
  434. );
  435. currentEntity.position = newposition;
  436. /**
  437. * 旋转
  438. */
  439. var heading = Cesium.Math.toRadians(that.billboardModel.rotateX);
  440. var pitch = Cesium.Math.toRadians(that.billboardModel.rotateY);
  441. var roll = Cesium.Math.toRadians(that.billboardModel.rotateZ);
  442. var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  443. var neworientation = Cesium.Transforms.headingPitchRollQuaternion(
  444. newposition,
  445. hpr
  446. );
  447. currentEntity.orientation = neworientation;
  448. },
  449. /**
  450. *实时更新位置
  451. */
  452. getPostions() {
  453. console.log("更新位置");
  454. var position = Cesium.Cartesian3.fromDegrees(
  455. parseFloat(this.billboardModel.x),
  456. parseFloat(this.billboardModel.y),
  457. parseFloat(this.billboardModel.z)
  458. );
  459. var property = new Cesium.SampledPositionProperty();
  460. // let time = Cesium.JulianDate.addSeconds(start, source[i].time, new Cesium.JulianDate);
  461. var time = Cesium.JulianDate.now();
  462. // 添加位置,和时间对应
  463. property.addSample(time, position);
  464. return property;
  465. },
  466. /**
  467. * 实时更新角度
  468. */
  469. getOrientation() {
  470. var that = this;
  471. // var rotate = Cesium.Math.toRadians(that.billboardModel.rotateX);
  472. // var hpr = new Cesium.HeadingPitchRoll(rotate, 0, 0);
  473. var position = Cesium.Cartesian3.fromDegrees(
  474. parseFloat(that.billboardModel.x),
  475. parseFloat(that.billboardModel.y),
  476. parseFloat(that.billboardModel.z)
  477. );
  478. // var neworientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
  479. // console.log("更新角度")
  480. // return neworientation;
  481. // 取样位置 相当于一个集合
  482. let property = new Cesium.SampledPositionProperty();
  483. // let time = Cesium.JulianDate.addSeconds(start, source[i].time, new Cesium.JulianDate);
  484. var time = Cesium.JulianDate.now();
  485. // 添加位置,和时间对应
  486. property.addSample(time, position);
  487. return property;
  488. },
  489. /**
  490. * 保存编辑
  491. */
  492. saveMode() {
  493. debugger;
  494. let that = this;
  495. if (
  496. that.billboardModel.billboardName == "" ||
  497. that.billboardModel.billboardName == null
  498. ) {
  499. this.$message.error("请添加模型名称");
  500. return;
  501. }
  502. if (that.billboardModel.isAddModel && modelList.length == 0) {
  503. this.$message.error("请先完成[添加广告牌],再保存");
  504. return;
  505. }
  506. that.billboardModel.id = uuidv4();
  507. that.billboardModel.billboardInfoId = that.projectId;
  508. window.billboardModelList.push(that.billboardModel);
  509. this.$message({
  510. message: "添加成功",
  511. type: "success",
  512. });
  513. viewer.entities.removeAll();
  514. // that.lyoption.cancel();
  515. that.$layer.close(that.layerid);
  516. },
  517. //取消
  518. cancle() {
  519. if (this.handlerPoint)
  520. this.handlerPoint.removeInputAction(
  521. Cesium.ScreenSpaceEventType.LEFT_CLICK
  522. );
  523. modelList = [];
  524. viewer.entities.removeAll();
  525. this.$layer.close(this.layerid);
  526. },
  527. },
  528. components: { Image },
  529. };
  530. </script>
  531. <style lang="scss">
  532. @import "@/../../zt.scss";
  533. </style>