guoshipeng
2023-07-06 6b2741434cb2be708a869505440f9f4efc8e6fd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <a-modal
    title="坐标选择"
    destroyOnClose
    :visible="true"
    @ok="addLonAndLat"
    @cancel="handleMapCancel"
    okText="确定"
    class="modalStyle"
  >
    <div>
      <p>
        <span>地址:</span
        ><a-input
          v-model="keyword"
          style="display: inline; width: 160px; height: 26px"
        />
        <span style="margin-left: 25px">经度:</span
        ><a-input
          v-model="clickPoint.lng"
          style="display: inline; width: 160px; height: 26px"
        />
        <span style="margin-left: 25px">纬度:</span
        ><a-input
          v-model="clickPoint.lat"
          style="display: inline; width: 160px; height: 26px"
        />
      </p>
      <!--      :scroll-wheel-zoom="true"-->
      <baidu-map
        :center="center"
        :zoom="zoom"
        @ready="handler"
        @click="mapClick"
        :scroll-wheel-zoom="true"
        style="height: 400px; width: 100%"
      >
        <bm-control>
          <bm-local-search
            :keyword="keyword"
            :auto-viewport="true"
            style="display: none"
          ></bm-local-search>
          <bm-marker
            :position="{ lng: clickPoint.lng, lat: clickPoint.lat }"
            :dragging="true"
            animation="BMAP_ANIMATION_BOUNCE"
          >
          </bm-marker>
        </bm-control>
      </baidu-map>
    </div>
  </a-modal>
</template>
 
<script lang="tsx">
import {
  Component,
  Prop,
  Vue,
  Emit, Watch,
} from 'vue-property-decorator';
import any = jasmine.any;
import { get, post } from "@/util/request";
 
 
@Component({
})
export default class PickCoordinate extends Vue {
  private center: any = {
    lng: 120.726838,
    lat: 31.3421
  }
  @Prop({
    type: String,
    default: ''
  })
  private lnglat!: string
 
  @Prop({
    type: String,
    default: ''
  })
  private typeOperation!: string
 
  private keyword: string = ''
  private zoom = 3
 
  @Watch('clickPoint', {deep: true})
  private monitorMapFlag(newVal: any, oldVal: any) {
    this.center.lng = newVal.lng
    this.center.lat = newVal.lat
  }
 
  @Watch('lnglat', {deep: true, immediate: true})
  private lnglatWatch(newVal: any, oldVal: any) {
    console.log('------------');
    console.log(newVal);
    // this.center.lng = newVal.lng
    // this.center.lat = newVal.lat
  }
  private created() {
 
  }
 
 
 
 
  // 初始化地图
  private handler({BMap, map}) {
    this.center.lng =  this.typeOperation === 'add' ? '120.726838' : this.lnglat.split(',')[1]
    this.center.lat =  this.typeOperation === 'add' ? '31.3421' : this.lnglat.split(',')[0]
    this.zoom = 19
 
  }
  // 初始定位到星虹国际
  private clickPoint: any = this.lnglat === '' ?  {
        lng: ' 120.726838',
        lat: ' 31.3421'
      } : {
    lng: this.lnglat.split(',')[1],
    lat: this.lnglat.split(',')[0]
  }
 
  private mapClick(e: any) {
    const { lng, lat } = e.point
    this.clickPoint.lng = lng
    this.clickPoint.lat = lat
  }
 
  private handleMapCancel() {
    this.keyword = ''
    this.flagSend(false)
  }
 
  private addLonAndLat() {
    if (this.typeOperation === 'add') {
      this.sendLonLat(this.clickPoint)
    } else {
      this.editLonLat(this.clickPoint)
    }
 
    this.flagSend(false)
  }
 
  @Emit('mapFlag1')
  private flagSend(flag: boolean) {
    return flag;
  }
 
  @Emit('sendLonLat')
  private sendLonLat(lonLat: any) {
    return lonLat;
  }
 
  @Emit('editLonLat')
  private editLonLat(lonLat: any) {
    return lonLat;
  }
}
</script>
 
<style  lang="less">
.modalStyle {
  .ant-modal {
    margin-left: 25%;
  }
  .ant-modal-content {
    width: 800px;
  }
}
.BMap_cpyCtrl,
.anchorBL {
  display: none;
}
</style>