addDataSet.html 22 KB

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