Map.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div id="mapView">
  3. <iframe id="i_map" name="i_map" frameborder="0"></iframe>
  4. </div>
  5. </template>
  6. <script>
  7. import CityGis from "../../utils/map/CityGis.Bridge";
  8. import { myBridge } from "@/utils/map/map";
  9. import { mapMapMutations } from "@/utils/store-map-unit";
  10. let bridge
  11. export {bridge}
  12. export default {
  13. name: 'MyMap',
  14. mounted() {
  15. this.createMap()
  16. },
  17. methods: {
  18. ...mapMapMutations({
  19. changesearchAArr:'changesearchAArr',
  20. }),
  21. createMap() {
  22. this.$nextTick(() => {
  23. myBridge.bridgeContent = bridge = new CityGis.Bridge({
  24. id: "i_map",
  25. url: "http://10.108.3.5:8089/map_widget/#/mapcmnw?theme=dark&view=2D",
  26. onReady: function () {
  27. },
  28. });
  29. bridge.addEventListener((arg) => {
  30. console.log(arg)
  31. switch (arg.action) {
  32. case "MapIsReady":
  33. this.addPointSearch()
  34. break
  35. case "ViewComplete":
  36. this.locateCM()
  37. break
  38. case "Calculation":
  39. this.$message({
  40. showClose: true,
  41. duration: 10000,
  42. message: '测量结果:'+arg.data.result,
  43. });
  44. break
  45. case 'MapClickResult':
  46. this.$emit('pointSearchRes', arg.data[0])
  47. break
  48. case "ReturnResult": {
  49. let arr =(arg?.data?.data || []).map(i => ({
  50. ...i,
  51. name:i.zhutiname
  52. }))
  53. let realArr = []
  54. for (let i = 0; i < arr.length; i+1) {
  55. let findAllZt = arr.filter(i1 => i1.zhutiname === arr[i].zhutiname)
  56. realArr.push(arr[i])
  57. i = findAllZt.length
  58. }
  59. this['changesearchAArr'](realArr)
  60. break;
  61. }
  62. }
  63. })
  64. })
  65. },
  66. addPointSearch() {
  67. let action = {
  68. ActionName: "MapClickAll",
  69. Parameters: {
  70. "status": true,
  71. "is_draw": true,
  72. "is_code": false
  73. },
  74. }
  75. bridge.Invoke(action)
  76. },
  77. calcuLine(toolStatus) {
  78. let action = {}
  79. if (toolStatus) {
  80. action = {
  81. ActionName: "Calculation",
  82. Parameters: {
  83. type: "polyline"
  84. },
  85. }
  86. } else {
  87. action = {
  88. ActionName: "ClearMap",
  89. Parameters: {
  90. is_draw: true,
  91. is_search: false,
  92. is_position: false
  93. }
  94. }
  95. }
  96. bridge.Invoke(action)
  97. },
  98. calcuGon(toolStatus) {
  99. let action = {}
  100. if (toolStatus) {
  101. action = {
  102. ActionName: "Calculation",
  103. Parameters: {
  104. type: "polygon"
  105. },
  106. }
  107. } else {
  108. action = {
  109. ActionName: "ClearMap",
  110. Parameters: {
  111. is_draw: true,
  112. is_search: false,
  113. is_position: false
  114. }
  115. }
  116. }
  117. bridge.Invoke(action)
  118. },
  119. addLayer(layer,visible=true,opacity=1) {
  120. let type = 'feature'
  121. let token_type = ''
  122. if(layer.url.startsWith('http://10.121.226.95')) {
  123. type = 'shc_map'
  124. token_type = 'token_nw'
  125. } else if(layer.url.startsWith('http://smiserver.gtj.sh.cegn.cn')) {
  126. type = 'shc_map'
  127. token_type = 'token_smi'
  128. }
  129. if(layer.type) {
  130. type = layer.type
  131. }
  132. let params = {
  133. ActionName: "AddLayer",
  134. Parameters: {
  135. id: layer.id,
  136. title: layer.title,
  137. visible,
  138. opacity,
  139. url: layer.url,
  140. type,
  141. token_type
  142. },
  143. };
  144. if(layer.sublayers) {
  145. params.Parameters['sublayers'] = layer.sublayers
  146. }
  147. console.log('添加图层---',params)
  148. bridge.Invoke(params);
  149. },
  150. emptyAllLayers() {
  151. let action = {
  152. ActionName: "ClearMapLayers"
  153. }
  154. bridge.Invoke(action)
  155. },
  156. clearMap() {
  157. let action = {
  158. ActionName: "ClearMap",
  159. Parameters: {
  160. is_draw: true,
  161. is_search: true,
  162. is_position: true
  163. }
  164. }
  165. bridge.Invoke(action)
  166. },
  167. changeBaseMap(name) {
  168. let params = {
  169. ActionName: "ChangeBaseMap",
  170. Parameters: {
  171. "title": name,
  172. "opacity": 1
  173. },
  174. };
  175. bridge.Invoke(params);
  176. },
  177. locateCM() {
  178. const params32 = {
  179. "minx": -31227.356231616784,
  180. "miny": 19268.786635562752,
  181. "maxx": 47546.66798309832,
  182. "maxy": 75148.89839578628
  183. }
  184. const params16 = {
  185. "minx": -90405,
  186. "miny": -9789,
  187. "maxx": 109738,
  188. "maxy": 102790
  189. }
  190. const screenRatio = document.body.clientWidth / document.body.clientHeight
  191. let action = {
  192. ActionName: "SetExtent",
  193. };
  194. if(screenRatio>2) {
  195. action['Parameters'] = params32
  196. } else {
  197. action['Parameters'] = params16
  198. }
  199. bridge.Invoke(action);
  200. },
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. #mapView {
  206. position: absolute;
  207. top: 0;
  208. left: 0;
  209. height: 100%;
  210. width: 100%;
  211. background-color: #235F61;
  212. z-index: 2;
  213. }
  214. #i_map {
  215. padding: 0;
  216. margin: 0;
  217. height: 100%;
  218. width: 100%;
  219. }
  220. </style>