addDataSet.html 25 KB

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