6
6
append-to-body
7
7
draggable
8
8
destroy-on-close >
9
- 经纬度:[{{ lnglat }}]
10
- <div id =" container" style =" width : 100 % ; height : 400px ; background : #fafafa " />
9
+ 经纬度:[{{ lng + ',' + lat }}]
10
+ <div id =" container" style =" height : 400px " />
11
11
</el-dialog >
12
12
</template >
13
13
@@ -19,39 +19,30 @@ const showDialog = ref(false);
19
19
const dialogTitle = ref (' ' );
20
20
const lng = ref (' ' );
21
21
const lat = ref (' ' );
22
- const lnglat = ref (' ' );
23
- const initMap = (coord , address ) => {
22
+ const initMap = (address ) => {
24
23
showDialog .value = true ;
25
24
dialogTitle .value = address ;
26
- coord = coord ? coord : ' 116.404,39.915' ;
27
- lnglat .value = coord ;
28
- if (coord ) {
29
- let arr = coord .split (' ,' );
30
- lng .value = arr [0 ];
31
- lat .value = arr [1 ];
32
- nextTick (() => {
33
- const map = new BMapGL .Map (' container' );
34
- map .enableScrollWheelZoom (true ); // 滚轮缩放
35
- map .addControl (new BMapGL .CityListControl ()); // 添加城市列表控件
36
- map .addControl (new BMapGL .ZoomControl ()); // 添加缩放控件
37
- // 创建地址解析器实例
38
- const myGeo = new BMapGL .Geocoder ();
39
- // 将地址解析结果显示在地图上,并调整地图视野
40
- myGeo .getPoint (address , (point ) => {
41
- console .log (' point' , point );
42
- if (point ) {
43
- map .centerAndZoom (point , 16 );
44
- // 标注
45
- map .addOverlay (new BMapGL .Marker (point , {title: address }));
46
- lng .value = point .lng ;
47
- lat .value = point .lat ;
48
- lnglat .value = lng .value + ' ,' + lat .value ;
49
- } else {
50
- ElMessage .error (' 您选择的地址没有解析到结果!' );
51
- }
52
- }, ' 北京市' );
53
- });
54
- }
25
+ nextTick (() => {
26
+ const map = new BMapGL .Map (' container' );
27
+ map .enableScrollWheelZoom (true ); // 滚轮缩放
28
+ map .addControl (new BMapGL .CityListControl ()); // 添加城市列表控件
29
+ map .addControl (new BMapGL .ZoomControl ()); // 添加缩放控件
30
+ // 创建地址解析器实例
31
+ const geocoder = new BMapGL .Geocoder ();
32
+ // 将地址解析结果显示在地图上,并调整地图视野
33
+ geocoder .getPoint (address , (point ) => {
34
+ console .log (' point' , point );
35
+ if (point ) {
36
+ lng .value = point .lng ;
37
+ lat .value = point .lat ;
38
+ map .centerAndZoom (point , 16 );
39
+ // 标注
40
+ map .addOverlay (new BMapGL .Marker (point , {title: address }));
41
+ } else {
42
+ ElMessage .error (' 您选择的地址没有解析到结果!' );
43
+ }
44
+ }, ' 北京市' );
45
+ });
55
46
};
56
47
57
48
defineExpose ({initMap });
0 commit comments