获取text文件接口
isStyleExist(areacode: number, name: string, filename: string): Promise<boolean> {
let url = `${this.url}/style/${name}/${areacode}/${filename}`;
let options: Object = {
responseType: 'text'
};
return this.http.get<string>(url, options).toPromise().then(() => {
return true;
}).catch(() => {
return false;
})
}
getStyle(styleName: string): Observable<Array<Stop>> {
let url = `${this.url}/style/${"style-eco.stl"}`;
let options: Object = {
responseType: 'text'
};
return this.http.get<string>(url, options).pipe(map((result: string) => {
let stops: Array<Stop> = [];
let obj = this.ngxXml2jsonService.xmlToJson(new DOMParser().parseFromString(result, 'text/xml'));
obj["Map"].Style.forEach(style => {
if (style["@attributes"].name == styleName) {
style.Rule.RasterSymbolizer.RasterColorizer.stop.forEach(stop => {
stops.push(new Stop(stop["@attributes"].color, stop["@attributes"].value, stop["@attributes"].text, stop["@attributes"].label));
});
}
});
return stops;
}));
}
获取表格数据接口
getCsvData(fileName: string): Observable<string> {
let url = this.url + '/product/image/' + fileName;
let options: Object = {
headers: this.jwt(),
responseType: 'text'
};
return this.http.get<string>(url, options);
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/70d85de5258ce48af4447ac572b27c69.png)
表格添加数据
statistics(taskExecution, type: string) {
this.type = type == "area" ? '1' : '0';
let statisticsData
this.settings = [];
this.isCount = true;
this.productServ.getCsvData(this.task.initGridInfoName("csv", type, taskExecution.arguments[0])).toPromise().then(GridInfo => {
statisticsData = GridInfo;
GridInfo.split("\r\n").forEach((info, i) => {
if (i == 0) {
for (let key = 0; key < info.split(",").length; key++) {
if (info.split(",")[key] == "要素类型" || info.split(",")[key] == "分辨率" || info.split(",")[key] == "年份" || info.split(",")[key] == "月份") {
continue;
}
this.settings.push({
headerName: info.split(",")[key],
field: key.toString(),
sort: null
})
}
return
}
})
}).catch(() => {
this.isCount = false;
this.message.error(this.type + "数据获取失败");
return;
}).then(() => {
if (statisticsData == undefined) return
this.source = [];
this.selTaskExecution = taskExecution;
this.task.analysisTaskParam(this.selTaskExecution.arguments[0]);
statisticsData.split("\r\n").forEach((info, i) => {
if (i != 0) {
let item: {} = []
for (let key = 0; key < info.split(",").length; key++) {
item[key] = info.split(",")[key]
}
this.source.push(item)
}
})
this.isCount = false;
this.source.pop()
})
}