This commit is contained in:
wangshiming
2021-12-15 13:19:03 +08:00
parent 0201624265
commit 5f7df7339a
23 changed files with 1159 additions and 105 deletions

View File

@ -1,9 +1,31 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
declare var AMap: any;
@Injectable({
providedIn: 'root'
})
export class AmapService {
constructor() {}
public length = 0;
public time = 0;
constructor() { }
sub = new Subject<any>();
//计算路径驾车最优路线的长度与所需时间
drivingCompute(starts: any[], ends: any[]): Observable<any> {
AMap.plugin('AMap.Driving', () => {
let driving = new AMap.Driving({
// 驾车路线规划策略AMap.DrivingPolicy.LEAST_TIME是最快捷模式
policy: AMap.DrivingPolicy.LEAST_TIME
});
const points = starts.concat(ends).map(item => {
return { keyword: item.address, city: item.city };
});
driving.search(points, (status: any, result: any) => {
const repData = { distance: (result.routes[0].distance / 1000).toFixed(2), time: (result.routes[0].time / 60 / 60).toFixed(2) };
this.sub.next(repData);
});
});
return this.sub;
}
}