More refactoring, add thematic maps button

This commit is contained in:
Willem Dantuma 2020-04-22 08:11:50 +02:00
parent ef81b04f4e
commit 69751540d3
4 changed files with 34 additions and 16 deletions

View File

@ -42,6 +42,7 @@ export const DOQUERY = '[Map] DoQuery';
export const SETSTYLE = '[Map] SetStyle'; export const SETSTYLE = '[Map] SetStyle';
export const SHOWLAYERSWITCHER = '[Map] ShowLayerSwitcher'; export const SHOWLAYERSWITCHER = '[Map] ShowLayerSwitcher';
export const CLEAR = '[Map] Clear'; export const CLEAR = '[Map] Clear';
export const SETREPLACEURL = '[Map] SetReplaceUrl';
export class Clear implements Action { export class Clear implements Action {
readonly type = CLEAR; readonly type = CLEAR;
@ -165,7 +166,7 @@ export class SetExtent implements Action {
export class SetQueryState implements Action { export class SetQueryState implements Action {
readonly type = SETQUERYSTATE; readonly type = SETQUERYSTATE;
constructor(public queryState: IQueryState) { } constructor(public queryState: IQueryState,public replaceUrl:boolean = true) { }
} }
export class SetTimeSpan implements Action { export class SetTimeSpan implements Action {
@ -251,6 +252,11 @@ export class ShowLayerSwitcher implements Action {
constructor(public show:boolean) {} constructor(public show:boolean) {}
} }
export class SetReplaceUrl implements Action {
readonly type = SETREPLACEURL;
constructor(public replaceUrl:boolean) {}
}
export type Actions = SetMapState export type Actions = SetMapState
| Init | Init
| Clear | Clear
@ -285,5 +291,6 @@ export type Actions = SetMapState
| SetViewExtent | SetViewExtent
| DoQuery | DoQuery
| SetStyle | SetStyle
| ShowLayerSwitcher; | ShowLayerSwitcher
| SetReplaceUrl;

View File

@ -115,7 +115,8 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
} }
if(urlparts.length==0 ) { if(urlparts.length==0 ) {
newQueryState.itemCode = queryState.itemCode; newQueryState.itemCode = queryState.itemCode;
this.replaceUrl(mapState,newQueryState,false); this.store.dispatch(new mapActions.SetQueryState(newQueryState,false));
//this.replaceUrl(mapState,newQueryState,false);
} else { } else {
this.router.navigate(urlparts); this.router.navigate(urlparts);
} }
@ -257,7 +258,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
window.localStorage.setItem("FarmMapsCommonMap_mapState",this.serializeMapState(newMapState)); window.localStorage.setItem("FarmMapsCommonMap_mapState",this.serializeMapState(newMapState));
} else if(queryStateChanged) { } else if(queryStateChanged) {
return of(new mapActions.SetQueryState(newQueryState)); return of(new mapActions.SetQueryState(newQueryState));
} return of(null) } return of(new mapActions.SetReplaceUrl(true));
})).subscribe((action) => { })).subscribe((action) => {
if(action) { if(action) {
console.debug("Url to state"); console.debug("Url to state");
@ -267,7 +268,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
// state to url // state to url
this.stateSub = this.state$.pipe(withLatestFrom(this.route.paramMap),switchMap(([state,params]) => { this.stateSub = this.state$.pipe(switchMap((state) => {
let newUrl = this.serializeMapState(state.mapState) + "_" + this.serializeService.serialize(state.queryState); let newUrl = this.serializeMapState(state.mapState) + "_" + this.serializeService.serialize(state.queryState);
if(this.lastUrl!=newUrl && state.setStateCount>0) { if(this.lastUrl!=newUrl && state.setStateCount>0) {
this.lastUrl=newUrl; this.lastUrl=newUrl;
@ -279,7 +280,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
})).subscribe((newUrlState) =>{ })).subscribe((newUrlState) =>{
if(newUrlState) { if(newUrlState) {
console.debug(`State to url ${newUrlState.setStateCount}`); console.debug(`State to url ${newUrlState.setStateCount}`);
this.replaceUrl(newUrlState.mapState,newUrlState.queryState,true); this.replaceUrl(newUrlState.mapState,newUrlState.queryState,newUrlState.replaceUrl);
} }
}); });

View File

@ -57,7 +57,8 @@ export interface State {
styles:IStyles, styles:IStyles,
showLayerSwitcher:boolean, showLayerSwitcher:boolean,
setStateCount:number, setStateCount:number,
inSearch:boolean inSearch:boolean,
replaceUrl:boolean
} }
export const initialState: State = { export const initialState: State = {
@ -94,7 +95,8 @@ export const initialState: State = {
styles: {}, styles: {},
showLayerSwitcher: false, showLayerSwitcher: false,
setStateCount: 0, setStateCount: 0,
inSearch:false inSearch:false,
replaceUrl:true
} }
export function reducer(state = initialState, action: mapActions.Actions | commonActions.Actions | RouterNavigationAction): State { export function reducer(state = initialState, action: mapActions.Actions | commonActions.Actions | RouterNavigationAction): State {
@ -111,7 +113,7 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
} }
case mapActions.SETQUERYSTATE: { case mapActions.SETQUERYSTATE: {
let a = action as mapActions.SetQueryState; let a = action as mapActions.SetQueryState;
return tassign(state, { queryState: tassign(a.queryState ),setStateCount: state.setStateCount+1}); return tassign(state, { queryState: tassign(a.queryState ),setStateCount: state.setStateCount+1,replaceUrl:a.replaceUrl});
} }
case mapActions.SETSTATE: { case mapActions.SETSTATE: {
let a = action as mapActions.SetState; let a = action as mapActions.SetState;
@ -457,6 +459,10 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
let a = action as mapActions.ShowLayerSwitcher; let a = action as mapActions.ShowLayerSwitcher;
return tassign(state,{showLayerSwitcher:a.show}); return tassign(state,{showLayerSwitcher:a.show});
} }
case mapActions.SETREPLACEURL: {
let a= action as mapActions.SetReplaceUrl;
return tassign(state,{replaceUrl:a.replaceUrl});
}
default: { default: {
return state; return state;
} }
@ -487,7 +493,7 @@ export const getStyles = (state:State) => state.styles;
export const getShowLayerSwitcher = (state:State) => state.showLayerSwitcher; export const getShowLayerSwitcher = (state:State) => state.showLayerSwitcher;
export const getSetStateCount = (state:State) => state.setStateCount; export const getSetStateCount = (state:State) => state.setStateCount;
export const getInSearch = (state:State) => state.inSearch; export const getInSearch = (state:State) => state.inSearch;
export const getState = (state:State) => {return {mapState:state.mapState,queryState:state.queryState,setStateCount:state.setStateCount};} export const getState = (state:State) => {return {mapState:state.mapState,queryState:state.queryState,setStateCount:state.setStateCount,replaceUrl:state.replaceUrl};}
export const selectMapState = createFeatureSelector<State>(MODULE_NAME); export const selectMapState = createFeatureSelector<State>(MODULE_NAME);
export const selectGetMapState= createSelector(selectMapState, getMapState); export const selectGetMapState= createSelector(selectMapState, getMapState);

View File

@ -5,6 +5,10 @@
<div class="icon rounded-circle farm-icon"><i class="fm fm-farm" aria-hidden="true"></i></div> <div class="icon rounded-circle farm-icon"><i class="fm fm-farm" aria-hidden="true"></i></div>
<div class="caption" i18n>Farms</div> <div class="caption" i18n>Farms</div>
</div> </div>
<div class="shortcut-icon" (click)="handlePredefinedQuery($event,{itemType:'vnd.farmmaps.itemtype.layer'})">
<div class="icon rounded-circle thematic-maps-icon"><i class="fa fa-map" aria-hidden="true"></i></div>
<div class="caption" i18n>Thematic maps</div>
</div>
</div> </div>
</div> </div>
</div> </div>