addDataSet.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 id="plane">
  22. <div class="scrollBox">
  23. <!-- <button id="location1">定位1</button>
  24. <button id="location2">定位2</button> -->
  25. <p class="title">数据集位置</p>
  26. <p class="desc">输入拍摄时记录的坐标,将数据集放置在真实世界地图中</p>
  27. <form>
  28. <div class="tag">
  29. <P class="formTitle">锚点1</P>
  30. <div class="localIcon" @click="location(1)"></div>
  31. </div>
  32. <div class="formItem">
  33. <p class="itemTitle">本地坐标:</p>
  34. <div class="inputItem">
  35. <div class="name"> X</div>
  36. <div class="ipt">
  37. <input type="text" v-model="ax" name="ax" id="ax" />
  38. </div>
  39. <span class="unit">m</span>
  40. </div>
  41. <div class="inputItem">
  42. <div class="name"> Y</div>
  43. <div class="ipt">
  44. <input type="text" v-model="ay" name="ay" id="ay" />
  45. </div>
  46. <span class="unit">m</span>
  47. </div>
  48. <div class="inputItem">
  49. <div class="name"> Z</div>
  50. <div class="ipt">
  51. <input type="text" v-model="az" name="az" id="az" />
  52. </div>
  53. <span class="unit">m</span>
  54. </div>
  55. </div>
  56. <div class="formItem">
  57. <p class="itemTitle">地理坐标:</p>
  58. <div class="inputItem">
  59. <div class="name">经度</div>
  60. <div class="ipt">
  61. <input type="text" v-model="alon" name="alon" id="alon" value="120" />
  62. </div>
  63. </div>
  64. <div class="inputItem">
  65. <div class="name">纬度</div>
  66. <div class="ipt">
  67. <input type="text" v-model="alat" name="alat" id="alat" value="22" />
  68. </div>
  69. </div>
  70. <div class="inputItem">
  71. <div class="name">高程</div>
  72. <div class="ipt">
  73. <input type="text" v-model="aalt" name="aalt" id="aalt" value="0" />
  74. </div>
  75. </div>
  76. </div>
  77. <div class="tag">
  78. <P class="formTitle">锚点2</P>
  79. <div class="localIcon" @click="location(2)"></div>
  80. </div>
  81. <div class="formItem">
  82. <p class="itemTitle">本地坐标:</p>
  83. <div class="inputItem">
  84. <div class="name"> X</div>
  85. <div class="ipt">
  86. <input type="text" v-model="bx" name="bx" id="bx" />
  87. </div>
  88. <span class="unit">m</span>
  89. </div>
  90. <div class="inputItem">
  91. <div class="name"> Y</div>
  92. <div class="ipt">
  93. <input type="text" v-model="by" name="by" id="by" />
  94. </div>
  95. <span class="unit">m</span>
  96. </div>
  97. <div class="inputItem">
  98. <div class="name"> Z</div>
  99. <div class="ipt">
  100. <input type="text" v-model="bz" name="bz" id="bz" />
  101. </div>
  102. <span class="unit">m</span>
  103. </div>
  104. </div>
  105. <div class="formItem">
  106. <p class="itemTitle">地理坐标:</p>
  107. <div class="inputItem">
  108. <div class="name">经度</div>
  109. <div class="ipt">
  110. <input type="text" v-model="blon" name="blon" id="blon" value="123" />
  111. </div>
  112. </div>
  113. <div class="inputItem">
  114. <div class="name">纬度</div>
  115. <div class="ipt">
  116. <input type="text" v-model="blat" name="blat" id="blat" value="22" />
  117. </div>
  118. </div>
  119. <div class="inputItem">
  120. <div class="name">高程</div>
  121. <div class="ipt">
  122. <input type="text" v-model="balt" name="balt" id="balt" value="0" />
  123. </div>
  124. </div>
  125. </div>
  126. <p class="itemTitle">EPSG 坐标系 </p>
  127. <div class="formItem">
  128. <div class="allIpt">
  129. <input type="text" v-model="EPSG" name="EPSG" id="EPSG" />
  130. </div>
  131. </div>
  132. </form>
  133. </div>
  134. <div class="bottom">
  135. <div class="style"></div>
  136. <!-- <input type="submit" class="submitBtn" value="提交" />
  137. <button id="clear">取消</button> -->
  138. <div id="clear" @click="getImageTransform">提交地图信息</div>
  139. <div id="clear" @click="clearMap">取消</div>
  140. <div class="submitBtn" @click="commit()">
  141. 提交
  142. </div>
  143. </div>
  144. </div>
  145. <div class="rightBox">
  146. <div class="map-layer">
  147. <div id="map" class="map"></div>
  148. <image-tranform :map-ol="map" v-if="map" ref="imageTranform" />
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <script src="./js/vue.js"></script>
  154. <script src="./js/axios.min.js"></script>
  155. <script src="./js/proj4.js"></script>
  156. <script src="./components/image-transform/index.js"></script>
  157. <script type="text/javascript">
  158. //输入经纬度就可以定位
  159. </script>
  160. <script>
  161. //坐标转换定义 部分 定义一个 cgc_2000的38度带投影坐标系
  162. 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");
  163. var projection = new ol.proj.Projection({
  164. code: "EPSG:99999",
  165. extent: [334238.8538694997, 425861.702215328, 599418.034383447, 5936877.5664797],
  166. units: 'm',
  167. axisOrientation: 'neu',
  168. global: false
  169. });
  170. //结合proj4在ol中自定义坐标系
  171. ol.proj.addProjection(projection);
  172. ol.proj.addCoordinateTransforms("EPSG:4326", "EPSG:99999",
  173. function (coordinate) {
  174. return proj4("EPSG:4326", "EPSG:99999", coordinate);
  175. },
  176. function (coordinate) {
  177. return proj4("EPSG:99999", "EPSG:4326", coordinate);
  178. }
  179. );
  180. new Vue({
  181. el: '#app',
  182. data() {
  183. return {
  184. pointLayerArray: [],
  185. map: null,
  186. gaodeMapLayer: {},
  187. ax: '',
  188. ay: '',
  189. az: '',
  190. alon: '120',
  191. alat: '22',
  192. aalt: '0',
  193. bx: '',
  194. by: '',
  195. bz: '',
  196. blon: '123',
  197. blat: '22',
  198. balt: '0',
  199. EPSG: 'EPSG:99999',
  200. ageControlLocation1: [],
  201. ageControlLocation2: [],
  202. gpsControlCoordinate1: [],
  203. gpsControlCoordinate2: [],
  204. sceneNum: '',
  205. canvas: null,
  206. ctx: null,
  207. imageCanvas: null,
  208. imageCanvasLayer: null,
  209. img: null,
  210. drugObj: null,
  211. rotateObj: null,
  212. imgSrc: null,
  213. file: null,
  214. isRotate: false,
  215. isDraw: false,
  216. size: 512,
  217. limitSize: 512,
  218. uploadData: {
  219. file: null,
  220. lon: '113.59963069739054',
  221. lat: '22.364821730960752',
  222. direction: '0',
  223. size: '256'
  224. }
  225. }
  226. },
  227. created() {
  228. },
  229. mounted() {
  230. this.sceneNum = window.location.pathname.split('/')[2]
  231. this.map = this.initMap('map');
  232. console.log(this.map)
  233. },
  234. methods: {
  235. getImageTransform() {
  236. // 地图数据上传 如果用户没有选择数据直接返回true 如果有数据要上传返回promise
  237. this.$refs.imageTranform.uploadData()
  238. .then(res => {
  239. alert('成功')
  240. })
  241. .catch(() => {
  242. alert('失败')
  243. })
  244. },
  245. initMap(divid) {
  246. this.pointLayerArray = [];
  247. this.gaodeMapLayer = new ol.layer.Tile({
  248. source: new ol.source.XYZ({
  249. url: 'http://wprd03.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}' //高德地图切片访问路径
  250. })
  251. });
  252. return new ol.Map({
  253. layers: [this.gaodeMapLayer],
  254. target: divid,
  255. view: new ol.View({
  256. center: ol.proj.fromLonLat([113.59569403794666,
  257. 22.36656052911783
  258. ]), //最初定位的位置
  259. zoom: 4 //地图层级
  260. })
  261. });
  262. },
  263. clearMap() {
  264. this.pointLayerArray.map(each => {
  265. if (each.type == "con_point") {
  266. this.map.removeLayer(each)
  267. }
  268. });
  269. this.pointLayerArray = [];
  270. },
  271. addPoint(lon, lat, text) {
  272. let vector = new ol.source.Vector();
  273. let vLayer = new ol.layer.Vector({
  274. source: vector
  275. })
  276. vLayer.type = "con_point";
  277. this.map.addLayer(vLayer)
  278. this.pointLayerArray.push(vLayer);
  279. let labelCoords = ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:99999');
  280. let feature = new ol.Feature({
  281. geometry: new ol.geom.Point(labelCoords)
  282. });
  283. vector.addFeature(feature);
  284. vLayer.setStyle(new ol.style.Style({
  285. image: new ol.style.Circle({ //点样式
  286. radius: 7,
  287. fill: new ol.style.Fill({
  288. color: '#00c033'
  289. })
  290. }),
  291. text: new ol.style.Text({
  292. text: text,
  293. font: '15px sans-serif',
  294. offsetX: 5,
  295. offsetY: -10,
  296. fill: new ol.style.Fill({
  297. color: "#b9391f"
  298. }),
  299. stroke: new ol.style.Stroke({
  300. color: "#b9391f"
  301. })
  302. })
  303. }))
  304. this.map.getView().setCenter(labelCoords)
  305. },
  306. location(type) {
  307. let alon
  308. let alat
  309. let str = ''
  310. if (type == 1) {
  311. alon = this.alon;
  312. alat = this.alat;
  313. str = '锚点1'
  314. } else {
  315. alon = this.blon;
  316. alat = this.blat;
  317. str = '锚点2'
  318. }
  319. this.addPoint(+alon, +alat, str)
  320. },
  321. handleData() {
  322. //重置数组
  323. this.ageControlLocation1 = []
  324. this.ageControlLocation2 = []
  325. this.gpsControlCoordinate1 = []
  326. this.gpsControlCoordinate2 = []
  327. //
  328. this.ageControlLocation1.push(this.ax - 0)
  329. this.ageControlLocation1.push(this.ay - 0)
  330. this.ageControlLocation1.push(this.az - 0)
  331. this.gpsControlCoordinate1.push(this.alon - 0)
  332. this.gpsControlCoordinate1.push(this.alat - 0)
  333. this.gpsControlCoordinate1.push(this.aalt - 0)
  334. this.ageControlLocation2.push(this.bx - 0)
  335. this.ageControlLocation2.push(this.by - 0)
  336. this.ageControlLocation2.push(this.bz - 0)
  337. this.gpsControlCoordinate2.push(this.blon - 0)
  338. this.gpsControlCoordinate2.push(this.blat - 0)
  339. this.gpsControlCoordinate2.push(this.balt - 0)
  340. },
  341. commit() {
  342. this.handleData()
  343. Promise.all([
  344. axios.post('/indoor/' + this.sceneNum + '/api/controlPoint/save', {
  345. ageControlLocation1: this.ageControlLocation1,
  346. ageControlLocation2: this.ageControlLocation2,
  347. gpsControlCoordinate1: this.gpsControlCoordinate1,
  348. gpsControlCoordinate2: this.gpsControlCoordinate2,
  349. sceneNum: this.sceneNum,
  350. // id: 1
  351. })
  352. .catch(function(error) {
  353. alert('数据集位置上传失败')
  354. }),
  355. this.getImageTransform()
  356. .catch(_ => {
  357. alert('地图数据上传失败')
  358. })
  359. ]).then(() => {
  360. alert('成功')
  361. })
  362. },
  363. }
  364. })
  365. </script>
  366. </body>
  367. </html>