guoshipeng
2023-08-14 756e81d6e35231521f0431e292edb22aed65e403
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
  <a-modal
    title="坐标选择"
    destroyOnClose
    :visible="true"
    @ok="addLonAndLat"
    @cancel="handleMapCancel"
    okText="确定"
    class="modalStyle"
  >
    <div>
      <div style="display: flex">
        <div style="display: flex; width: 300px">
          <div>地址:</div>
            <a-input
            placeholder="关键字搜索"
            id="tipinput"
            style="width: 160px; height: 26px"
          ></a-input>
          <!-- <a-input
            v-model="input"
            placeholder="关键字搜索"
            id="tipinput"
            style="width: 160px; height: 26px"
            @change="searchMap"
          ></a-input> -->
          <!-- <a-button
            size="small"
            type="primary"
            @click="searchMap"
            style="margin-left: 10px"
            >搜索</a-button
          > -->
 
          <!-- <el-amap-search-box
            :search-option="searchOption"
            :on-search-result="selectPoi"
            style="width: 200px; height: 26px; margin-left: 10px;border;"
          /> -->
          <!-- <a-input style="width: 160px; height: 26px" @focus="selectPoi" /> -->
        </div>
        <div>
          <span style="margin-left: 25px">经度:</span
          ><a-input
            v-model="clickPoint[0]"
            style="display: inline; width: 160px; height: 26px"
          />
        </div>
        <div>
          <span style="margin-left: 25px">纬度:</span
          ><a-input
            v-model="clickPoint[1]"
            style="display: inline; width: 160px; height: 26px"
          />
        </div>
      </div>
      <el-amap
        ref="map"
        :center="clickPoint"
        :events="{ click: mapClick }"
        :zoom="zoom"
        :scroll-wheel-zoom="true"
        style="height: 400px; width: 100%; margin-top: 20px"
      >
        <el-amap-marker
          :position="clickPoint"
          animation="AMAP_ANIMATION_BOUNCE"
          :dragging="true"
        ></el-amap-marker>
      </el-amap>
      <!--      :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 = [
     120.726838,
     31.3421
  ]
  @Prop({
    type: String,
    default: ''
  })
  private lnglat!: string
 
  @Prop({
    type: String,
    default: ''
  })
  private typeOperation!: string
 
  private keyword: string = ''
  private zoom = 19
  private searchOption:any={
      city: '全国',
      citylimit: false
  }
  @Watch('clickPoint', {deep: true, immediate: true},)
  private monitorMapFlag(newVal: any, oldVal: any) {
    console.log(newVal,'newVal');
    this.center= [newVal.lng,newVal.lat]
  }
  private num1:any=1
 
  @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() {
    console.log(this.clickPoint,'clickPoint');
  }
 
  // 初始化地图
  // 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 selectPoi(e){
    console.log(e);
    let poi = e
      if (poi.length > 0) {
         this.clickPoint = [poi[0].lng, poi[0].lat]
         }
  }
  private input:any=''
  private mark:any=''
  private searchMap(){
     var autoOptions = {
        input: "tipinput"
    };
    var auto = new AMap.AutoComplete(autoOptions);
    const placeSearch = new AMap.PlaceSearch(this.input);
    console.log(window);
     auto.on("select", select);//注册监听,当选中某条记录时会触发
        function select(e) {
          console.log(e.poi.adcode);
            placeSearch.setCity(e.poi.adcode);
            placeSearch.search(e.poi.name);  //关键字查询查询
        }
  
  // 关键字查询
  // console.log(this.input);
  //  placeSearch.search(this.input, (status, result) => {
  //   // 查询成功时,result即对应匹配的POI信息
   
  //   console.log(result);//打印这句话报错,第一遍可以打印出来,第二遍就会报错
  // });
  // // 监听选中节点事件
  // AMap.event.addListener(placeSearch, "selectChanged", (SelectChangeEvent) => {
  //   // 获取节点信息自行处理逻辑代码
  //   this.mark = SelectChangeEvent.selected.data;
  //   console.log(SelectChangeEvent.selected.data,'苏轼');
  // }); 
 
  }
  // 初始定位到星虹国际
  private clickPoint: any = this.lnglat === '' ?  [
          120.720262,
         31.335757
      ] : [
     this.lnglat.split(',')[1],
     this.lnglat.split(',')[0]
  ]
 
  private mapClick(e: any) {
    const { lng, lat } = e.lnglat 
    this.clickPoint=[ lng, lat]
    this.$forceUpdate()
    // console.log(this.clickPoint);
  }
 
  private handleMapCancel() {
    this.keyword = ''
    this.flagSend(false)
  }
 
  private addLonAndLat() {
    if (this.typeOperation === 'add') {
      console.log('add');
      this.sendLonLat(this.clickPoint)
    } else {
      console.log('upa');
      this.editLonLat(this.clickPoint)
    }
    this.flagSend(false)
  }
 
  @Emit('mapFlag1')
  private flagSend(flag: boolean) {
    return flag;
  }
 
  @Emit('sendLonLat')
  private sendLonLat(lonLat: any) {
    console.log(lonLat,'jia');
    return lonLat;
  }
 
  @Emit('editLonLat')
  private editLonLat(lonLat: any) {
    console.log(lonLat,'gai');
    return lonLat;
  }
}
</script>
 
<style  lang="less" scoped>
.modalStyle {
  .ant-modal {
    margin-left: 25%;
  }
  .ant-modal-content {
    width: 800px;
  }
}
.BMap_cpyCtrl,
.anchorBL {
  display: none;
}
/* 去除高德地图的logo */
/deep/.amap-logo {
  display: none;
  opacity: 0 !important;
}
/deep/.amap-copyright {
  opacity: 0;
}
.amap-sug-result {
  position: absolute;
  z-index: 9999 !important;;
  background-color: #fefefe;
  border: 1px solid #d1d1d1;
  bottom: auto;
}
</style>