Make bbox optional
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good

This commit is contained in:
Willem Dantuma 2019-11-18 09:42:05 +01:00
parent 5d79dcc7b6
commit 16db063339

View File

@ -1,126 +1,128 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { IItemType } from '../models/item.type'; import { IItemType } from '../models/item.type';
import { IItem } from '../models/item'; import { IItem } from '../models/item';
import { IItemTask } from '../models/itemTask'; import { IItemTask } from '../models/itemTask';
import { HttpClient, HttpParams } from "@angular/common/http"; import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config"; import { AppConfig } from "../shared/app.config";
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ItemService { export class ItemService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig) { constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
} }
ApiEndpoint() { ApiEndpoint() {
return this.appConfig.getConfig("apiEndPoint"); return this.appConfig.getConfig("apiEndPoint");
} }
parseDates(item: any): IItem { parseDates(item: any): IItem {
item.created = new Date(Date.parse(item.created)); item.created = new Date(Date.parse(item.created));
item.updated = new Date(Date.parse(item.updated)); item.updated = new Date(Date.parse(item.updated));
item.dataDate = new Date(Date.parse(item.dataDate)); item.dataDate = new Date(Date.parse(item.dataDate));
return item; return item;
} }
getItemTypes(): Observable<{ [id: string]: IItemType }> { getItemTypes(): Observable<{ [id: string]: IItemType }> {
return this.httpClient.get<{ [id: string]: IItemType }>(`${this.ApiEndpoint()}/api/v1/itemtypes/`); return this.httpClient.get<{ [id: string]: IItemType }>(`${this.ApiEndpoint()}/api/v1/itemtypes/`);
} }
getFeatures(extent: number[], crs: string, searchText?: string, searchTags?:string,startDate?:Date,endDate?:Date,itemType?:string,parentCode?:string,dataFilter?:string,level?:number): Observable<any> { getFeatures(extent: number[], crs: string, searchText?: string, searchTags?:string,startDate?:Date,endDate?:Date,itemType?:string,parentCode?:string,dataFilter?:string,level?:number): Observable<any> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("bbox", extent.join(",")); params = params.append("bbox", extent.join(","));
params = params.append("crs", crs); params = params.append("crs", crs);
if (searchText) params = params.append("q", searchText); if (searchText) params = params.append("q", searchText);
if (searchTags) params = params.append("t", searchTags); if (searchTags) params = params.append("t", searchTags);
if (startDate) params = params.append("sd", startDate.toISOString()); if (startDate) params = params.append("sd", startDate.toISOString());
if (endDate) params = params.append("ed", endDate.toISOString()); if (endDate) params = params.append("ed", endDate.toISOString());
if (itemType) params = params.append("it", itemType); if (itemType) params = params.append("it", itemType);
if (parentCode) params = params.append("pc", parentCode); if (parentCode) params = params.append("pc", parentCode);
if (dataFilter) params = params.append("df", dataFilter); if (dataFilter) params = params.append("df", dataFilter);
if (level) params = params.append("lvl", dataFilter); if (level) params = params.append("lvl", dataFilter);
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/features/`, {params:params}); return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/features/`, {params:params});
} }
getFeature(code:string, crs: string): Observable<any> { getFeature(code:string, crs: string): Observable<any> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("crs", crs); params = params.append("crs", crs);
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/feature/`, { params: params }); return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/feature/`, { params: params });
} }
getItem(code: string): Observable<IItem> { getItem(code: string): Observable<IItem> {
return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}`).pipe(map(i => this.parseDates(i))); return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}`).pipe(map(i => this.parseDates(i)));
} }
getItemByCodeAndType(code: string, itemType: string): Observable<IItem> { getItemByCodeAndType(code: string, itemType: string): Observable<IItem> {
return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}/${itemType}`); return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}/${itemType}`);
} }
getItemList(itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> { getItemList(itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("it", itemType); params = params.append("it", itemType);
if(dataFilter != null){ if(dataFilter != null){
params = params.append("df", JSON.stringify(dataFilter)); params = params.append("df", JSON.stringify(dataFilter));
} }
params = params.append("lvl", itemType); params = params.append("lvl", itemType);
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i)))); return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i))));
} }
getChildItemList(parentcode: string, itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> { getChildItemList(parentcode: string, itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("it", itemType); params = params.append("it", itemType);
if (dataFilter != null) { if (dataFilter != null) {
params = params.append("df", JSON.stringify(dataFilter)); params = params.append("df", JSON.stringify(dataFilter));
} }
params = params.append("lvl", level.toString()); params = params.append("lvl", level.toString());
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i)))); return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i))));
} }
getChildItemListByExtent(parentcode: string, itemType: string, extent: number[], crs: string, dataFilter?: any, level: number = 1): Observable<IItem[]> { getChildItemListByExtent(parentcode: string, itemType: string, extent: number[], crs: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("it", itemType); params = params.append("it", itemType);
params = params.append("bbox", extent.join(",")); params = params.append("bbox", extent.join(","));
params = params.append("crs", crs); params = params.append("crs", crs);
if (dataFilter != null) { if (dataFilter != null) {
params = params.append("df", JSON.stringify(dataFilter)); params = params.append("df", JSON.stringify(dataFilter));
} }
params = params.append("lvl", level.toString()); params = params.append("lvl", level.toString());
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i)))); return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i))));
} }
getItemFeatures(code: string, extent: number[], crs: string, layerIndex?:number): Observable<any> { getItemFeatures(code: string, extent: number[], crs: string, layerIndex?:number): Observable<any> {
var params = new HttpParams(); var params = new HttpParams();
params = params.append("bbox", extent.join(",")); params = params.append("crs", crs);
params = params.append("crs", crs); if(extent != null) {
if(layerIndex!=null) params = params.append("bbox", extent.join(","));
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features/layer/${layerIndex}`, { params: params }); }
else if(layerIndex!=null)
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features`, { params: params }); return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features/layer/${layerIndex}`, { params: params });
} else
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features`, { params: params });
putItem(item:IItem): Observable<IItem> { }
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/items/${item.code}`,item);
} putItem(item:IItem): Observable<IItem> {
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/items/${item.code}`,item);
deleteItems(itemCodes:string[]): Observable<any> { }
return this.httpClient.post<any>(`${this.ApiEndpoint()}/api/v1/items/delete`, itemCodes);
} deleteItems(itemCodes:string[]): Observable<any> {
return this.httpClient.post<any>(`${this.ApiEndpoint()}/api/v1/items/delete`, itemCodes);
getTemporalLast(code: string): Observable<any> { }
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/last`);
} getTemporalLast(code: string): Observable<any> {
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/last`);
getTemporal(code: string, startDate?: Date, endDate?: Date): Observable<any> { }
var params = new HttpParams();
if (startDate) params = params.append("sd", startDate.toISOString()); getTemporal(code: string, startDate?: Date, endDate?: Date): Observable<any> {
if (endDate) params = params.append("ed", endDate.toISOString()); var params = new HttpParams();
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/`, { params: params }); if (startDate) params = params.append("sd", startDate.toISOString());
} if (endDate) params = params.append("ed", endDate.toISOString());
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/`, { params: params });
postItemTask(item: IItem, task: IItemTask): Observable<IItemTask> { }
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/tasks`, task);
} postItemTask(item: IItem, task: IItemTask): Observable<IItemTask> {
} return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/tasks`, task);
}
}