This commit is contained in:
Taric Xin
2022-03-04 14:56:56 +08:00
parent 0270e41c4a
commit 07553918d0
3 changed files with 36 additions and 21 deletions

View File

@ -1,5 +1,5 @@
import AMapLoader from '@amap/amap-jsapi-loader';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { amapConf } from '@conf/amap.config';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { throwError } from 'rxjs';
@ -27,7 +27,10 @@ export class AmapPoiPickerComponent implements OnInit {
infoWindow: any;
geocoder: any;
constructor(private modalRef: NzModalRef, private service: AmapService) {}
@Input()
selectedAddress!: string;
constructor(private modalRef: NzModalRef, private service: AmapService, private cdr: ChangeDetectorRef) {}
ngOnInit(): void {
this.mapInit();
// this.PoiPicker();
@ -77,6 +80,8 @@ export class AmapPoiPickerComponent implements OnInit {
// 地图创建成功
this.aMap.on('complete', () => {
console.log('地图创建成功');
this.cdr.detectChanges();
this.poiPickerReady(poiPicker);
});
@ -113,12 +118,21 @@ export class AmapPoiPickerComponent implements OnInit {
radius: 1000 //范围默认500
});
// 获取当前定位
this.service.getCurrentPosition().subscribe(res => {
if (res) {
this.selectedPOI(res.position);
}
});
if (this.selectedAddress) {
this.geocoder.getLocation(this.selectedAddress, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
// result中对应详细地理坐标信息
this.selectedPOI(result.geocodes?.[0].location);
}
});
} else {
// 获取当前定位
this.service.getCurrentPosition().subscribe(res => {
if (res) {
this.selectedPOI(res.position);
}
});
}
//选取了某个POI
poiPicker.on('poiPicked', (poiResult: any) => {