addDataSet.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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" 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="">
  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"></div>
  61. <div class="fileBtnicon fileSave"></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="./components/image-transform/index.js"></script>
  197. <script type="text/javascript">
  198. //输入经纬度就可以定位
  199. </script>
  200. <script>
  201. //坐标转换定义 部分 定义一个 cgc_2000的38度带投影坐标系
  202. proj4.defs("EPSG:99999",
  203. "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
  204. var projection = new ol.proj.Projection({
  205. code: "EPSG:99999",
  206. extent: [334238.8538694997, 425861.702215328, 599418.034383447, 5936877.5664797],
  207. units: 'm',
  208. axisOrientation: 'neu',
  209. global: false
  210. });
  211. //结合proj4在ol中自定义坐标系
  212. ol.proj.addProjection(projection);
  213. ol.proj.addCoordinateTransforms("EPSG:4326", "EPSG:99999",
  214. function(coordinate) {
  215. return proj4("EPSG:4326", "EPSG:99999", coordinate);
  216. },
  217. function(coordinate) {
  218. return proj4("EPSG:99999", "EPSG:4326", coordinate);
  219. }
  220. );
  221. new Vue({
  222. el: '#app',
  223. data() {
  224. return {
  225. isEdit: false,
  226. pointLayerArray: [],
  227. map: null,
  228. gaodeMapLayer: {},
  229. ax: '',
  230. ay: '',
  231. az: '',
  232. alon: '120',
  233. alat: '22',
  234. aalt: '0',
  235. bx: '',
  236. by: '',
  237. bz: '',
  238. blon: '123',
  239. blat: '22',
  240. balt: '0',
  241. EPSG: 'EPSG:99999',
  242. ageControlLocation1: [],
  243. ageControlLocation2: [],
  244. gpsControlCoordinate1: [],
  245. gpsControlCoordinate2: [],
  246. control_point_data: {
  247. ageControlLocation1: [],
  248. ageControlLocation2: [],
  249. gpsControlCoordinate1: [],
  250. gpsControlCoordinate2: [],
  251. },
  252. sceneNum: '',
  253. canvas: null,
  254. ctx: null,
  255. imageCanvas: null,
  256. imageCanvasLayer: null,
  257. img: null,
  258. drugObj: null,
  259. rotateObj: null,
  260. imgSrc: null,
  261. file: null,
  262. isRotate: false,
  263. isDraw: false,
  264. size: 512,
  265. limitSize: 512,
  266. uploadData: {
  267. file: null,
  268. lon: '113.59963069739054',
  269. lat: '22.364821730960752',
  270. direction: '0',
  271. size: '256'
  272. },
  273. // 优化
  274. list: [{
  275. ageControlLocation1: [0, 0, 0],
  276. gpsControlCoordinate1: [120, 22, 0]
  277. }, {
  278. ageControlLocation2: [0, 0, 0],
  279. gpsControlCoordinate2: [123, 22, 0]
  280. }]
  281. }
  282. },
  283. created() {
  284. },
  285. mounted() {
  286. this.getContorlPoint()
  287. this.sceneNum = window.location.pathname.split('/')[2]
  288. let t = setTimeout(() => {
  289. this.map = this.initMap('map');
  290. }, 0)
  291. },
  292. methods: {
  293. getImageTransform() {
  294. // 地图数据上传 如果用户没有选择数据直接返回true 如果有数据要上传返回promise
  295. this.$refs.imageTranform.uploadData()
  296. .then(res => {
  297. alert('成功')
  298. })
  299. .catch(() => {
  300. alert('失败')
  301. })
  302. },
  303. initMap(divid) {
  304. this.pointLayerArray = [];
  305. this.gaodeMapLayer = new ol.layer.Tile({
  306. source: new ol.source.XYZ({
  307. url: 'http://wprd03.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}' //高德地图切片访问路径
  308. })
  309. });
  310. return new ol.Map({
  311. layers: [this.gaodeMapLayer],
  312. target: divid,
  313. view: new ol.View({
  314. center: ol.proj.fromLonLat([113.59569403794666,
  315. 22.36656052911783
  316. ]), //最初定位的位置
  317. zoom: 4 //地图层级
  318. })
  319. });
  320. },
  321. clearMap() {
  322. this.pointLayerArray.map(each => {
  323. if (each.type == "con_point") {
  324. this.map.removeLayer(each)
  325. }
  326. });
  327. this.pointLayerArray = [];
  328. },
  329. addPoint(lon, lat, text, index) {
  330. let vector = new ol.source.Vector();
  331. let vLayer = new ol.layer.Vector({
  332. source: vector
  333. })
  334. vLayer.type = "con_point";
  335. vLayer.index = index;
  336. this.map.addLayer(vLayer)
  337. this.pointLayerArray.push(vLayer);
  338. let labelCoords = ol.proj.transform([lon, lat], "EPSG:4326", "EPSG:3857");
  339. let feature = new ol.Feature({
  340. geometry: new ol.geom.Point(labelCoords)
  341. });
  342. vector.addFeature(feature);
  343. vLayer.setStyle(new ol.style.Style({
  344. image: new ol.style.Circle({ //点样式
  345. radius: 7,
  346. fill: new ol.style.Fill({
  347. color: '#00c033'
  348. })
  349. }),
  350. text: new ol.style.Text({
  351. text: text,
  352. font: '15px sans-serif',
  353. offsetX: 5,
  354. offsetY: -10,
  355. fill: new ol.style.Fill({
  356. color: "#b9391f"
  357. }),
  358. stroke: new ol.style.Stroke({
  359. color: "#b9391f"
  360. })
  361. })
  362. }))
  363. this.map.getView().setCenter(labelCoords)
  364. },
  365. set_location(index) {
  366. let alon
  367. let alat
  368. let str = ''
  369. if (index == 1) {
  370. alon = this.alon;
  371. alat = this.alat;
  372. str = '锚点1'
  373. } else {
  374. alon = this.blon;
  375. alat = this.blat;
  376. str = '锚点2'
  377. }
  378. this.removePoint(index)
  379. this.addPoint(+alon, +alat, str, index)
  380. },
  381. removePoint(index) {
  382. let num = this.pointLayerArray.filter((item, i) => {
  383. if (index == item.index) {
  384. this.pointLayerArray.splice(i, 1)
  385. }
  386. })
  387. },
  388. commit() {
  389. this.handleData()
  390. Promise.all([
  391. axios.post('/indoor/' + this.sceneNum + '/api/controlPoint/save', {
  392. ageControlLocation1: this.ageControlLocation1,
  393. ageControlLocation2: this.ageControlLocation2,
  394. gpsControlCoordinate1: this.gpsControlCoordinate1,
  395. gpsControlCoordinate2: this.gpsControlCoordinate2,
  396. sceneNum: this.sceneNum,
  397. // id: 1
  398. })
  399. .catch(function(error) {
  400. alert('数据集位置上传失败')
  401. }),
  402. this.getImageTransform()
  403. .catch(_ => {
  404. alert('地图数据上传失败')
  405. })
  406. ]).then(() => {
  407. alert('成功')
  408. })
  409. },
  410. handleData() {
  411. //重置数组
  412. this.ageControlLocation1 = []
  413. this.ageControlLocation2 = []
  414. this.gpsControlCoordinate1 = []
  415. this.gpsControlCoordinate2 = []
  416. //
  417. this.ageControlLocation1.push(this.ax - 0)
  418. this.ageControlLocation1.push(this.ay - 0)
  419. this.ageControlLocation1.push(this.az - 0)
  420. this.gpsControlCoordinate1.push(this.alon - 0)
  421. this.gpsControlCoordinate1.push(this.alat - 0)
  422. this.gpsControlCoordinate1.push(this.aalt - 0)
  423. this.ageControlLocation2.push(this.bx - 0)
  424. this.ageControlLocation2.push(this.by - 0)
  425. this.ageControlLocation2.push(this.bz - 0)
  426. this.gpsControlCoordinate2.push(this.blon - 0)
  427. this.gpsControlCoordinate2.push(this.blat - 0)
  428. this.gpsControlCoordinate2.push(this.balt - 0)
  429. },
  430. //获取控制点
  431. getContorlPoint() {
  432. // /indoor/{sceneCode}/api/controlPoint/detail
  433. const sceneName = window.location.pathname.split('/')[2]
  434. const isDev = !sceneName || sceneName === 'addDataSet.html'
  435. const sceneCode = isDev ? 't-kJ2PEjZ' : sceneName
  436. axios.get(`/indoor/${sceneCode}/api/controlPoint/detail`).then(res => {
  437. this.initContorlPoint(res.data.data)
  438. this.set_location(1)
  439. this.set_location(2)
  440. }).catch(err => {
  441. })
  442. },
  443. initContorlPoint(data) {
  444. console.log(data)
  445. this.ax = data.ageControlLocation1[0]
  446. this.ay = data.ageControlLocation1[1]
  447. this.bx = data.ageControlLocation2[0]
  448. this.by = data.ageControlLocation2[1]
  449. this.alon = data.gpsControlCoordinate1[0]
  450. this.alat = data.gpsControlCoordinate1[1]
  451. this.blon = data.gpsControlCoordinate2[0]
  452. this.blat = data.gpsControlCoordinate2[1]
  453. }
  454. }
  455. })
  456. </script>
  457. </body>
  458. </html>