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 aef56da..0ded481 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -16,6 +16,7 @@ export const STARTSEARCHSUCCESS = '[Map] StartSearchSuccess'; export const SELECTFEATURE = '[Map] SelectFeature'; export const SELECTITEM = '[Map] SelectItem'; export const SELECTITEMSUCCESS = '[Map] SelectItemSuccess'; +export const SETSELECTEDITEMLAYER = '[Map] SetSelectedItemLayer'; export const SELECTTEMPORALITEMSSUCCESS = '[Map] SelectTemporalItemsSuccess'; export const NEXTTEMPORAL = '[Map] NextTemporal'; export const PREVIOUSTEMPORAL = '[Map] PreviousTemporal'; @@ -181,6 +182,12 @@ export class AddLayer implements Action { constructor(public item:IItem,public layerIndex=-1) { } } +export class SetSelectedItemLayer implements Action { + readonly type = SETSELECTEDITEMLAYER; + + constructor(public item:IItem,public layerIndex=-1) { } +} + export class SetVisibility implements Action { readonly type = SETVISIBILITY; @@ -299,5 +306,6 @@ export type Actions = SetMapState | SetStyle | ShowLayerSwitcher | SetReplaceUrl - | SetFeatures; + | SetFeatures + | SetSelectedItemLayer; 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 de27cd7..a8f69f7 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -194,6 +194,14 @@ export class MapEffects { } )); + @Effect() + selectItemSuccessSetLayer$: Observable = this.actions$.pipe( + ofType(mapActions.SELECTITEMSUCCESS), + map((action:mapActions.SelectItemSuccess) => + new mapActions.SetSelectedItemLayer(action.item) + ) + ); + @Effect() selectItemSuccess$: Observable = this.actions$.pipe( ofType(mapActions.SELECTITEMSUCCESS), 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 d0a3f8b..72182c9 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -163,18 +163,10 @@ export function reducer(state = initialState, action: mapActions.Actions | commo } case mapActions.SELECTITEMSUCCESS: { let a = action as mapActions.SelectItemSuccess; - var itemLayer = null; - if (a.item && "vnd.farmmaps.itemtype.layer,vnd.farmmaps.itemtype.shape.processed,vnd.farmmaps.itemtype.geotiff.processed".indexOf(a.item.itemType) >=0 ) { - itemLayer = new ItemLayer(a.item); - itemLayer.layerIndex = a.item.data.layers?a.item.data.layers[0].index:-1; - } else if (a.item && a.item.itemType == "vnd.farmmaps.itemtype.temporal") { - itemLayer = new TemporalItemLayer(a.item); - } return tassign(state, { inSearch:false, selectedItem: a.item, parentItem: a.parentItem, - selectedItemLayer: itemLayer, panelVisible: a.item != null, clearEnabled: a.item != null, searchCollapsed: false, @@ -182,6 +174,20 @@ export function reducer(state = initialState, action: mapActions.Actions | commo queryState: tassign(state.queryState, {itemCode:a.item ? a.item.code:null}) }); } + case mapActions.SETSELECTEDITEMLAYER: { + let a = action as mapActions.SetSelectedItemLayer; + var itemLayer = null; + if (a.item && "vnd.farmmaps.itemtype.layer,vnd.farmmaps.itemtype.shape.processed,vnd.farmmaps.itemtype.geotiff.processed".indexOf(a.item.itemType) >=0 ) { + itemLayer = new ItemLayer(a.item); + itemLayer.layerIndex = a.layerIndex>=0?a.layerIndex:a.item.data.layers?a.item.data.layers[0].index:-1; + } else if (a.item && a.item.itemType == "vnd.farmmaps.itemtype.temporal") { + itemLayer = new TemporalItemLayer(a.item); + } + + return tassign(state, { + selectedItemLayer: itemLayer, + }); + } case mapActions.SELECTTEMPORALITEMSSUCCESS:{ let a = action as mapActions.SelectTemporalItemsSuccess; let selectedItemLayer=tassign(state.selectedItemLayer) as TemporalItemLayer;