addDataSet.html 25 KB

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