addDataSet.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <link rel="stylesheet" href="./ol.css" type="text/css">
  5. <link rel="stylesheet" href="./style.css" type="text/css">
  6. <script src="./ol.js"></script>
  7. <style>
  8. [v-cloak] {
  9. display: none;
  10. }
  11. #editor {
  12. height: 200px;
  13. }
  14. </style>
  15. <!-- <script src="./ol.js"></script> -->
  16. <title>定位</title>
  17. </head>
  18. <body>
  19. <div id="app" v-cloak>
  20. <div class="content">
  21. <!-- <div class="rightBox">
  22. <div class="map-layer">
  23. <div id="map" class="map"></div>
  24. <image-tranform :map-ol="map" v-if="map && showImageTranform" v-show="showImageTranform1" ref="imageTranform" />
  25. </div>
  26. </div> -->
  27. <div id="plane">
  28. <div class="main" v-if="!isEdit">
  29. <!-- <div class="title">定位</div> -->
  30. <p class="desc">通过两个控制点坐标确定点云在地图上的位置</p>
  31. <div class="editBtn" @click="openEdit">修改控制点</div>
  32. <div class="main_item">
  33. <p class="main_item_title">控制点1</p>
  34. <div class="dataBox">
  35. <p>本地坐标</p>
  36. <div>
  37. <span>X:{{showData.ax}}</span><br/>
  38. <span>Y:{{showData.ay}}</span><br/>
  39. <span>Z:{{showData.az}}</span><br/>
  40. </div>
  41. <p>地理坐标</p>
  42. <div>
  43. <span>经度:{{showData.alon}}</span><br/>
  44. <span>纬度:{{showData.alat}}</span><br/>
  45. <span>高程:{{showData.aalt}}</span><br/>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="main_item">
  50. <p class="main_item_title">控制点2</p>
  51. <div class="dataBox">
  52. <p>本地坐标</p>
  53. <div>
  54. <span>X:{{showData.bx}}</span><br/>
  55. <span>Y:{{showData.by}}</span><br/>
  56. <span>Z:{{showData.bz}}</span><br/>
  57. </div>
  58. <p>地理坐标</p>
  59. <div>
  60. <span>经度:{{showData.blon}}</span><br/>
  61. <span>纬度:{{showData.blat}}</span><br/>
  62. <span>高程:{{showData.balt}}</span><br/>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- <div class="main_item">
  67. <div class="Setting">
  68. <div class="msgBox">
  69. <p class="title">
  70. 地理坐标</p>
  71. <p class="desc">确定点云在世界地图上的位置</p>
  72. </div>
  73. <div class="btnton" @click="isEdit = true">
  74. 修改
  75. </div>
  76. </div>
  77. </div> -->
  78. <!-- <div class="main_item" v-if="false">
  79. <div class="Setting">
  80. <div class="msgBox">
  81. <p class="title">
  82. 平面图</p>
  83. <p class="desc">添加建筑物平面图,方便预览</p>
  84. </div>
  85. <div class="btnton" @click="readyUpload">
  86. 上传
  87. </div>
  88. </div>
  89. <div class="mapList">
  90. <div class="mapItem">
  91. <div class="fileName">
  92. 思维展厅.PNG
  93. </div>
  94. <div class="fileBtn">
  95. <div class="fileBtnicon fileHide" @click="showImageTranform1 = !showImageTranform1"></div>
  96. <div class="fileBtnicon fileSave" @click="getImageTransform"></div>
  97. <div class="fileBtnicon fileSave" @click="getImageTiled"></div>
  98. <div class="fileBtnicon fileDel"></div>
  99. </div>
  100. </div>
  101. </div>
  102. </div> -->
  103. </div>
  104. <div v-if="isEdit" class="scrollBox">
  105. <!-- <button id="location1">定位1</button>
  106. <button id="location2">定位2</button> -->
  107. <!-- <p class="title">定位</p> -->
  108. <!-- <p class="desc">通过两个控制点坐标确定点云在地图上的位置</p> -->
  109. <p class="itemTitle">EPSG 坐标系 </p>
  110. <div class="formItem">
  111. <div class="allIpt">
  112. <input type="text" disabled v-model="EPSG" name="EPSG" id="EPSG" />
  113. </div>
  114. </div>
  115. <form>
  116. <div class="tag">
  117. <P class="formTitle">控制点1</P>
  118. <!-- <div class="localIcon" @click="set_location(1)"></div> -->
  119. </div>
  120. <div class="formItem">
  121. <p class="itemTitle">本地坐标:</p>
  122. <div class="inputItem">
  123. <div class="name"> X</div>
  124. <div class="ipt">
  125. <input type="text" v-model="ax" name="ax" id="ax" />
  126. </div>
  127. <span class="unit">m</span>
  128. </div>
  129. <div class="inputItem">
  130. <div class="name"> Y</div>
  131. <div class="ipt">
  132. <input type="text" v-model="ay" name="ay" id="ay" />
  133. </div>
  134. <span class="unit">m</span>
  135. </div>
  136. <div class="inputItem">
  137. <div class="name"> Z</div>
  138. <div class="ipt">
  139. <input type="text" v-model="az" name="az" id="az" />
  140. </div>
  141. <span class="unit">m</span>
  142. </div>
  143. </div>
  144. <div class="formItem">
  145. <p class="itemTitle">地理坐标:</p>
  146. <div class="inputItem">
  147. <div class="name">经度</div>
  148. <div class="ipt">
  149. <input type="text" v-model="alon" name="alon" id="alon" value="120" />
  150. </div>
  151. </div>
  152. <div class="inputItem">
  153. <div class="name">纬度</div>
  154. <div class="ipt">
  155. <input type="text" v-model="alat" name="alat" id="alat" value="22" />
  156. </div>
  157. </div>
  158. <div class="inputItem">
  159. <div class="name">高程</div>
  160. <div class="ipt">
  161. <input type="text" v-model="aalt" name="aalt" id="aalt" value="0" />
  162. </div>
  163. </div>
  164. </div>
  165. <div class="tag">
  166. <P class="formTitle">控制点2</P>
  167. <!-- <div class="localIcon" @click="set_location(2)"></div> -->
  168. </div>
  169. <div class="formItem">
  170. <p class="itemTitle">本地坐标:</p>
  171. <div class="inputItem">
  172. <div class="name"> X</div>
  173. <div class="ipt">
  174. <input type="text" v-model="bx" name="bx" id="bx" />
  175. </div>
  176. <span class="unit">m</span>
  177. </div>
  178. <div class="inputItem">
  179. <div class="name"> Y</div>
  180. <div class="ipt">
  181. <input type="text" v-model="by" name="by" id="by" />
  182. </div>
  183. <span class="unit">m</span>
  184. </div>
  185. <div class="inputItem">
  186. <div class="name"> Z</div>
  187. <div class="ipt">
  188. <input type="text" v-model="bz" name="bz" id="bz" />
  189. </div>
  190. <span class="unit">m</span>
  191. </div>
  192. </div>
  193. <div class="formItem">
  194. <p class="itemTitle">地理坐标:</p>
  195. <div class="inputItem">
  196. <div class="name">经度</div>
  197. <div class="ipt">
  198. <input type="text" v-model="blon" name="blon" id="blon" value="123" />
  199. </div>
  200. </div>
  201. <div class="inputItem">
  202. <div class="name">纬度</div>
  203. <div class="ipt">
  204. <input type="text" v-model="blat" name="blat" id="blat" value="22" />
  205. </div>
  206. </div>
  207. <div class="inputItem">
  208. <div class="name">高程</div>
  209. <div class="ipt">
  210. <input type="text" v-model="balt" name="balt" id="balt" value="0" />
  211. </div>
  212. </div>
  213. </div>
  214. </form>
  215. </div>
  216. <div v-if="isEdit" class="bottom">
  217. <div class="style"></div>
  218. <!-- <input type="submit" class="submitBtn" value="提交" />
  219. <button id="clear">取消</button> -->
  220. <!-- <div id="clear" @click="getImageTransform">提交地图信息</div> -->
  221. <!-- <div id="clear" @click="clearMap">取消</div> -->
  222. <div id="clear" @click="isEdit=false">取消</div>
  223. <div class="submitBtn" @click="commit()">
  224. 保存
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </div>
  230. <script src="./js/vue.js"></script>
  231. <script src="./js/axios.min.js"></script>
  232. <script src="./js/proj4.js"></script>
  233. <script src="./js/three.js"></script>
  234. <script src="./components/image-transform/index.js"></script>
  235. <script type="text/javascript">
  236. //输入经纬度就可以定位
  237. </script>
  238. <script>
  239. //坐标转换定义 部分 定义一个 cgc_2000的38度带投影坐标系
  240. proj4.defs("EPSG:99999",
  241. "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
  242. proj4.defs("EPSG:99999", "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
  243. proj4.defs("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs");
  244. var projection = new ol.proj.Projection({
  245. code: "EPSG:99999",
  246. extent: [334238.8538694997, 425861.702215328, 599418.034383447, 5936877.5664797],
  247. units: 'm',
  248. axisOrientation: 'neu',
  249. global: false
  250. });
  251. //结合proj4在ol中自定义坐标系
  252. ol.proj.addProjection(projection);
  253. ol.proj.addCoordinateTransforms("EPSG:4326", "EPSG:99999",
  254. function(coordinate) {
  255. return proj4("EPSG:4326", "EPSG:99999", coordinate);
  256. },
  257. function(coordinate) {
  258. return proj4("EPSG:99999", "EPSG:4326", coordinate);
  259. }
  260. );
  261. new Vue({
  262. el: '#app',
  263. data() {
  264. return {
  265. showImageTranform: true,
  266. showImageTranform1: true,
  267. isEdit: false,
  268. pointLayerArray: [],
  269. map: null,
  270. gaodeMapLayer: {},
  271. ax: '',
  272. ay: '',
  273. az: '',
  274. alon: '120',
  275. alat: '22',
  276. aalt: '',
  277. bx: '',
  278. by: '',
  279. bz: '',
  280. blon: '123',
  281. blat: '22',
  282. balt: '',
  283. EPSG: 'EPSG:4490',
  284. ageControlLocation1: [],
  285. ageControlLocation2: [],
  286. gpsControlCoordinate1: [],
  287. gpsControlCoordinate2: [],
  288. control_point_data: {
  289. ageControlLocation1: [],
  290. ageControlLocation2: [],
  291. gpsControlCoordinate1: [],
  292. gpsControlCoordinate2: [],
  293. },
  294. sceneNum: '',
  295. canvas: null,
  296. ctx: null,
  297. imageCanvas: null,
  298. imageCanvasLayer: null,
  299. img: null,
  300. drugObj: null,
  301. rotateObj: null,
  302. imgSrc: null,
  303. file: null,
  304. isRotate: false,
  305. isDraw: false,
  306. size: 512,
  307. limitSize: 512,
  308. uploadData: {
  309. file: null,
  310. lon: '113.59963069739054',
  311. lat: '22.364821730960752',
  312. direction: '0',
  313. size: '256'
  314. },
  315. // 优化
  316. showData: {
  317. ax: '',
  318. ay: '',
  319. az: '',
  320. alon: '120',
  321. alat: '22',
  322. aalt: '',
  323. bx: '',
  324. by: '',
  325. bz: '',
  326. blon: '123',
  327. blat: '22',
  328. balt: ''
  329. }
  330. }
  331. },
  332. created() {
  333. },
  334. mounted() {
  335. this.getContorlPoint()
  336. this.sceneNum = window.location.pathname.split('/')[2]
  337. this.$nextTick(() => {
  338. let t = setTimeout(() => {
  339. this.map = this.initMap('map');
  340. }, 100)
  341. })
  342. },
  343. methods: {
  344. readyUpload() {
  345. // console.log(this.$refs.imageTranform)
  346. this.$refs.imageTranform.readyUpload()
  347. },
  348. getImageTransform() {
  349. // 地图数据上传 如果用户没有选择数据直接返回true 如果有数据要上传返回promise
  350. Promise.all([
  351. this.$refs.imageTranform.uploadData(),
  352. this.$refs.imageTranform.uploadTiled()
  353. ])
  354. .then(res => {
  355. alert('成功')
  356. this.showImageTranform = false
  357. this.$nextTick(() => {
  358. this.showImageTranform = true
  359. })
  360. })
  361. .catch(() => {
  362. alert('失败')
  363. })
  364. },
  365. getImageTiled() {
  366. this.$refs.imageTranform.uploadTiled()
  367. .then(() => alert('成功'))
  368. .catch(() => {
  369. alert('失败')
  370. })
  371. },
  372. initMap(divid) {
  373. this.pointLayerArray = [];
  374. this.gaodeMapLayer = new ol.layer.Tile({
  375. source: new ol.source.XYZ({
  376. url: 'http://wprd03.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}' //高德地图切片访问路径
  377. })
  378. });
  379. return new ol.Map({
  380. layers: [this.gaodeMapLayer],
  381. target: divid,
  382. view: new ol.View({
  383. center: ol.proj.fromLonLat([113.59569403794666,
  384. 22.36656052911783
  385. ]), //最初定位的位置
  386. zoom: 4 //地图层级
  387. })
  388. });
  389. },
  390. clearMap() {
  391. this.pointLayerArray.map(each => {
  392. if (each.type == "con_point") {
  393. this.map.removeLayer(each)
  394. }
  395. });
  396. this.pointLayerArray = [];
  397. },
  398. addPoint(lon, lat, text, index) {
  399. let vector = new ol.source.Vector();
  400. let vLayer = new ol.layer.Vector({
  401. source: vector
  402. })
  403. vLayer.type = "con_point";
  404. vLayer.index = index;
  405. this.map.addLayer(vLayer)
  406. this.pointLayerArray.push(vLayer);
  407. let labelCoords = ol.proj.transform([lon, lat], "EPSG:4326", "EPSG:3857");
  408. let feature = new ol.Feature({
  409. geometry: new ol.geom.Point(labelCoords)
  410. });
  411. vector.addFeature(feature);
  412. vLayer.setStyle(new ol.style.Style({
  413. image: new ol.style.Circle({ //点样式
  414. radius: 7,
  415. fill: new ol.style.Fill({
  416. color: '#00c033'
  417. })
  418. }),
  419. text: new ol.style.Text({
  420. text: text,
  421. font: '15px sans-serif',
  422. offsetX: 5,
  423. offsetY: -10,
  424. fill: new ol.style.Fill({
  425. color: "#b9391f"
  426. }),
  427. stroke: new ol.style.Stroke({
  428. color: "#b9391f"
  429. })
  430. })
  431. }))
  432. this.map.getView().setCenter(labelCoords)
  433. },
  434. set_location(index) {
  435. let alon
  436. let alat
  437. let str = ''
  438. if (index == 1) {
  439. alon = this.alon;
  440. alat = this.alat;
  441. str = '锚点1'
  442. } else {
  443. alon = this.blon;
  444. alat = this.blat;
  445. str = '锚点2'
  446. }
  447. this.removePoint(index)
  448. this.addPoint(+alon, +alat, str, index)
  449. },
  450. removePoint(index) {
  451. let num = this.pointLayerArray.filter((item, i) => {
  452. if (index == item.index) {
  453. this.pointLayerArray.splice(i, 1)
  454. }
  455. })
  456. },
  457. commit() {
  458. this.handleData()
  459. Promise.all([
  460. axios.post('/indoor/' + this.sceneNum + '/api/controlPoint/save', {
  461. ageControlLocation1: this.ageControlLocation1,
  462. ageControlLocation2: this.ageControlLocation2,
  463. gpsControlCoordinate1: this.gpsControlCoordinate1,
  464. gpsControlCoordinate2: this.gpsControlCoordinate2,
  465. sceneNum: this.sceneNum,
  466. // id: 1
  467. })
  468. .catch(function(error) {
  469. alert('数据集位置上传失败')
  470. }),
  471. // this.getImageTransform()
  472. // .catch(_ => {
  473. // alert('地图数据上传失败')
  474. // })
  475. ]).then(() => {
  476. this.getContorlPoint()
  477. alert('成功')
  478. })
  479. },
  480. handleData() {
  481. //重置数组
  482. this.ageControlLocation1 = []
  483. this.ageControlLocation2 = []
  484. this.gpsControlCoordinate1 = []
  485. this.gpsControlCoordinate2 = []
  486. //
  487. this.ageControlLocation1.push(this.ax - 0)
  488. this.ageControlLocation1.push(this.ay - 0)
  489. this.ageControlLocation1.push(this.az - 0)
  490. this.gpsControlCoordinate1.push(this.alon - 0)
  491. this.gpsControlCoordinate1.push(this.alat - 0)
  492. this.gpsControlCoordinate1.push(this.aalt - 0)
  493. this.ageControlLocation2.push(this.bx - 0)
  494. this.ageControlLocation2.push(this.by - 0)
  495. this.ageControlLocation2.push(this.bz - 0)
  496. this.gpsControlCoordinate2.push(this.blon - 0)
  497. this.gpsControlCoordinate2.push(this.blat - 0)
  498. this.gpsControlCoordinate2.push(this.balt - 0)
  499. },
  500. //获取控制点
  501. getContorlPoint() {
  502. // /indoor/{sceneCode}/api/controlPoint/detail
  503. const sceneName = window.location.pathname.split('/')[2]
  504. const isDev = !sceneName || sceneName === 'addDataSet.html'
  505. const sceneCode = isDev ? 't-kJ2PEjZ' : sceneName
  506. axios.get(`/indoor/${sceneCode}/api/controlPoint/detail`).then(res => {
  507. this.initContorlPoint(res.data.data)
  508. this.set_location(1)
  509. this.set_location(2)
  510. }).catch(err => {
  511. })
  512. },
  513. initContorlPoint(data) {
  514. this.ax = data.ageControlLocation1[0]
  515. this.ay = data.ageControlLocation1[1]
  516. this.bx = data.ageControlLocation2[0]
  517. this.by = data.ageControlLocation2[1]
  518. this.alon = data.gpsControlCoordinate1[0]
  519. this.alat = data.gpsControlCoordinate1[1]
  520. this.blon = data.gpsControlCoordinate2[0]
  521. this.blat = data.gpsControlCoordinate2[1]
  522. this.showData.ax = data.ageControlLocation1[0]
  523. this.showData.ay = data.ageControlLocation1[1]
  524. this.showData.bx = data.ageControlLocation2[0]
  525. this.showData.by = data.ageControlLocation2[1]
  526. this.showData.alon = data.gpsControlCoordinate1[0]
  527. this.showData.alat = data.gpsControlCoordinate1[1]
  528. this.showData.blon = data.gpsControlCoordinate2[0]
  529. this.showData.blat = data.gpsControlCoordinate2[1]
  530. },
  531. openEdit() {
  532. this.isEdit = true
  533. this.ax = this.showData.ax
  534. this.ay = this.showData.ay
  535. this.bx = this.showData.bx
  536. this.by = this.showData.by
  537. this.alon = this.showData.alon
  538. this.alat = this.showData.alat
  539. this.blon = this.showData.blon
  540. this.blat = this.showData.blat
  541. }
  542. }
  543. })
  544. </script>
  545. </body>
  546. </html>