addDataSet.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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="isEdit=true">修改锚点</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:{{ax}}</span>
  37. <span>Y:{{ay}}</span>
  38. <span>Z:{{az}}</span>
  39. </div>
  40. <p>地理坐标</p>
  41. <div>
  42. <span>经度:{{alon}}</span>
  43. <span>纬度:{{alat}}</span>
  44. <span>高程:{{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:{{bx}}</span>
  54. <span>Y:{{by}}</span>
  55. <span>Z:{{bz}}</span>
  56. </div>
  57. <p>地理坐标</p>
  58. <div>
  59. <span>经度:{{blon}}</span>
  60. <span>纬度:{{blat}}</span>
  61. <span>高程:{{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. <form>
  109. <div class="tag">
  110. <P class="formTitle">锚点1</P>
  111. <!-- <div class="localIcon" @click="set_location(1)"></div> -->
  112. </div>
  113. <div class="formItem">
  114. <p class="itemTitle">本地坐标:</p>
  115. <div class="inputItem">
  116. <div class="name"> X</div>
  117. <div class="ipt">
  118. <input type="text" v-model="ax" name="ax" id="ax" />
  119. </div>
  120. <span class="unit">m</span>
  121. </div>
  122. <div class="inputItem">
  123. <div class="name"> Y</div>
  124. <div class="ipt">
  125. <input type="text" v-model="ay" name="ay" id="ay" />
  126. </div>
  127. <span class="unit">m</span>
  128. </div>
  129. <div class="inputItem">
  130. <div class="name"> Z</div>
  131. <div class="ipt">
  132. <input type="text" v-model="az" name="az" id="az" />
  133. </div>
  134. <span class="unit">m</span>
  135. </div>
  136. </div>
  137. <div class="formItem">
  138. <p class="itemTitle">地理坐标:</p>
  139. <div class="inputItem">
  140. <div class="name">经度</div>
  141. <div class="ipt">
  142. <input type="text" v-model="alon" name="alon" id="alon" value="120" />
  143. </div>
  144. </div>
  145. <div class="inputItem">
  146. <div class="name">纬度</div>
  147. <div class="ipt">
  148. <input type="text" v-model="alat" name="alat" id="alat" value="22" />
  149. </div>
  150. </div>
  151. <div class="inputItem">
  152. <div class="name">高程</div>
  153. <div class="ipt">
  154. <input type="text" v-model="aalt" name="aalt" id="aalt" value="0" />
  155. </div>
  156. </div>
  157. </div>
  158. <div class="tag">
  159. <P class="formTitle">锚点2</P>
  160. <!-- <div class="localIcon" @click="set_location(2)"></div> -->
  161. </div>
  162. <div class="formItem">
  163. <p class="itemTitle">本地坐标:</p>
  164. <div class="inputItem">
  165. <div class="name"> X</div>
  166. <div class="ipt">
  167. <input type="text" v-model="bx" name="bx" id="bx" />
  168. </div>
  169. <span class="unit">m</span>
  170. </div>
  171. <div class="inputItem">
  172. <div class="name"> Y</div>
  173. <div class="ipt">
  174. <input type="text" v-model="by" name="by" id="by" />
  175. </div>
  176. <span class="unit">m</span>
  177. </div>
  178. <div class="inputItem">
  179. <div class="name"> Z</div>
  180. <div class="ipt">
  181. <input type="text" v-model="bz" name="bz" id="bz" />
  182. </div>
  183. <span class="unit">m</span>
  184. </div>
  185. </div>
  186. <div class="formItem">
  187. <p class="itemTitle">地理坐标:</p>
  188. <div class="inputItem">
  189. <div class="name">经度</div>
  190. <div class="ipt">
  191. <input type="text" v-model="blon" name="blon" id="blon" value="123" />
  192. </div>
  193. </div>
  194. <div class="inputItem">
  195. <div class="name">纬度</div>
  196. <div class="ipt">
  197. <input type="text" v-model="blat" name="blat" id="blat" value="22" />
  198. </div>
  199. </div>
  200. <div class="inputItem">
  201. <div class="name">高程</div>
  202. <div class="ipt">
  203. <input type="text" v-model="balt" name="balt" id="balt" value="0" />
  204. </div>
  205. </div>
  206. </div>
  207. <!-- <p class="itemTitle">EPSG 坐标系 </p>
  208. <div class="formItem">
  209. <div class="allIpt">
  210. <input type="text" v-model="EPSG" name="EPSG" id="EPSG" />
  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:99999',
  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. list: [{
  316. ageControlLocation1: [0, 0, 0],
  317. gpsControlCoordinate1: [120, 22, 0]
  318. }, {
  319. ageControlLocation2: [0, 0, 0],
  320. gpsControlCoordinate2: [123, 22, 0]
  321. }]
  322. }
  323. },
  324. created() {
  325. },
  326. mounted() {
  327. this.getContorlPoint()
  328. this.sceneNum = window.location.pathname.split('/')[2]
  329. this.$nextTick(() => {
  330. let t = setTimeout(() => {
  331. this.map = this.initMap('map');
  332. }, 100)
  333. })
  334. },
  335. methods: {
  336. readyUpload() {
  337. // console.log(this.$refs.imageTranform)
  338. this.$refs.imageTranform.readyUpload()
  339. },
  340. getImageTransform() {
  341. // 地图数据上传 如果用户没有选择数据直接返回true 如果有数据要上传返回promise
  342. Promise.all([
  343. this.$refs.imageTranform.uploadData(),
  344. this.$refs.imageTranform.uploadTiled()
  345. ])
  346. .then(res => {
  347. alert('成功')
  348. this.showImageTranform = false
  349. this.$nextTick(() => {
  350. this.showImageTranform = true
  351. })
  352. })
  353. .catch(() => {
  354. alert('失败')
  355. })
  356. },
  357. getImageTiled() {
  358. this.$refs.imageTranform.uploadTiled()
  359. .then(() => alert('成功'))
  360. .catch(() => {
  361. alert('失败')
  362. })
  363. },
  364. initMap(divid) {
  365. this.pointLayerArray = [];
  366. this.gaodeMapLayer = new ol.layer.Tile({
  367. source: new ol.source.XYZ({
  368. url: 'http://wprd03.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}' //高德地图切片访问路径
  369. })
  370. });
  371. return new ol.Map({
  372. layers: [this.gaodeMapLayer],
  373. target: divid,
  374. view: new ol.View({
  375. center: ol.proj.fromLonLat([113.59569403794666,
  376. 22.36656052911783
  377. ]), //最初定位的位置
  378. zoom: 4 //地图层级
  379. })
  380. });
  381. },
  382. clearMap() {
  383. this.pointLayerArray.map(each => {
  384. if (each.type == "con_point") {
  385. this.map.removeLayer(each)
  386. }
  387. });
  388. this.pointLayerArray = [];
  389. },
  390. addPoint(lon, lat, text, index) {
  391. let vector = new ol.source.Vector();
  392. let vLayer = new ol.layer.Vector({
  393. source: vector
  394. })
  395. vLayer.type = "con_point";
  396. vLayer.index = index;
  397. this.map.addLayer(vLayer)
  398. this.pointLayerArray.push(vLayer);
  399. let labelCoords = ol.proj.transform([lon, lat], "EPSG:4326", "EPSG:3857");
  400. let feature = new ol.Feature({
  401. geometry: new ol.geom.Point(labelCoords)
  402. });
  403. vector.addFeature(feature);
  404. vLayer.setStyle(new ol.style.Style({
  405. image: new ol.style.Circle({ //点样式
  406. radius: 7,
  407. fill: new ol.style.Fill({
  408. color: '#00c033'
  409. })
  410. }),
  411. text: new ol.style.Text({
  412. text: text,
  413. font: '15px sans-serif',
  414. offsetX: 5,
  415. offsetY: -10,
  416. fill: new ol.style.Fill({
  417. color: "#b9391f"
  418. }),
  419. stroke: new ol.style.Stroke({
  420. color: "#b9391f"
  421. })
  422. })
  423. }))
  424. this.map.getView().setCenter(labelCoords)
  425. },
  426. set_location(index) {
  427. let alon
  428. let alat
  429. let str = ''
  430. if (index == 1) {
  431. alon = this.alon;
  432. alat = this.alat;
  433. str = '锚点1'
  434. } else {
  435. alon = this.blon;
  436. alat = this.blat;
  437. str = '锚点2'
  438. }
  439. this.removePoint(index)
  440. this.addPoint(+alon, +alat, str, index)
  441. },
  442. removePoint(index) {
  443. let num = this.pointLayerArray.filter((item, i) => {
  444. if (index == item.index) {
  445. this.pointLayerArray.splice(i, 1)
  446. }
  447. })
  448. },
  449. commit() {
  450. this.handleData()
  451. Promise.all([
  452. axios.post('/indoor/' + this.sceneNum + '/api/controlPoint/save', {
  453. ageControlLocation1: this.ageControlLocation1,
  454. ageControlLocation2: this.ageControlLocation2,
  455. gpsControlCoordinate1: this.gpsControlCoordinate1,
  456. gpsControlCoordinate2: this.gpsControlCoordinate2,
  457. sceneNum: this.sceneNum,
  458. // id: 1
  459. })
  460. .catch(function(error) {
  461. alert('数据集位置上传失败')
  462. }),
  463. this.getImageTransform()
  464. .catch(_ => {
  465. alert('地图数据上传失败')
  466. })
  467. ]).then(() => {
  468. alert('成功')
  469. })
  470. },
  471. handleData() {
  472. //重置数组
  473. this.ageControlLocation1 = []
  474. this.ageControlLocation2 = []
  475. this.gpsControlCoordinate1 = []
  476. this.gpsControlCoordinate2 = []
  477. //
  478. this.ageControlLocation1.push(this.ax - 0)
  479. this.ageControlLocation1.push(this.ay - 0)
  480. this.ageControlLocation1.push(this.az - 0)
  481. this.gpsControlCoordinate1.push(this.alon - 0)
  482. this.gpsControlCoordinate1.push(this.alat - 0)
  483. this.gpsControlCoordinate1.push(this.aalt - 0)
  484. this.ageControlLocation2.push(this.bx - 0)
  485. this.ageControlLocation2.push(this.by - 0)
  486. this.ageControlLocation2.push(this.bz - 0)
  487. this.gpsControlCoordinate2.push(this.blon - 0)
  488. this.gpsControlCoordinate2.push(this.blat - 0)
  489. this.gpsControlCoordinate2.push(this.balt - 0)
  490. },
  491. //获取控制点
  492. getContorlPoint() {
  493. // /indoor/{sceneCode}/api/controlPoint/detail
  494. const sceneName = window.location.pathname.split('/')[2]
  495. const isDev = !sceneName || sceneName === 'addDataSet.html'
  496. const sceneCode = isDev ? 't-kJ2PEjZ' : sceneName
  497. axios.get(`/indoor/${sceneCode}/api/controlPoint/detail`).then(res => {
  498. this.initContorlPoint(res.data.data)
  499. this.set_location(1)
  500. this.set_location(2)
  501. }).catch(err => {
  502. })
  503. },
  504. initContorlPoint(data) {
  505. console.log(data)
  506. this.ax = data.ageControlLocation1[0]
  507. this.ay = data.ageControlLocation1[1]
  508. this.bx = data.ageControlLocation2[0]
  509. this.by = data.ageControlLocation2[1]
  510. this.alon = data.gpsControlCoordinate1[0]
  511. this.alat = data.gpsControlCoordinate1[1]
  512. this.blon = data.gpsControlCoordinate2[0]
  513. this.blat = data.gpsControlCoordinate2[1]
  514. }
  515. }
  516. })
  517. </script>
  518. </body>
  519. </html>