|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
|
import { Component, EventEmitter, NgZone, OnInit, Output } from '@angular/core'; |
|
|
|
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; |
|
|
|
|
import { ActivatedRoute } from '@angular/router'; |
|
|
|
|
declare var AMap: any; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@ -9,14 +11,75 @@ declare var AMap: any;
|
|
|
|
|
}) |
|
|
|
|
export class RouterGISComponent implements OnInit { |
|
|
|
|
@Output() onCustomEvent: EventEmitter<any> = new EventEmitter();//创建实力
|
|
|
|
|
constructor(public _ngZone:NgZone,public snackBar: MatSnackBar,) { } |
|
|
|
|
constructor(public _ngZone:NgZone,public snackBar: MatSnackBar,private http:HttpClient,private route:ActivatedRoute,) { } |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getCompanyData() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngAfterViewInit(): void { |
|
|
|
|
window.setTimeout(()=>{ |
|
|
|
|
this.mapInit() |
|
|
|
|
},0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取单位 信息
|
|
|
|
|
getCompanyData () { |
|
|
|
|
this.http.get(`/api/Companies/${this.route.snapshot.queryParams.id}`).subscribe((data:any)=>{ |
|
|
|
|
if (data.driveRouteStartPoint && data.driveRouteStartPoint.x && data.driveRouteStartPoint.y && data.driveRouteStartName) { //开始坐标 名称
|
|
|
|
|
this.routeStart = data.driveRouteStartName |
|
|
|
|
this.startCoordinate = [data.driveRouteStartPoint.x,data.driveRouteStartPoint.y] |
|
|
|
|
} |
|
|
|
|
if (data.driveRouteEndPoint && data.driveRouteEndPoint.x && data.driveRouteEndPoint.y && data.driveRouteEndName) { //结束坐标 名称
|
|
|
|
|
this.routeEnd = data.driveRouteEndName |
|
|
|
|
this.endCoordinate = [data.driveRouteEndPoint.x,data.driveRouteEndPoint.y] |
|
|
|
|
} else if (data.location && data.location.x && data.location.y) { |
|
|
|
|
this.routeEnd = data.name |
|
|
|
|
this.endCoordinate = [data.location.x,data.location.y] |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//保存 路线
|
|
|
|
|
submitRouter () { |
|
|
|
|
if (this.startCoordinate && this.endCoordinate && this.routeStart && this.routeEnd) { |
|
|
|
|
let start = {x:null, y:null} |
|
|
|
|
let end = {x:null, y:null} |
|
|
|
|
if (this.startCoordinate instanceof Array) { |
|
|
|
|
start.x = this.startCoordinate[0] |
|
|
|
|
start.y = this.startCoordinate[1] |
|
|
|
|
} else { |
|
|
|
|
start.x = this.startCoordinate.lng |
|
|
|
|
start.y = this.startCoordinate.lat |
|
|
|
|
} |
|
|
|
|
if (this.endCoordinate instanceof Array) { |
|
|
|
|
end.x = this.endCoordinate[0] |
|
|
|
|
end.y = this.endCoordinate[1] |
|
|
|
|
} else { |
|
|
|
|
end.x = this.endCoordinate.lng |
|
|
|
|
end.y = this.endCoordinate.lat |
|
|
|
|
} |
|
|
|
|
let params = { |
|
|
|
|
id: this.route.snapshot.queryParams.id, |
|
|
|
|
driveRouteStartPoint: start, |
|
|
|
|
driveRouteStartName: this.routeStart, |
|
|
|
|
driveRouteEndPoint: end, |
|
|
|
|
driveRouteEndName: this.routeEnd, |
|
|
|
|
} |
|
|
|
|
this.http.put(`/api/Companies/${this.route.snapshot.queryParams.id}`,params).subscribe(data=>{ |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('保存成功','确定',config); |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请先规划路线','确定',config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//地图初始化
|
|
|
|
|
mapInit () { |
|
|
|
|
let that = this |
|
|
|
@ -31,6 +94,9 @@ export class RouterGISComponent implements OnInit {
|
|
|
|
|
layers:[layer], //当只想显示标准图层时layers属性可缺省,
|
|
|
|
|
}); |
|
|
|
|
that.map.setCity('上海市'); |
|
|
|
|
AMap.plugin('AMap.Driving', function() { |
|
|
|
|
that.startCoordinate && that.endCoordinate? that.queryGISRoute() : null |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
map:any; //地图实例
|
|
|
|
@ -41,6 +107,9 @@ export class RouterGISComponent implements OnInit {
|
|
|
|
|
timeout:any; //延时器
|
|
|
|
|
routeGIS:any; //查询结果 规划路线
|
|
|
|
|
selectType:boolean = true; //路线选择 推荐方案/躲避用拥堵
|
|
|
|
|
routes:any = { distance: 0, time: 0, steps: [], };//导航查询结果 路线规划
|
|
|
|
|
startCoordinate:any//开始坐标
|
|
|
|
|
endCoordinate:any//结束坐标
|
|
|
|
|
|
|
|
|
|
//输入框 输入事件
|
|
|
|
|
routeChange (e) { |
|
|
|
@ -56,7 +125,6 @@ export class RouterGISComponent implements OnInit {
|
|
|
|
|
var autoComplete = new AMap.Autocomplete(autoOptions); |
|
|
|
|
autoComplete.search(keywords, function(status, result) { |
|
|
|
|
if (result && result.tips && result.tips.length) { //搜索到数据时
|
|
|
|
|
|
|
|
|
|
that._ngZone.run(()=>{
|
|
|
|
|
if(e == 0){ |
|
|
|
|
that.routeStartList = result.tips |
|
|
|
@ -113,10 +181,6 @@ export class RouterGISComponent implements OnInit {
|
|
|
|
|
this.endCoordinate = data2 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
routes:any = { distance: 0, time: 0, steps: [], };//导航查询结果 路线规划
|
|
|
|
|
startCoordinate:any//开始坐标
|
|
|
|
|
endCoordinate:any//结束坐标
|
|
|
|
|
|
|
|
|
|
//导航查询
|
|
|
|
|
queryGISRoute () { |
|
|
|
|
if (this.startCoordinate && this.endCoordinate) { |
|
|
|
|