zhouwenxuan
2024-02-27 48b9dbfb66cf8bf6c83dac0f9365ba71d3181fba
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
<template>
  <el-dialog
      v-model="state.mapLocationVisible"
      append-to-body
      :close-on-click-modal="false"
      width="75%"
      :title="state.title"
  >
    <div class="mapLocation_head">
      <div>
        <el-alert
            title="点击地点获取经纬度信息"
            type="info"
            :closable="false"
        >
        </el-alert>
      </div>
      <div class="mapLocation_latlng">
        <span>经度:</span>
        <el-input class="mapLocation_latlng_input" id="lng" v-model="state.longitude"></el-input>
      </div>
      <div class="mapLocation_latlng">
        <span>纬度:</span>
        <el-input class="mapLocation_latlng_input" id="lat" v-model="state.latitude"></el-input>
      </div>
    </div>
    <div class="mapLocation_body">
      <baidu-map class="map" ak="BkZdiHBj9aGrMdVFM48r2njNiMzsekga" v="3.0" type="API" :center="state.center" :zoom="state.zoom" scroll-wheel-zoom @ready="initMap" @click="getPosition">
        <div style="position: absolute;z-index: 999;margin-top: -495px">
          <label>搜索:<input v-model="state.keyword"></label>
          <bm-local-search
              :keyword="state.keyword"
              :auto-viewport="true"
              location="新疆"
              :pageCapacity="3"
          ></bm-local-search>
        </div>
 
        <bm-marker :position="{lng: state.longitude, lat: state.latitude}" :dragging="true" animation="BMAP_ANIMATION_BOUNCE">
          <bm-label content="选择地点" :labelStyle="{color: 'red', fontSize : '24px'}" :offset="{width: -35, height: 30}"/>
        </bm-marker>
 
 
      </baidu-map>
    </div>
    <div  align="right" style="margin-top: 10px">
      <el-button @click="state.mapLocationVisible = false">取消</el-button>
      <el-button type="primary" @click="submitLatLng()">确认</el-button>
    </div>
  </el-dialog>
</template>
 
<script setup>
import {ref, onMounted, reactive, toRefs, defineComponent,defineExpose,defineEmits} from 'vue';
import { BaiduMap,BmMarker,BmLocalSearch } from 'vue-baidu-map-3x'
const state = reactive({
  title: '',
  longitude: '',
  latitude: '',
  mapLocationVisible: false,
  zoom: 7,
  center: {
    lng: '87.62472586600425',
    lat: '43.82743324701045'
  },
  keyword:'',
  location: ''
})
 
const emit = defineEmits(['giveLatLng'])
 
onMounted(() => {
  // ...(mounted钩子中的代码不变)
});
const map = reactive({})
 
const getPosition = ({type, target, point, pixel, overlay})=>{
  state.longitude = point.lng
  state.latitude = point.lat
}
 
const openMapLocation=(longitude,latitude)=>{
  state.longitude = longitude
  state.latitude = latitude
  state.zoom = 13
  state.center = {
    lng: longitude,
    lat: latitude
  }
  state.mapLocationVisible = true
}
 
const submitLatLng=()=>{
  state.mapLocationVisible = false
  emit('giveLatLng',state.longitude,state.latitude);
}
 
const initMap=()=>{
 
}
 
defineExpose({
  openMapLocation
})
</script>
 
<style lang="scss" scoped>
.map {
  width: 100%;
  height: 500px;
 
  :deep(.BMap_cpyCtrl){
    display: none!important;
    visibility: hidden!important;
  }
 
  :deep(.anchorBL) {
    display: none!important;
    visibility: hidden!important;
  }
}
.mapLocation_head{
  width:100%;
  height:100px;
}
.mapLocation_body{
  width:100%;
  height:500px
}
.mapLocation_latlng{
  padding-top:10px;
  display:inline-block;
  margin-right: 20px;
}
.mapLocation_latlng_input{
  width:250px;
}
</style>