This commit is contained in:
Taric Xin
2022-04-12 20:56:58 +08:00
parent 846959b798
commit f850722613
8 changed files with 68 additions and 54 deletions

View File

@ -71,9 +71,10 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy
this.setData(this.pathList);
if (changes.mapList?.currentValue.length > 0) {
this.setPathIndex(this.selectedIndex);
this.getPoiByPositon('起', this.mapList[0]?.lnglat, '时间:' + this.amapService.formatTime(this.mapList[0]?.time));
this.getPoiByPositon('起', 'blue', this.mapList[0]?.lnglat, '时间:' + this.amapService.formatTime(this.mapList[0]?.time));
this.getPoiByPositon(
'终',
'red',
this.mapList[this.mapList?.length - 1]?.lnglat,
'时间:' + this.amapService.formatTime(this.mapList[this.mapList?.length - 1]?.time)
);
@ -82,8 +83,6 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy
}
// 标点列表变更: 更新标点数据, 绘画标点
if (changes?.pois?.currentValue) {
console.log(changes?.pois?.currentValue);
this._pois = changes?.pois?.currentValue;
if (this?.markerList && this._pois.length > 0) {
this.markerList.render(this._pois);
@ -156,9 +155,10 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy
if (this.pathList.length > 0) {
this.setPathIndex(this.selectedIndex);
this.getPoiByPositon('起', this.mapList[0]?.lnglat, '时间:' + this.amapService.formatTime(this.mapList[0]?.time));
this.getPoiByPositon('起', 'blue', this.mapList[0]?.lnglat, '时间:' + this.amapService.formatTime(this.mapList[0]?.time));
this.getPoiByPositon(
'终',
'red',
this.mapList[this.mapList?.length - 1]?.lnglat,
'时间:' + this.amapService.formatTime(this.mapList[this.mapList?.length - 1]?.time)
);
@ -176,6 +176,9 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy
content: `
<label style="font-weight: bold;">${result.regeocode.formattedAddress}<label/><br/>
<label style="font-weight: 400;">车速: ${info.pathData.points[info.pointIndex].name}<label/><br/>
<label style="font-weight: 400;">东经: ${info.pathData.points[info.pointIndex].lnglat?.[0]}, 北纬:${
info.pathData.points[info.pointIndex].lnglat?.[1]
}<label/><br/>
<label style="font-weight: 400;">时间: ${this.amapService.formatTime(info.pathData.points[info.pointIndex].time)}<label/>
`
});
@ -289,14 +292,11 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy
}
/** 根据标点经纬度获取地址信息 */
getPoiByPositon(label: string, position: string[], time: string) {
getPoiByPositon(label: string, color: string, position: string[], time: string) {
this.geocoder.getAddress(position, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
// result中对应详细地理坐标信息
this._pois = [
...this.pois,
{ markerLabel: label, color: 'red', position, title: result.regeocode.formattedAddress, time }
];
this._pois = [...this._pois, { markerLabel: label, color: color, position, title: result.regeocode.formattedAddress, time }];
if (this.markerList) {
this.markerList.render(this._pois);
}