郑永安
2023-06-19 6ae336af4670a425ae8892aacda560ec2147d8a7
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
<template>
  <div class="app-container">
    <baidu-map class="map-container" v-bind="mapOptions" @click="mapMoveEnd">
      <bm-control ::offset="{ width: '30px', height: '10px' }">
        <bm-auto-complete v-model="mapKeyword" :sugStyle="{ zIndex: 100000 }">
          <el-row :gutter="2">
            <el-col :span="22">
              <el-input v-model="mapKeyword" placeholder="请输入搜索关键字"></el-input>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" @click="mapSearch">确定</el-button>
            </el-col>
          </el-row>
        </bm-auto-complete>
      </bm-control>
    </baidu-map>
  </div>
</template>
<script>
import { BaiduMap, BmControl, BmAutoComplete } from 'vue-baidu-map/components';
 
export default {
  components: { BaiduMap, BmControl, BmAutoComplete },
  props: {},
  data() {
    return {
      mapOptions: {
        ak: '42xN1Fhp3VCKvKQRprbfsR48ZbvDbOD0',
        center: { lng: 119.691445, lat: 31.512202 },
        scrollWheelZoom: true,
        zoom: 16
      },
      mapKeyword: '宜兴市'
    };
  },
  methods: {
    mapSearch() {
      let geoCoder = new BMap.Geocoder();
      /* 获取位置对应的坐标 */
      geoCoder.getPoint(this.mapKeyword, point => {
        this.$emit('locationChanged', { searchConfirmed: true, lng: point.lng, lat: point.lat });
      });
    },
    mapMoveEnd(e) {
      const { lng, lat } = e.point;
      this.$emit('locationChanged', {
        lng,
        lat
      });
    }
  }
};
</script>
 
<style lang="scss" scoped>
.map-container {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
</style>