|
|
|
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 {
|
|
|
|
|
|
|
|
readonly c_get = "/Get";
|
|
|
|
readonly c_post = "/PostOrPut";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通用消息头
|
|
|
|
*/
|
|
|
|
headers = {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
};
|
|
|
|
|
|
|
|
//获取单位信息的api
|
|
|
|
baseUrl = 'api/Services/3D/BuildingBasicInfo';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 事态标绘(电子沙盘)的api
|
|
|
|
*/
|
|
|
|
markUrl = "api/Services/3D/Sandboxie";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private http: HttpClient
|
|
|
|
) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取三维信息
|
|
|
|
*/
|
|
|
|
getBuildingBasicInfos(name: string): Observable<string> {
|
|
|
|
return this.http.get<string>(this.baseUrl + this.c_get + '?name=' + name);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 保存三维信息
|
|
|
|
* @param name
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
postBuildingBasicInfos(name: string, data: any): Observable<any> {
|
|
|
|
let params = {
|
|
|
|
name: name,
|
|
|
|
}
|
|
|
|
|
|
|
|
let instance = this;
|
|
|
|
|
|
|
|
return this.http.post<any>(this.baseUrl + this.c_post, `'${JSON.stringify(data)}'`, { instance.headers, params })
|
|
|
|
.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 + this.c_get, { params: id }).pipe( //'?name='
|
|
|
|
catchError((err) => this.handleError(err))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 推送事态标绘的信息
|
|
|
|
* @param name
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
postMarkData(name: string, data: any): Observable<any> {
|
|
|
|
let params = {
|
|
|
|
name: name,
|
|
|
|
//content: JSON.stringify(data),
|
|
|
|
}
|
|
|
|
return this.http.post<any>(this.markUrl + this.c_post, JSON.stringify(data), { params })
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 服务器返回的结果
|
|
|
|
*/
|
|
|
|
class HttpResult {
|
|
|
|
|
|
|
|
}
|