import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, throwError } from 'rxjs'; import { catchError, retry } from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class BuildingBasicInfosService { //获取单位信息的api baseUrl = 'api/Services/3D/BuildingBasicInfo'; /** * 事态标绘(电子沙盘)的api */ markUrl = "api/Services/3D/Sandboxie"; constructor( private http: HttpClient ) { } /** * 获取三维信息 */ getBuildingBasicInfos(name: string): Observable { return this.http.get(this.baseUrl + '?name=' + name); } /** * 保存三维信息 * @param name * @param data */ postBuildingBasicInfos(name: string, data: any): Observable { return this.http.post(this.baseUrl + '?name=' + name, data) .pipe( catchError((err) => this.handleError(err)) ); } /** * 获取事态标绘的信息 * @param name */ getMarkData(name: string): Observable { // name = "bb"; let id = { "name": name }; return this.http.get(this.markUrl, { params: id }).pipe( //'?name=' catchError((err) => this.handleError(err)) ); } /** * 推送事态标绘的信息 * @param name * @param data */ postMarkData(name: string, data: any): Observable { return this.http.post(this.markUrl + '?name=' + name, data) .pipe( catchError((err) => this.handleError(err)) ); } private handleError(error: HttpErrorResponse) { if (error.error instanceof ErrorEvent) { // A client-side or network error occurred. Handle it accordingly. console.error('An error occurred:', error.error.message); } else { // The backend returned an unsuccessful response code. // The response body may contain clues as to what went wrong. if (error.status == 404) { console.log("404===" + error.error); } else { console.error( error + `Backend returned code ${error.status}, ` + `body was: ${error.error}`); } } // Return an observable with a user-facing error message. return throwError( error); } }