index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <confirm-dialog
  3. ref="confirmDialg"
  4. title="坐标拾取"
  5. v-bind="$attrs"
  6. @confirm="onConfirm"
  7. >
  8. <div class="c-grid-form u-align-self--center">
  9. <span class="c-grid-form__label">来源</span>
  10. <schema-select
  11. v-model="info.type"
  12. :schema="typeSelectSchema"
  13. />
  14. <span class="c-grid-form__label" />
  15. <div class="c-grid-form__option">
  16. <div class="l-flex--row c-sibling-item--v">
  17. <span class="c-sibling-item c-grid-form__label u-required">经度</span>
  18. <el-input
  19. v-model.trim="info.longitude"
  20. class="c-sibling-item u-width--xs"
  21. placeholder="-180 ~ +180"
  22. maxlength="13"
  23. />
  24. <span class="c-sibling-item far c-grid-form__label u-required">纬度</span>
  25. <el-input
  26. v-model.trim="info.latitude"
  27. class="c-sibling-item far u-width--xs"
  28. placeholder="-90 ~ +90"
  29. maxlength="12"
  30. />
  31. </div>
  32. <a
  33. class="c-sibling-item--v nearer o-link"
  34. href="https://lbs.amap.com/tools/picker"
  35. target="_blank"
  36. >
  37. 高德地图拾取器(需登录提升精度)
  38. </a>
  39. <a
  40. class="c-sibling-item--v nearer o-link"
  41. href="http://api.map.baidu.com/lbsapi/getpoint/index.html"
  42. target="_blank"
  43. >
  44. 百度地图拾取器
  45. </a>
  46. </div>
  47. </div>
  48. </confirm-dialog>
  49. </template>
  50. <script>
  51. import AMapLoader from '@amap/amap-jsapi-loader'
  52. export default {
  53. name: 'CoordinateDialog',
  54. data () {
  55. return {
  56. info: {},
  57. typeSelectSchema: {
  58. options: [
  59. { value: 'gd', label: '高德' },
  60. { value: 'baidu', label: '百度' },
  61. { value: 'gps', label: 'GPS' }
  62. ]
  63. }
  64. }
  65. },
  66. methods: {
  67. show (data) {
  68. this.info = {
  69. type: 'gd',
  70. longitude: '',
  71. latitude: '',
  72. ...data
  73. }
  74. AMapLoader.load({
  75. key: process.env.VUE_APP_GAODE_MAP_KEY,
  76. version: '2.0',
  77. plugins: ['']
  78. }).then(AMap => {
  79. this.$map = AMap
  80. })
  81. this.$refs.confirmDialg.show()
  82. },
  83. onConfirm (done) {
  84. if (!this.info.longitude) {
  85. this.$message({
  86. type: 'warning',
  87. message: '请填写经度'
  88. })
  89. return
  90. }
  91. if (!this.info.latitude) {
  92. this.$message({
  93. type: 'warning',
  94. message: '请填写纬度'
  95. })
  96. return
  97. }
  98. if (this.info.type === 'gd') {
  99. this.$emit('confirm', {
  100. value: {
  101. longitude: this.info.longitude,
  102. latitude: this.info.latitude
  103. },
  104. done
  105. })
  106. } else {
  107. if (!this.$map) {
  108. this.$message({
  109. type: 'warning',
  110. message: '转换坐标失败,请关闭后重试'
  111. })
  112. return
  113. }
  114. this.$map.convertFrom([this.info.longitude, this.info.latitude], this.info.type, (status, result) => {
  115. console.log('coordinate', result)
  116. if (result.info === 'ok') {
  117. this.$emit('confirm', {
  118. value: {
  119. longitude: result.locations[0].lng,
  120. latitude: result.locations[0].lat
  121. },
  122. done
  123. })
  124. } else {
  125. this.$message({
  126. type: 'warning',
  127. message: '转换坐标失败,请稍后重试'
  128. })
  129. }
  130. })
  131. }
  132. }
  133. }
  134. }
  135. </script>