diff --git a/projects/common-map/src/fm-map/actions/map.actions.ts b/projects/common-map/src/fm-map/actions/map.actions.ts index 5f17acf..f1c6f49 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -102,7 +102,7 @@ export class SelectItemSuccess implements Action { export class SelectTemporalItemsSuccess implements Action { readonly type = SELECTTEMPORALITEMSSUCCESS; - constructor(public temporalItems: IListItem[]) { } + constructor(public temporalItems: IItem[]) { } } export class AddFeatureSuccess implements Action { diff --git a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts index 5fc56f9..71407ec 100644 --- a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts +++ b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts @@ -3,7 +3,7 @@ import { HttpClient } from "@angular/common/http"; import { LayerVectorComponent, LayerTileComponent, LayerGroupComponent, MapComponent } from 'ngx-openlayers'; import { ItemService } from '@farmmaps/common'; import { AppConfig } from '@farmmaps/common'; -import { IItemLayer} from '../../../models/item.layer'; +import { IItemLayer,ItemLayer, ITemporalItemLayer} from '../../../models/item.layer'; import { ILayerData} from '../../../models/layer.data'; import { IRenderoutputTiles,IRenderoutputImage,IGradientstop,ILayer,IHistogram} from '../../../models/color.map'; import {Extent} from 'ol/extent'; @@ -227,6 +227,8 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange } createTemporalLayer(item:IItem,itemLayer:IItemLayer):Layer { + let i = itemLayer as ITemporalItemLayer; + return null; } @@ -240,7 +242,10 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange } else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.layer') { layer = this.createExternalLayer(itemLayer.item,itemLayer); } else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') { - layer = this.createTemporalLayer(itemLayer.item,itemLayer); + var i = itemLayer as ITemporalItemLayer; + if(i.selectedItem) { + layer = this.createLayer( new ItemLayer(i.selectedItem) ); + } } if (layer) { let geometry = new GeoJSON().readGeometry(itemLayer.item.geometry); diff --git a/projects/common-map/src/fm-map/effects/map.effects.ts b/projects/common-map/src/fm-map/effects/map.effects.ts index af2a7a6..27a11ee 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -178,6 +178,7 @@ export class MapEffects { switchMap((action:mapActions.SelectItemSuccess) => { if(action.item.itemType == "vnd.farmmaps.itemtype.temporal") { return this.itemService$.getChildItemList(action.item.code,null).pipe( + map(items => items.sort((a, b) => b.dataDate.getTime() - a.dataDate.getTime())), map((items) => new mapActions.SelectTemporalItemsSuccess(items )), catchError(error => of(new commonActions.Fail(error)))); } else { diff --git a/projects/common-map/src/fm-map/models/item.layer.ts b/projects/common-map/src/fm-map/models/item.layer.ts index 0138ab4..c9c91a9 100644 --- a/projects/common-map/src/fm-map/models/item.layer.ts +++ b/projects/common-map/src/fm-map/models/item.layer.ts @@ -27,18 +27,20 @@ export class ItemLayer implements IItemLayer { export interface ITemporalItemLayer extends IItemLayer { previousLayer: Layer - selectedLayer: Layer, nextLayer: Layer - temporalItems: IListItem[], - selectedItem: IListItem + temporalItems: IItem[], + previousItem: IItem, + selectedItem: IItem, + nextItem:IItem } export class TemporalItemLayer extends ItemLayer implements ITemporalItemLayer { public previousLayer:Layer = null; - public selectedLayer:Layer = null; public nextLayer:Layer = null; - public temporalItems:IListItem[] = []; - public selectedItem:IListItem =null; + public temporalItems:IItem[] = []; + public previousItem:IItem = null; + public selectedItem:IItem =null; + public nextItem:IItem = null; constructor(item:IItem) { super(item) diff --git a/projects/common-map/src/fm-map/reducers/map.reducer.ts b/projects/common-map/src/fm-map/reducers/map.reducer.ts index 7dc4055..3e9af47 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -1,6 +1,6 @@ import { tassign } from 'tassign'; import { IItem,Item } from '@farmmaps/common'; -import { IItemLayer,ItemLayer,TemporalItemLayer} from '../models/item.layer'; +import { IItemLayer,ItemLayer,ITemporalItemLayer,TemporalItemLayer} from '../models/item.layer'; import { IMapState} from '../models/map.state'; import { IQueryState} from '@farmmaps/common'; import { IPeriodState} from '../models/period.state'; @@ -177,6 +177,15 @@ export function reducer(state = initialState, action: mapActions.Actions | commo queryState: tassign(state.queryState, {itemCode:a.item ? a.item.code:null}) }); } + case mapActions.SELECTTEMPORALITEMSSUCCESS:{ + let a = action as mapActions.SelectTemporalItemsSuccess; + let selectedItemLayer=tassign(state.selectedItemLayer) as TemporalItemLayer; + selectedItemLayer.temporalItems = a.temporalItems; + selectedItemLayer.selectedItem = a.temporalItems.length>0?a.temporalItems[a.temporalItems.length-1]:null; + selectedItemLayer.previousItem = a.temporalItems.length>1?a.temporalItems[a.temporalItems.length-2]:null; + selectedItemLayer.nextItem = null; + return tassign(state,{selectedItemLayer:tassign(state.selectedItemLayer,selectedItemLayer as ItemLayer)}); + } case mapActions.STARTSEARCH: { let a = action as mapActions.StartSearch; return tassign(state, {