addDataSet.html 21 KB

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