From cb419fcabee7789d41c173807943668f62201b2b Mon Sep 17 00:00:00 2001 From: SHAOJIAHAO <55341701@qq.com> Date: Thu, 28 Jan 2021 16:02:25 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=E4=BF=AE=E6=94=B9=E8=B7=AF?= =?UTF-8?q?=E7=BA=BF=E6=9F=A5=E8=AF=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gis-labeling/gis-labeling.component.ts | 45 ++++++++++++++----- .../router-gis/router-gis.component.ts | 38 ++++++++++++---- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/app/gis-management/gis-labeling/gis-labeling.component.ts b/src/app/gis-management/gis-labeling/gis-labeling.component.ts index 5fc2e49..86de6b8 100644 --- a/src/app/gis-management/gis-labeling/gis-labeling.component.ts +++ b/src/app/gis-management/gis-labeling/gis-labeling.component.ts @@ -915,12 +915,19 @@ export class GisLabelingComponent 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){ + if(e == 0){//起点 that.routeStartList = result.tips - that.startCoordinate = new AMap.LngLat(result.tips[0].location.lng, result.tips[0].location.lat) - }else{ + if(result.tips.length != 0){ + for (let index = 0; index < result.tips.length; index++) { + const element = result.tips[index]; + if(element.location){ + that.startCoordinate = new AMap.LngLat(element.location.lng, element.location.lat) + return + } + } + } + }else{//终点 that.routeEndList = result.tips that.endCoordinate = new AMap.LngLat(result.tips[0].location.lng, result.tips[0].location.lat) } @@ -986,13 +993,28 @@ export class GisLabelingComponent implements OnInit { this.routeGIS = new AMap.Driving({ map: this.map, }); - this.routeGIS.search(this.startCoordinate,this.endCoordinate, - function(status, result) { - if (status === 'complete') { - that.routes = result.routes[0] - } else { alert('获取驾驶规划路线失败') } - } - ); + if(!this.startCoordinate){ + let config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open('未查询到起点坐标信息,请输入有效地址','确定',config); + return + }else if(!this.startCoordinate){ + let config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open('未查询到终点坐标信息,请输入有效地址','确定',config); + return + }else{ + this.routeGIS.search(this.startCoordinate,this.endCoordinate, + function(status, result) { + if (status === 'complete') { + that.routes = result.routes[0] + } else { alert('获取驾驶规划路线失败') } + } + ); + } + } //切换 导航模式 推荐方案/躲避拥堵 @@ -1006,6 +1028,7 @@ export class GisLabelingComponent implements OnInit { policy: e==true? AMap.DrivingPolicy.LEAST_TIME : AMap.DrivingPolicy.REAL_TRAFFIC }); // 根据起终点名称规划驾车导航路线 + this.routeGIS.search(this.startCoordinate,this.endCoordinate, function(status, result) { if (status === 'complete') { diff --git a/src/app/key-unit/router-gis/router-gis.component.ts b/src/app/key-unit/router-gis/router-gis.component.ts index 3c50e52..932f40c 100644 --- a/src/app/key-unit/router-gis/router-gis.component.ts +++ b/src/app/key-unit/router-gis/router-gis.component.ts @@ -60,7 +60,15 @@ export class RouterGISComponent implements OnInit { that._ngZone.run(()=>{ if(e == 0){ that.routeStartList = result.tips - that.startCoordinate = new AMap.LngLat(result.tips[0].location.lng, result.tips[0].location.lat) + if(result.tips.length != 0){ + for (let index = 0; index < result.tips.length; index++) { + const element = result.tips[index]; + if(element.location){ + that.startCoordinate = new AMap.LngLat(element.location.lng, element.location.lat) + return + } + } + } }else{ that.routeEndList = result.tips that.endCoordinate = new AMap.LngLat(result.tips[0].location.lng, result.tips[0].location.lat) @@ -127,13 +135,27 @@ export class RouterGISComponent implements OnInit { this.routeGIS = new AMap.Driving({ map: this.map, }); - this.routeGIS.search(this.startCoordinate,this.endCoordinate, - function(status, result) { - if (status === 'complete') { - that.routes = result.routes[0] - } else { alert('获取驾驶规划路线失败') } - } - ); + if(!this.startCoordinate){ + let config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open('未查询到起点坐标信息,请输入有效地址','确定',config); + return + }else if(!this.startCoordinate){ + let config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open('未查询到终点坐标信息,请输入有效地址','确定',config); + return + }else{ + this.routeGIS.search(this.startCoordinate,this.endCoordinate, + function(status, result) { + if (status === 'complete') { + that.routes = result.routes[0] + } else { alert('获取驾驶规划路线失败') } + } + ); + } } else { const config = new MatSnackBarConfig(); config.verticalPosition = 'top';