@@ -121,6 +121,7 @@ import {
121121 setCreationStep
122122} from '@mapstore/framework/actions/contextcreator' ;
123123import { setContext } from '@mapstore/framework/actions/context' ;
124+ import { REDUCERS_LOADED } from '@mapstore/framework/actions/storemanager' ;
124125import { wrapStartStop } from '@mapstore/framework/observables/epics' ;
125126import { parseDevHostname } from '@js/utils/APIUtils' ;
126127import { ProcessTypes } from '@js/utils/ResourceServiceUtils' ;
@@ -231,22 +232,34 @@ const resourceTypes = {
231232 ] ) )
232233 . switchMap ( ( [ baseConfig , resource ] ) => {
233234 const [ mapResource , mapViewerResource ] = resource ?? [ ] ;
235+ const viewerData = mapViewerResource ?. data ?? null ;
236+ const viewerPk = mapViewerResource ?. pk ;
234237 const mapConfig = options . data
235238 ? options . data
236239 : toMapStoreMapConfig ( mapResource , baseConfig ) ;
237- return Observable . of (
238- configureMap ( mapConfig ) ,
239- setControlProperty ( 'toolbar' , 'expanded' , false ) ,
240- setContext ( mapViewerResource ? mapViewerResource . data : null ) ,
241- setResource ( mapResource ) ,
240+
241+ const initialActions = Observable . of (
242+ setContext ( viewerData ) ,
242243 setResourceId ( pk ) ,
244+ setResource ( mapResource ) ,
243245 setMapViewerLinkedResource ( mapViewerResource ) ,
244246 setResourcePathParameters ( {
245247 ...options ?. params ,
246- appPk : mapViewerResource ?. pk ,
247- hasViewer : ! ! mapViewerResource ?. pk
248- } )
248+ appPk : viewerPk ,
249+ hasViewer : ! ! viewerPk
250+ } ) ,
251+ setControlProperty ( "toolbar" , "expanded" , false )
249252 ) ;
253+
254+ // Wait for module plugin reducers to load before configuring map
255+ // This ensures dynamic plugin reducers are ready to restore state
256+ const waitForReducers$ = viewerData && options ?. action$
257+ ? Observable . race (
258+ options . action$ . ofType ( REDUCERS_LOADED ) . take ( 1 ) ,
259+ Observable . timer ( 5000 ) // timeout as safety fallback only
260+ ) : Observable . of ( null ) ;
261+
262+ return Observable . concat ( initialActions , waitForReducers$ . map ( ( ) => configureMap ( mapConfig ) ) ) ;
250263 } ) ,
251264 newResourceObservable : ( options ) => {
252265 const queryDatasetParts = ( options ?. query ?. [ 'gn-dataset' ] || '' ) . split ( ':' ) ;
@@ -540,7 +553,8 @@ export const gnViewerRequestResourceConfig = (action$, store) =>
540553 isSamePreviousResource,
541554 resourceData,
542555 selectedLayer : isSamePreviousResource && { ...getInitialDatasetLayer ( state ) , style : getInitialDatasetLayerStyle ( state ) } ,
543- params : { ...action ?. options ?. params , query}
556+ params : { ...action ?. options ?. params , query} ,
557+ action$
544558 } ) ,
545559 Observable . of (
546560 loadingResourceConfig ( false )
0 commit comments