峰峰执法平台简易案件程序板块 pad端
yang
2022-10-17 4107256a8d1fa9a2db0969122bfc760994b12421
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
<template>
  <el-dialog
    v-dialogDrag
    width="70%"
    :visible.sync="MapTrue"
    :before-close="cancelMap"
    append-to-body>
    <div class="bDiv">
    <baidu-map
      class="bm-view"
      :center="center"
      :zoom="zoom"
      :dragging="true"
      :scroll-wheel-zoom="true"
      @ready="handler"
      @click="getClickInfo"
      :key="timeKey"
    >
      <!--        //地理位置的搜索功能-->
      <!--        <bm-local-search-->
      <!--          :keyword="keyword"-->
      <!--          :auto-viewport="true"-->
      <!--          :location="location"-->
      <!--        ></bm-local-search>-->
      <!--        //缩放比例尺的展示-->
      <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
      <!--        //定位-->
      <!--        <bm-geolocation-->
      <!--          anchor="BMAP_ANCHOR_BOTTOM_RIGHT"-->
      <!--          :showAddressBar="true"-->
      <!--          :autoLocation="true"-->
      <!--        ></bm-geolocation>-->
      <!--        //添加一个小红点的,并将当前的经纬度写入数据中-->
      <!--        <bm-marker :position="{lng:center.lng, lat: center.lat}"></bm-marker>-->
      <bm-control :offset="{width: '10px', height: '10px'}">
        <bm-auto-complete v-if="autoComplete"  :sugStyle="{zIndex: 999999}" @confirm="handleConfirm" :key="`${timeKey}-BaiduMap`">
          <el-input v-model="keyword" type="text" clearable placeholder="请输入搜索关键字" class="serachinput"/>
        </bm-auto-complete>
      </bm-control>
      <bm-marker  :position="position"></bm-marker>
    </baidu-map>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submits">确 定</el-button>
      <el-button @click="cancelMap">取 消</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import moment from "moment";
export default {
  name: "index",
  props:['MapTrue'],
  data(){
    return{
      baidumapSwitch: false,
      autoComplete: true,
      center: {lng: 114.21148, lat: 36.41937},
      zoom: 14,
      // location: '北京市',
      keyword: '请输入搜索关键词',
      markers: [],
      position: {},
      timeKey: '',
      mapes:{
        center: {lng: 114.21148, lat: 36.41937 },
        cilty: {
          address: '石家庄',
          addressComponents: {
            city: '石家庄',
            district: '',
            province: '',
            street: '',
            streetNumber: '',
          }
        }
      },
      geocoder: {}, //解析器
    }
  },
  created () {
    this.timeKey = moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss')
  },
  methods:{
    handleConfirm ({ item }) {
      this.queryString = `${item.value.city}${item.value.district}${item.value.business}`
      this.querySearch(this.queryString)
      console.log(item,'item')
      this.mapes.cilty.address=this.queryString
      this.mapes.cilty.addressComponents= item
      // this.keyword = ''
      console.log(this.keyword,'keyWORD======')
      item = {}
    },
    querySearch (queryString, cb) {
      var that = this
      /* global BMap */
      var myGeo = new BMap.Geocoder()
      myGeo.getPoint(queryString, function (point) {
        if (point) {
          that.point = point
        }
      }, this.locationCity)
      setTimeout(function () {
        that.show(that.point.lng, that.point.lat)
      }, 500)
    },
    show (gpsLongitude, gpsLatitude) {
      if (gpsLongitude === undefined || (gpsLongitude === 0 && gpsLatitude === 0)) {
        gpsLongitude = 114.21148
        gpsLatitude = 36.41937
      }
      const position = { id: Math.random() * 40, lng: gpsLongitude, lat: gpsLatitude }
      this.center = { lng: gpsLongitude, lat: gpsLatitude }
      this.markers = []
      this.markers.push(position)
      this.position = position
      this.mapes.center=position
    },
    // 百度地图初始化(这个一定要!否则地图回加载不出来)
    handler ({ BMap, map }) {
        console.log({ BMap, map },'{ BMap, map }')
      //百度地图主题默认为白色,如上图所示
      //百度地图使用黑色主题
      //[百度地图更多主题](https://lbsyun.baidu.com/custom/list.htm)
      var mapStyle = { style: 'white' }
      map.setMapStyle(mapStyle)
      this.geocoder = new BMap.Geocoder()
    },
    // 点击获取到当前经纬度
    getClickInfo (e) {
        this.geocoder.getLocation(e.point,res => {
            console.log(res,'res=====')
            const position = { id: Math.random() * 40, lng: e.point.lng, lat: e.point.lat }
            // this.markers = []
            // this.markers.push(position)
            this.position = position
            this.keyword = res.address
            this.mapes.center=res.point
            this.mapes.cilty.address = res.address
        })
    },
    Mapinit(formMap){
      this.$nextTick(()=>{
        if (formMap.latitude==""||formMap==null){
          this.center={lng: 114.21148, lat: 36.41937 }
        }else {
          const a = formMap.latitude.split(",")
          this.center.lng = a[0]
          this.center.lat = a[1]
          this.position.lng=a[0]
          this.position.lng=a[1]
          // this.map.cilty.address = mapes.map
        }
      })
    },
    cancelMap(){
      this.keyword = ''
      this.$emit("cancelMap",false)
 
    },
  // 确定
    submits() {
      // console.log(this.map,'157665')
        console.log(this.mapes,'this.mapes')
      this.$emit("cancelMaps",this.mapes)
      this.cancelMap();
    },
  }
}
</script>
 
<style lang="scss" scoped>
.bDiv{
  height: 600px;
.bm-view {
  width: calc(100%);
  height: 600px;
  float: left;
}
}
 
</style>