-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from xieziyu/dev
Release v2.2.0
- Loading branch information
Showing
71 changed files
with
1,718 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
{ | ||
"name": "ngx-amap", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"author": "Xie, Ziyu", | ||
"license": "MIT", | ||
"keywords": [ | ||
"angular", | ||
"ng", | ||
"map", | ||
"amap" | ||
], | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/xieziyu/ngx-amap.git" | ||
}, | ||
"homepage": "https://xieziyu.github.io/ngx-amap", | ||
"bugs": "https://github.com/xieziyu/ngx-amap/issues", | ||
"peerDependencies": { | ||
"@angular/common": "^6.0.0-rc.0 || ^6.0.0", | ||
"@angular/core": "^6.0.0-rc.0 || ^6.0.0" | ||
"@angular/common": "^6.0.0-rc.0 || >=6.0.0", | ||
"@angular/core": "^6.0.0-rc.0 || >=6.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
projects/ngx-amap/src/services/amap-driving/amap-driving.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { AMapClass, Driving, LngLat } from '../../types/class'; | ||
import { DrivingOptions, ILngLat } from '../../types/interface'; | ||
import { LoggerService } from '../logger/logger.service'; | ||
import { PluginLoaderService } from '../plugin-loader/plugin-loader.service'; | ||
import { EventBinder } from '../../utils/event-binder'; | ||
import { DrivingResult } from '../../types/class/driving/driving-result'; | ||
|
||
declare const AMap: AMapClass; | ||
|
||
/** | ||
* 驾车路线规划服务 | ||
*/ | ||
@Injectable() | ||
export class AmapDrivingService { | ||
TAG = 'amap-driving'; | ||
|
||
private _plugin: Promise<void>; | ||
|
||
constructor(private logger: LoggerService, private plugins: PluginLoaderService) { | ||
} | ||
|
||
get loaded(): Promise<void> { | ||
if (!this._plugin) { | ||
this._plugin = this.plugins.load('AMap.Driving'); | ||
} | ||
|
||
return this._plugin; | ||
} | ||
|
||
of(opts?: DrivingOptions): Promise<AmapDrivingWrapper> { | ||
return this.loaded.then(() => new AmapDrivingWrapper(opts)); | ||
} | ||
} | ||
|
||
/** | ||
* AmapDrivingWrapper对象将高德原生的Driving对象提供的方法封装成Promise的实现,更方便回调 | ||
*/ | ||
export class AmapDrivingWrapper extends EventBinder { | ||
private _driving: Driving; | ||
|
||
constructor(opts?: DrivingOptions) { | ||
super(); | ||
this._driving = new AMap.Driving(opts); | ||
} | ||
|
||
get native(): Driving { | ||
return this._driving; | ||
} | ||
|
||
/** | ||
* 用于侦听Driving事件,返回可以被subscribe的Observable对象 | ||
* @param event | ||
* @returns | ||
*/ | ||
on(event: string): Observable<any> { | ||
return this.bindEvent<Driving>(this._driving, event); | ||
} | ||
|
||
search(origin: any[], destination?: ILngLat, opts?: any): Promise<{ status: string, result: string | DrivingResult }> { | ||
if (typeof destination !== 'undefined') { | ||
return new Promise(resolve => this._driving.search(origin, destination, opts, (status, result) => { | ||
resolve({ status, result }); | ||
})); | ||
} else { | ||
return new Promise(resolve => this._driving.search(origin, (status, result) => { | ||
resolve({ status, result }); | ||
})); | ||
} | ||
} | ||
|
||
setPolicy(policy: any) { | ||
this._driving.setPolicy(policy); | ||
} | ||
|
||
setAvoidPolygons(path: ILngLat[]) { | ||
this._driving.setAvoidPolygons(path); | ||
} | ||
|
||
setAvoidRoad(road: string) { | ||
this._driving.setAvoidRoad(road); | ||
} | ||
|
||
clearAvoidRoad() { | ||
this._driving.clearAvoidRoad(); | ||
} | ||
|
||
clearAvoidPolygons() { | ||
this._driving.clearAvoidPolygons(); | ||
} | ||
|
||
clear() { | ||
this._driving.clear(); | ||
} | ||
|
||
getAvoidPolygons(): LngLat[] { | ||
return this._driving.getAvoidPolygons(); | ||
} | ||
getAvoidRoad(): string { | ||
return this._driving.getAvoidRoad(); | ||
} | ||
|
||
setProvinceAndNumber(province: string, number: string) { | ||
this._driving.setProvinceAndNumber(province, number); | ||
} | ||
|
||
searchOnAMAP(obj: any) { | ||
this._driving.searchOnAMAP(obj); | ||
} | ||
} |
Oops, something went wrong.