You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
4 years ago
|
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/v2/BuildingBasicInfos';
|
||
|
|
||
|
/**
|
||
|
* 事态标绘(电子沙盘)的api
|
||
|
*/
|
||
|
markUrl = "api/v2/Sandboxie";
|
||
|
|
||
|
|
||
|
constructor(
|
||
|
private http: HttpClient
|
||
|
) { }
|
||
|
|
||
|
/**
|
||
|
* 获取三维信息
|
||
|
*/
|
||
|
getBuildingBasicInfos(name: string): Observable<string> {
|
||
|
return this.http.get<string>(this.baseUrl + '?name=' + name);
|
||
|
}
|
||
|
/**
|
||
|
* 保存三维信息
|
||
|
* @param name
|
||
|
* @param data
|
||
|
*/
|
||
|
postBuildingBasicInfos(name: string, data: any): Observable<any> {
|
||
|
return this.http.post<any>(this.baseUrl + '?name=' + name, data)
|
||
|
.pipe(
|
||
|
catchError((err) => this.handleError(err))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取事态标绘的信息
|
||
|
* @param name
|
||
|
*/
|
||
|
getMarkData(name: string): Observable<string> {
|
||
|
// name = "bb";
|
||
|
let id = { "name": name };
|
||
|
return this.http.get<string>(this.markUrl, { params: id }).pipe( //'?name='
|
||
|
catchError((err) => this.handleError(err))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 推送事态标绘的信息
|
||
|
* @param name
|
||
|
* @param data
|
||
|
*/
|
||
|
postMarkData(name: string, data: any): Observable<any> {
|
||
|
return this.http.post<any>(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);
|
||
|
}
|
||
|
}
|