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';