Implement device update event
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
parent
2e0b090fb7
commit
615872992f
12
package-lock.json
generated
12
package-lock.json
generated
@ -1943,9 +1943,9 @@
|
||||
}
|
||||
},
|
||||
"@farmmaps/common": {
|
||||
"version": "0.0.1-prerelease.83",
|
||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.83.tgz",
|
||||
"integrity": "sha512-JQryEA79ELg9hFYBYBIyEQD0bv5oHTX6Uch2nRaOlLhaiXbo6g/F4UYdRnLGTo7nzIPD1wcLcZQorfSMOhYPyQ==",
|
||||
"version": "0.0.1-prerelease.90",
|
||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.90.tgz",
|
||||
"integrity": "sha512-uSB9cJ06aJtfftQ/Yw6qR+LeeOAP1ly6JGxW6ubr/9hEqub38w+BPsQQYD5Sxn/oLjknRwhzEMZKYWTINF4zXw==",
|
||||
"requires": {
|
||||
"angular-oauth2-oidc": "^8.0.2",
|
||||
"ngx-uploadx": "^3.3.2",
|
||||
@ -1953,9 +1953,9 @@
|
||||
}
|
||||
},
|
||||
"@farmmaps/common-map": {
|
||||
"version": "0.0.1-prerelease.83",
|
||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.83.tgz",
|
||||
"integrity": "sha512-tILDqqj+ucSipvxJws3tLlZ4ytewqfmZzTmS07O0YhTFqx7+4WzkW8kL8S8vx3t3rB/ZPoAMa9u+w6G2WQ6nCw==",
|
||||
"version": "0.0.1-prerelease.90",
|
||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.90.tgz",
|
||||
"integrity": "sha512-z1q8cHFNrrAQx8n8dXW2cn9d3wxG9oruPSoNgUrgz+YYJkxeDr0kd3SqloftPJrVxES0iIiqguweo0SRyBGVYA==",
|
||||
"requires": {
|
||||
"ngx-openlayers": "1.0.0-next.13",
|
||||
"ol": "^6.0.0",
|
||||
|
@ -20,8 +20,8 @@
|
||||
"@angular/platform-browser-dynamic": "~8.2.14",
|
||||
"@angular/router": "~8.2.14",
|
||||
"@aspnet/signalr": "^1.1.4",
|
||||
"@farmmaps/common": ">=0.0.1-prerelease.83 <0.0.1",
|
||||
"@farmmaps/common-map": ">=0.0.1-prerelease.83 <0.0.1",
|
||||
"@farmmaps/common": ">=0.0.1-prerelease.90 <0.0.1",
|
||||
"@farmmaps/common-map": ">=0.0.1-prerelease.90 <0.0.1",
|
||||
"@ng-bootstrap/ng-bootstrap": "^4.2.1",
|
||||
"@ngrx/effects": "^8.2.0",
|
||||
"@ngrx/router-store": "^8.2.0",
|
||||
|
@ -15,6 +15,6 @@
|
||||
"@ngrx/router-store": "^8.2",
|
||||
"@ngrx/store": "^8.2",
|
||||
"tassign": "^1.0.0",
|
||||
"@farmmaps/common": ">=0.0.1-prerelease.82 <0.0.1"
|
||||
"@farmmaps/common": ">=0.0.1-prerelease.90 <0.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { Effect, Actions,ofType } from '@ngrx/effects';
|
||||
import { Observable , of } from 'rxjs';
|
||||
import { withLatestFrom, switchMap, map, catchError, mergeMap, delay} from 'rxjs/operators';
|
||||
|
||||
import {GeoJSON} from 'ol/format';
|
||||
import {GeoJSON,WKT} from 'ol/format';
|
||||
import {Feature} from 'ol';
|
||||
import { getCenter, Extent, createEmpty, extend} from 'ol/extent';
|
||||
import {Point} from 'ol/geom'
|
||||
@ -25,10 +25,15 @@ import { tassign } from 'tassign';
|
||||
|
||||
@Injectable()
|
||||
export class MapEffects {
|
||||
private _format: GeoJSON;
|
||||
private _geojsonFormat: GeoJSON;
|
||||
private _wktFormat: WKT;
|
||||
|
||||
private toPointFeature(feature: any): Feature {
|
||||
var f = this._format.readFeature(feature);
|
||||
private toPointFeature(updateEvent:commonActions.DeviceUpdateEvent): Feature {
|
||||
var f = this._wktFormat.readFeature(updateEvent.attributes["geometry"],{
|
||||
dataProjection: 'EPSG:4326',
|
||||
featureProjection: 'EPSG:3857'
|
||||
});
|
||||
f.setId(updateEvent.itemCode);
|
||||
var centroid = getCenter(f.getGeometry().getExtent());
|
||||
f.setGeometry(new Point(centroid));
|
||||
return f;
|
||||
@ -83,7 +88,7 @@ export class MapEffects {
|
||||
f.id = f.properties["code"];
|
||||
}
|
||||
}
|
||||
return of(new mapActions.StartSearchSuccess(this._format.readFeatures(features), action.queryState));
|
||||
return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), action.queryState));
|
||||
}
|
||||
),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
@ -135,7 +140,11 @@ export class MapEffects {
|
||||
ofType(mapActions.SELECTITEMSUCCESS),
|
||||
switchMap((action:mapActions.SelectItemSuccess) => {
|
||||
return this.itemService$.getFeature(action.item.code, "EPSG:3857").pipe(
|
||||
map((feature: IItem) => new mapActions.AddFeatureSuccess(this._format.readFeature(feature) )),
|
||||
map((feature: any) => {
|
||||
let f = this._geojsonFormat.readFeature(feature);
|
||||
f.setId(action.item.code);
|
||||
return new mapActions.AddFeatureSuccess(f );
|
||||
}),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
}
|
||||
));
|
||||
@ -163,21 +172,19 @@ export class MapEffects {
|
||||
|
||||
@Effect()
|
||||
featureUpdate$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(commonActions.ITEMCHANGEDEVENT),
|
||||
ofType(commonActions.DEVICEUPDATEEVENT),
|
||||
withLatestFrom(this.store$.select(mapReducers.selectGetFeatures)),
|
||||
mergeMap(([action, features]) => {
|
||||
let itemChangedAction = action as commonActions.ItemChangedEvent;
|
||||
let deviceUpdateEventAction = action as commonActions.DeviceUpdateEvent;
|
||||
var feature: Feature = null;
|
||||
for (let f of features) {
|
||||
if (f.get("code") == itemChangedAction.itemCode) {
|
||||
if (f.getId() == deviceUpdateEventAction.itemCode) {
|
||||
feature = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (feature) {
|
||||
return this.itemService$.getFeature(itemChangedAction.itemCode, "EPSG:3857").pipe(
|
||||
map((feature: any) => new mapActions.UpdateFeatureSuccess(this.toPointFeature(feature))),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
return of(new mapActions.UpdateFeatureSuccess(this.toPointFeature(deviceUpdateEventAction)));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
@ -225,6 +232,7 @@ export class MapEffects {
|
||||
}));
|
||||
|
||||
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService) {
|
||||
this._format = new GeoJSON();
|
||||
this._geojsonFormat = new GeoJSON();
|
||||
this._wktFormat = new WKT();
|
||||
}
|
||||
}
|
||||
|
@ -1,372 +1,372 @@
|
||||
import { tassign } from 'tassign';
|
||||
import { IItem,Item } from '@farmmaps/common';
|
||||
import { IItemLayer,ItemLayer} from '../models/item.layer';
|
||||
import { IMapState} from '../models/map.state';
|
||||
import { IQueryState} from '../models/query.state';
|
||||
import { IPeriodState} from '../models/period.state';
|
||||
import * as mapActions from '../actions/map.actions';
|
||||
import {commonActions} from '@farmmaps/common';
|
||||
import { createSelector, createFeatureSelector } from '@ngrx/store';
|
||||
|
||||
import {Feature} from 'ol';
|
||||
|
||||
import { ROUTER_NAVIGATION, RouterNavigationAction } from '@ngrx/router-store';
|
||||
|
||||
import { MODULE_NAME } from '../module-name';
|
||||
|
||||
const startDate:Date = new Date(new Date(Date.now()).getFullYear(), new Date(Date.now()).getMonth() - 3, 1);
|
||||
const endDate:Date = new Date(Date.now());
|
||||
|
||||
export const initialQueryState: IQueryState = {
|
||||
itemCode: null,
|
||||
parentCode: null,
|
||||
level: 1,
|
||||
itemType: null,
|
||||
bboxFilter: false,
|
||||
query: null,
|
||||
tags: null,
|
||||
endDate: null,
|
||||
startDate: null,
|
||||
bbox: []
|
||||
};
|
||||
|
||||
export interface State {
|
||||
period:IPeriodState,
|
||||
mapState: IMapState,
|
||||
viewExtent: number[],
|
||||
queryState: IQueryState,
|
||||
query:IQueryState,
|
||||
parentCode: string,
|
||||
features: Array<Feature>,
|
||||
panelVisible: boolean,
|
||||
panelCollapsed: boolean,
|
||||
selectedFeature: Feature,
|
||||
selectedItem:IItem,
|
||||
clearEnabled: boolean,
|
||||
searchCollapsed: boolean,
|
||||
searchMinified: boolean,
|
||||
menuVisible: boolean,
|
||||
extent: number[],
|
||||
baseLayers: Array<IItemLayer>
|
||||
overlayLayers: Array<IItemLayer>,
|
||||
selectedItemLayer: IItemLayer,
|
||||
projection: string,
|
||||
selectedBaseLayer: IItemLayer,
|
||||
selectedOverlayLayer: IItemLayer
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
period: {
|
||||
startDate: startDate,
|
||||
endDate: endDate
|
||||
},
|
||||
mapState: {
|
||||
zoom: 8,
|
||||
rotation: 0,
|
||||
xCenter: 5.377554,
|
||||
yCenter: 52.162422,
|
||||
baseLayerCode: ""
|
||||
},
|
||||
viewExtent:[],
|
||||
queryState: tassign(initialQueryState),
|
||||
query: tassign(initialQueryState),
|
||||
parentCode: null,
|
||||
features: [],
|
||||
panelVisible: false,
|
||||
panelCollapsed: false,
|
||||
selectedFeature: null,
|
||||
selectedItem: null,
|
||||
clearEnabled: false,
|
||||
searchCollapsed: true,
|
||||
searchMinified:false,
|
||||
menuVisible: true,
|
||||
extent: null,
|
||||
baseLayers: [],
|
||||
overlayLayers: [],
|
||||
projection: "EPSG:3857",
|
||||
selectedBaseLayer: null,
|
||||
selectedOverlayLayer: null,
|
||||
selectedItemLayer: null
|
||||
}
|
||||
|
||||
export function reducer(state = initialState, action: mapActions.Actions | commonActions.Actions | RouterNavigationAction): State {
|
||||
switch (action.type) {
|
||||
case ROUTER_NAVIGATION: {
|
||||
let a = action as RouterNavigationAction;
|
||||
return tassign(state);
|
||||
}
|
||||
case mapActions.SETMAPSTATE: {
|
||||
let a = action as mapActions.SetMapState;
|
||||
return tassign(state, {
|
||||
mapState: a.mapState
|
||||
});
|
||||
}
|
||||
case mapActions.SETQUERYSTATE: {
|
||||
let a = action as mapActions.SetQueryState;
|
||||
return tassign(state, { queryState: tassign(a.queryState )});
|
||||
}
|
||||
case mapActions.SETSTATE: {
|
||||
let a = action as mapActions.SetState;
|
||||
return tassign(state, { mapState: tassign(a.mapState), queryState: tassign(a.queryState)});
|
||||
}
|
||||
case mapActions.SETVIEWEXTENT: {
|
||||
let a = action as mapActions.SetViewExtent;
|
||||
return tassign(state, { viewExtent: a.extent });
|
||||
}
|
||||
case mapActions.SETPARENT: {
|
||||
let a = action as mapActions.SetParent;
|
||||
return tassign(state, {
|
||||
parentCode : a.parentCode
|
||||
});
|
||||
}
|
||||
case mapActions.STARTSEARCHSUCCESS: {
|
||||
let a = action as mapActions.StartSearchSuccess;
|
||||
return tassign(state, {
|
||||
panelVisible: true,
|
||||
clearEnabled: true,
|
||||
searchMinified: true,
|
||||
features: a.features
|
||||
});
|
||||
}
|
||||
case mapActions.SELECTFEATURE: {
|
||||
let a = action as mapActions.SelectFeature;
|
||||
return tassign(state, {
|
||||
selectedFeature: state.selectedItem?state.selectedFeature: a.feature
|
||||
});
|
||||
}
|
||||
case mapActions.SELECTITEM: {
|
||||
return tassign(state, {
|
||||
selectedItem: null,
|
||||
searchMinified:false,
|
||||
selectedItemLayer: null,
|
||||
features:[]
|
||||
});
|
||||
}
|
||||
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);
|
||||
}
|
||||
return tassign(state, {
|
||||
selectedItem: a.item,
|
||||
selectedItemLayer: itemLayer,
|
||||
panelVisible: a.item != null,
|
||||
clearEnabled: a.item != null,
|
||||
searchCollapsed: false,
|
||||
searchMinified: true,
|
||||
queryState: tassign(state.queryState, {itemCode:a.item ? a.item.code:null})
|
||||
});
|
||||
}
|
||||
case mapActions.STARTSEARCH: {
|
||||
let a = action as mapActions.StartSearch;
|
||||
return tassign(state, {
|
||||
selectedItem: null,
|
||||
selectedItemLayer:null,
|
||||
queryState: tassign(a.queryState),
|
||||
searchCollapsed: false,
|
||||
searchMinified: true,
|
||||
menuVisible:false
|
||||
});
|
||||
}
|
||||
case mapActions.DOQUERY: {
|
||||
let a = action as mapActions.DoQuery;
|
||||
return tassign(state, {
|
||||
query: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] })});
|
||||
}
|
||||
case mapActions.ADDFEATURESUCCESS: {
|
||||
let a = action as mapActions.AddFeatureSuccess;
|
||||
let features = state.features.slice();
|
||||
features.push(a.feature);
|
||||
return tassign(state, {
|
||||
panelVisible: true,
|
||||
selectedFeature: a.feature,
|
||||
menuVisible: false,
|
||||
extent: a.feature.getGeometry().getExtent(),
|
||||
searchCollapsed: false,
|
||||
clearEnabled:true,
|
||||
features:features
|
||||
});
|
||||
}
|
||||
case mapActions.UPDATEFEATURESUCCESS: {
|
||||
let a = action as mapActions.UpdateFeatureSuccess;
|
||||
let features: any[] = [];
|
||||
var index = -1;
|
||||
for (var i = 0; i < state.features.length; i++) {
|
||||
if (state.features[i].get("code") == a.feature.get("code")) {
|
||||
features.push(a.feature);
|
||||
} else {
|
||||
features.push(state.features[i]);
|
||||
}
|
||||
}
|
||||
return tassign(state, { features: features });
|
||||
}
|
||||
case mapActions.EXPANDSEARCH: {
|
||||
return tassign(state, { searchCollapsed: false });
|
||||
}
|
||||
case mapActions.COLLAPSESEARCH: {
|
||||
return tassign(state, { searchCollapsed: state.panelVisible ? false: true});
|
||||
}
|
||||
case mapActions.TOGGLEMENU: {
|
||||
return tassign(state, { menuVisible: !state.menuVisible });
|
||||
}
|
||||
case mapActions.SETEXTENT: {
|
||||
let a = action as mapActions.SetExtent;
|
||||
return tassign(state, { extent: a.extent });
|
||||
}
|
||||
case mapActions.ADDLAYER: {
|
||||
let a = action as mapActions.AddLayer;
|
||||
let itemLayers = state.overlayLayers.slice(0);
|
||||
let itemLayer = new ItemLayer(a.item);
|
||||
itemLayer.layerIndex = a.layerIndex == -1 ? 0 : a.layerIndex;
|
||||
itemLayers.push(itemLayer);
|
||||
return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer });
|
||||
}
|
||||
case mapActions.REMOVELAYER: {
|
||||
let a = action as mapActions.RemoveLayer;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
var selectedOverlayLayer: IItemLayer = null;
|
||||
if (i>0 && state.overlayLayers.length > 1)
|
||||
selectedOverlayLayer = state.overlayLayers[i - 1];
|
||||
else if (i == 0 && state.overlayLayers.length > 1)
|
||||
selectedOverlayLayer = state.overlayLayers[i + 1];
|
||||
newLayers.splice(i, 1);
|
||||
return tassign(state, { overlayLayers: newLayers, selectedOverlayLayer: selectedOverlayLayer });
|
||||
}
|
||||
case mapActions.SETVISIBILITY: {
|
||||
let a = action as mapActions.SetVisibility;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].visible = a.visibility;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
case mapActions.SETOPACITY: {
|
||||
let a = action as mapActions.SetOpacity;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].opacity = a.opacity;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
case mapActions.SETLAYERINDEX: {
|
||||
let a = action as mapActions.SetLayerIndex;
|
||||
if (a.itemLayer == null) {
|
||||
var newItemlayer = new ItemLayer(state.selectedItemLayer.item);
|
||||
newItemlayer.layerIndex = a.layerIndex;
|
||||
return tassign(state, { selectedItemLayer: newItemlayer})
|
||||
} else {
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].layerIndex = a.layerIndex;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
}
|
||||
case mapActions.LOADBASELAYERSSUCCESS: {
|
||||
let a =action as mapActions.LoadBaseLayersSuccess;
|
||||
let baseLayers:ItemLayer[] = [];
|
||||
for (let item of a.items) {
|
||||
var l = new ItemLayer(item);
|
||||
l.visible = false;
|
||||
baseLayers.push(l);
|
||||
}
|
||||
var selectedBaseLayer: IItemLayer = null;
|
||||
var mapState = tassign(state.mapState);
|
||||
console.debug(`Base layerload: ${mapState.baseLayerCode}`)
|
||||
if (baseLayers.length > 0 && mapState.baseLayerCode != "") {
|
||||
selectedBaseLayer = baseLayers.filter(layer => layer.item.code === mapState.baseLayerCode)[0];
|
||||
selectedBaseLayer.visible = true;
|
||||
} else if (baseLayers.length > 0) {
|
||||
selectedBaseLayer = baseLayers[0];
|
||||
selectedBaseLayer.visible = true;
|
||||
mapState.baseLayerCode = selectedBaseLayer.item.code;
|
||||
}
|
||||
return tassign(state, { mapState:mapState, baseLayers: baseLayers, selectedBaseLayer: selectedBaseLayer });
|
||||
}
|
||||
case mapActions.SELECTBASELAYER: {
|
||||
let a = action as mapActions.SelectBaseLayer;
|
||||
let baseLayers = state.baseLayers.slice(0);
|
||||
baseLayers.forEach((l) => l.visible = false);
|
||||
let i = state.baseLayers.indexOf(a.itemLayer);
|
||||
baseLayers[i].visible = true;
|
||||
var mapState = tassign(state.mapState);
|
||||
mapState.baseLayerCode = a.itemLayer.item.code;
|
||||
return tassign(state, {mapState:mapState, baseLayers:baseLayers,selectedBaseLayer:a.itemLayer });
|
||||
}
|
||||
case mapActions.SELECTOVERLAYLAYER: {
|
||||
let a = action as mapActions.SelectOverlayLayer;
|
||||
return tassign(state, { selectedOverlayLayer: a.itemLayer });
|
||||
}
|
||||
case commonActions.ESCAPE: {
|
||||
let a = action as commonActions.Escape;
|
||||
let newQueryState = tassign(state.queryState, { query: null, tags: null, itemCode: null, parentCode: null, itemType: null });
|
||||
if (a.escapeKey) {
|
||||
return tassign(state, {
|
||||
panelVisible: false,
|
||||
panelCollapsed:false,
|
||||
selectedItem: null,
|
||||
selectedItemLayer: null,
|
||||
selectedFeature: null,
|
||||
queryState: newQueryState,
|
||||
clearEnabled: false,
|
||||
searchCollapsed: true,
|
||||
searchMinified: false,
|
||||
menuVisible:false,
|
||||
features: [],
|
||||
query:initialState.query
|
||||
});
|
||||
} else {
|
||||
return tassign(state, {});
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getMapState = (state: State) => state.mapState;
|
||||
export const getParentCode = (state: State) => state.parentCode;
|
||||
export const getFeatures = (state: State) => state.features;
|
||||
export const getPanelVisible = (state: State) => state.panelVisible;
|
||||
export const getPanelCollapsed = (state: State) => state.panelCollapsed;
|
||||
export const getSelectedFeature = (state: State) => state.selectedFeature;
|
||||
export const getSelectedItem = (state: State) => state.selectedItem;
|
||||
export const getQueryState = (state: State) => state.queryState;
|
||||
export const getClearEnabled = (state: State) => state.clearEnabled;
|
||||
export const getSearchCollapsed = (state: State) => state.searchCollapsed;
|
||||
export const getSearchMinified = (state: State) => state.searchMinified;
|
||||
export const getMenuVisible = (state: State) => state.menuVisible;
|
||||
export const getExtent = (state: State) => state.extent;
|
||||
export const getOverlayLayers = (state: State) => state.overlayLayers;
|
||||
export const getBaseLayers = (state: State) => state.baseLayers;
|
||||
export const getProjection = (state: State) => state.projection;
|
||||
export const getSelectedBaseLayer = (state: State) => state.selectedBaseLayer;
|
||||
export const getSelectedOverlayLayer = (state: State) => state.selectedOverlayLayer;
|
||||
export const getQuery = (state: State) => state.query;
|
||||
export const getSelectedItemLayer = (state: State) => state.selectedItemLayer;
|
||||
export const getPeriod = (state:State) => state.period;
|
||||
|
||||
export const selectMapState = createFeatureSelector<State>(MODULE_NAME);
|
||||
export const selectGetMapState= createSelector(selectMapState, getMapState);
|
||||
export const selectGetParentCode = createSelector(selectMapState, getParentCode);
|
||||
export const selectGetFeatures = createSelector(selectMapState, getFeatures);
|
||||
export const selectGetPanelVisible = createSelector(selectMapState, getPanelVisible);
|
||||
export const selectGetPanelCollapsed = createSelector(selectMapState, getPanelCollapsed);
|
||||
export const selectGetSelectedFeature = createSelector(selectMapState, getSelectedFeature);
|
||||
export const selectGetSelectedItem = createSelector(selectMapState, getSelectedItem);
|
||||
export const selectGetQueryState = createSelector(selectMapState, getQueryState);
|
||||
export const selectGetClearEnabled = createSelector(selectMapState, getClearEnabled);
|
||||
export const selectGetSearchCollapsed = createSelector(selectMapState, getSearchCollapsed);
|
||||
export const selectGetSearchMinified = createSelector(selectMapState, getSearchMinified);
|
||||
export const selectGetMenuVisible = createSelector(selectMapState, getMenuVisible);
|
||||
export const selectGetExtent = createSelector(selectMapState, getExtent);
|
||||
export const selectGetOverlayLayers = createSelector(selectMapState, getOverlayLayers);
|
||||
export const selectGetBaseLayers = createSelector(selectMapState, getBaseLayers);
|
||||
export const selectGetProjection = createSelector(selectMapState, getProjection);
|
||||
export const selectGetSelectedBaseLayer = createSelector(selectMapState, getSelectedBaseLayer);
|
||||
export const selectGetSelectedOverlayLayer = createSelector(selectMapState, getSelectedOverlayLayer);
|
||||
export const selectGetQuery = createSelector(selectMapState, getQuery);
|
||||
export const selectGetSelectedItemLayer = createSelector(selectMapState, getSelectedItemLayer);
|
||||
export const selectGetPeriod = createSelector(selectMapState, getPeriod);
|
||||
|
||||
|
||||
import { tassign } from 'tassign';
|
||||
import { IItem,Item } from '@farmmaps/common';
|
||||
import { IItemLayer,ItemLayer} from '../models/item.layer';
|
||||
import { IMapState} from '../models/map.state';
|
||||
import { IQueryState} from '../models/query.state';
|
||||
import { IPeriodState} from '../models/period.state';
|
||||
import * as mapActions from '../actions/map.actions';
|
||||
import {commonActions} from '@farmmaps/common';
|
||||
import { createSelector, createFeatureSelector } from '@ngrx/store';
|
||||
|
||||
import {Feature} from 'ol';
|
||||
|
||||
import { ROUTER_NAVIGATION, RouterNavigationAction } from '@ngrx/router-store';
|
||||
|
||||
import { MODULE_NAME } from '../module-name';
|
||||
|
||||
const startDate:Date = new Date(new Date(Date.now()).getFullYear(), new Date(Date.now()).getMonth() - 3, 1);
|
||||
const endDate:Date = new Date(Date.now());
|
||||
|
||||
export const initialQueryState: IQueryState = {
|
||||
itemCode: null,
|
||||
parentCode: null,
|
||||
level: 1,
|
||||
itemType: null,
|
||||
bboxFilter: false,
|
||||
query: null,
|
||||
tags: null,
|
||||
endDate: null,
|
||||
startDate: null,
|
||||
bbox: []
|
||||
};
|
||||
|
||||
export interface State {
|
||||
period:IPeriodState,
|
||||
mapState: IMapState,
|
||||
viewExtent: number[],
|
||||
queryState: IQueryState,
|
||||
query:IQueryState,
|
||||
parentCode: string,
|
||||
features: Array<Feature>,
|
||||
panelVisible: boolean,
|
||||
panelCollapsed: boolean,
|
||||
selectedFeature: Feature,
|
||||
selectedItem:IItem,
|
||||
clearEnabled: boolean,
|
||||
searchCollapsed: boolean,
|
||||
searchMinified: boolean,
|
||||
menuVisible: boolean,
|
||||
extent: number[],
|
||||
baseLayers: Array<IItemLayer>
|
||||
overlayLayers: Array<IItemLayer>,
|
||||
selectedItemLayer: IItemLayer,
|
||||
projection: string,
|
||||
selectedBaseLayer: IItemLayer,
|
||||
selectedOverlayLayer: IItemLayer
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
period: {
|
||||
startDate: startDate,
|
||||
endDate: endDate
|
||||
},
|
||||
mapState: {
|
||||
zoom: 8,
|
||||
rotation: 0,
|
||||
xCenter: 5.377554,
|
||||
yCenter: 52.162422,
|
||||
baseLayerCode: ""
|
||||
},
|
||||
viewExtent:[],
|
||||
queryState: tassign(initialQueryState),
|
||||
query: tassign(initialQueryState),
|
||||
parentCode: null,
|
||||
features: [],
|
||||
panelVisible: false,
|
||||
panelCollapsed: false,
|
||||
selectedFeature: null,
|
||||
selectedItem: null,
|
||||
clearEnabled: false,
|
||||
searchCollapsed: true,
|
||||
searchMinified:false,
|
||||
menuVisible: true,
|
||||
extent: null,
|
||||
baseLayers: [],
|
||||
overlayLayers: [],
|
||||
projection: "EPSG:3857",
|
||||
selectedBaseLayer: null,
|
||||
selectedOverlayLayer: null,
|
||||
selectedItemLayer: null
|
||||
}
|
||||
|
||||
export function reducer(state = initialState, action: mapActions.Actions | commonActions.Actions | RouterNavigationAction): State {
|
||||
switch (action.type) {
|
||||
case ROUTER_NAVIGATION: {
|
||||
let a = action as RouterNavigationAction;
|
||||
return tassign(state);
|
||||
}
|
||||
case mapActions.SETMAPSTATE: {
|
||||
let a = action as mapActions.SetMapState;
|
||||
return tassign(state, {
|
||||
mapState: a.mapState
|
||||
});
|
||||
}
|
||||
case mapActions.SETQUERYSTATE: {
|
||||
let a = action as mapActions.SetQueryState;
|
||||
return tassign(state, { queryState: tassign(a.queryState )});
|
||||
}
|
||||
case mapActions.SETSTATE: {
|
||||
let a = action as mapActions.SetState;
|
||||
return tassign(state, { mapState: tassign(a.mapState), queryState: tassign(a.queryState)});
|
||||
}
|
||||
case mapActions.SETVIEWEXTENT: {
|
||||
let a = action as mapActions.SetViewExtent;
|
||||
return tassign(state, { viewExtent: a.extent });
|
||||
}
|
||||
case mapActions.SETPARENT: {
|
||||
let a = action as mapActions.SetParent;
|
||||
return tassign(state, {
|
||||
parentCode : a.parentCode
|
||||
});
|
||||
}
|
||||
case mapActions.STARTSEARCHSUCCESS: {
|
||||
let a = action as mapActions.StartSearchSuccess;
|
||||
return tassign(state, {
|
||||
panelVisible: true,
|
||||
clearEnabled: true,
|
||||
searchMinified: true,
|
||||
features: a.features
|
||||
});
|
||||
}
|
||||
case mapActions.SELECTFEATURE: {
|
||||
let a = action as mapActions.SelectFeature;
|
||||
return tassign(state, {
|
||||
selectedFeature: state.selectedItem?state.selectedFeature: a.feature
|
||||
});
|
||||
}
|
||||
case mapActions.SELECTITEM: {
|
||||
return tassign(state, {
|
||||
selectedItem: null,
|
||||
searchMinified:false,
|
||||
selectedItemLayer: null,
|
||||
features:[]
|
||||
});
|
||||
}
|
||||
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);
|
||||
}
|
||||
return tassign(state, {
|
||||
selectedItem: a.item,
|
||||
selectedItemLayer: itemLayer,
|
||||
panelVisible: a.item != null,
|
||||
clearEnabled: a.item != null,
|
||||
searchCollapsed: false,
|
||||
searchMinified: true,
|
||||
queryState: tassign(state.queryState, {itemCode:a.item ? a.item.code:null})
|
||||
});
|
||||
}
|
||||
case mapActions.STARTSEARCH: {
|
||||
let a = action as mapActions.StartSearch;
|
||||
return tassign(state, {
|
||||
selectedItem: null,
|
||||
selectedItemLayer:null,
|
||||
queryState: tassign(a.queryState),
|
||||
searchCollapsed: false,
|
||||
searchMinified: true,
|
||||
menuVisible:false
|
||||
});
|
||||
}
|
||||
case mapActions.DOQUERY: {
|
||||
let a = action as mapActions.DoQuery;
|
||||
return tassign(state, {
|
||||
query: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] })});
|
||||
}
|
||||
case mapActions.ADDFEATURESUCCESS: {
|
||||
let a = action as mapActions.AddFeatureSuccess;
|
||||
let features = state.features.slice();
|
||||
features.push(a.feature);
|
||||
return tassign(state, {
|
||||
panelVisible: true,
|
||||
selectedFeature: a.feature,
|
||||
menuVisible: false,
|
||||
extent: a.feature.getGeometry().getExtent(),
|
||||
searchCollapsed: false,
|
||||
clearEnabled:true,
|
||||
features:features
|
||||
});
|
||||
}
|
||||
case mapActions.UPDATEFEATURESUCCESS: {
|
||||
let a = action as mapActions.UpdateFeatureSuccess;
|
||||
let features: any[] = [];
|
||||
var index = -1;
|
||||
for (var i = 0; i < state.features.length; i++) {
|
||||
if (state.features[i].getId() == a.feature.getId()) {
|
||||
features.push(a.feature);
|
||||
} else {
|
||||
features.push(state.features[i]);
|
||||
}
|
||||
}
|
||||
return tassign(state, { features: features });
|
||||
}
|
||||
case mapActions.EXPANDSEARCH: {
|
||||
return tassign(state, { searchCollapsed: false });
|
||||
}
|
||||
case mapActions.COLLAPSESEARCH: {
|
||||
return tassign(state, { searchCollapsed: state.panelVisible ? false: true});
|
||||
}
|
||||
case mapActions.TOGGLEMENU: {
|
||||
return tassign(state, { menuVisible: !state.menuVisible });
|
||||
}
|
||||
case mapActions.SETEXTENT: {
|
||||
let a = action as mapActions.SetExtent;
|
||||
return tassign(state, { extent: a.extent });
|
||||
}
|
||||
case mapActions.ADDLAYER: {
|
||||
let a = action as mapActions.AddLayer;
|
||||
let itemLayers = state.overlayLayers.slice(0);
|
||||
let itemLayer = new ItemLayer(a.item);
|
||||
itemLayer.layerIndex = a.layerIndex == -1 ? 0 : a.layerIndex;
|
||||
itemLayers.push(itemLayer);
|
||||
return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer });
|
||||
}
|
||||
case mapActions.REMOVELAYER: {
|
||||
let a = action as mapActions.RemoveLayer;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
var selectedOverlayLayer: IItemLayer = null;
|
||||
if (i>0 && state.overlayLayers.length > 1)
|
||||
selectedOverlayLayer = state.overlayLayers[i - 1];
|
||||
else if (i == 0 && state.overlayLayers.length > 1)
|
||||
selectedOverlayLayer = state.overlayLayers[i + 1];
|
||||
newLayers.splice(i, 1);
|
||||
return tassign(state, { overlayLayers: newLayers, selectedOverlayLayer: selectedOverlayLayer });
|
||||
}
|
||||
case mapActions.SETVISIBILITY: {
|
||||
let a = action as mapActions.SetVisibility;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].visible = a.visibility;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
case mapActions.SETOPACITY: {
|
||||
let a = action as mapActions.SetOpacity;
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].opacity = a.opacity;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
case mapActions.SETLAYERINDEX: {
|
||||
let a = action as mapActions.SetLayerIndex;
|
||||
if (a.itemLayer == null) {
|
||||
var newItemlayer = new ItemLayer(state.selectedItemLayer.item);
|
||||
newItemlayer.layerIndex = a.layerIndex;
|
||||
return tassign(state, { selectedItemLayer: newItemlayer})
|
||||
} else {
|
||||
let newLayers = state.overlayLayers.slice(0);
|
||||
let i = state.overlayLayers.indexOf(a.itemLayer);
|
||||
newLayers[i].layerIndex = a.layerIndex;
|
||||
return tassign(state, { overlayLayers: newLayers });
|
||||
}
|
||||
}
|
||||
case mapActions.LOADBASELAYERSSUCCESS: {
|
||||
let a =action as mapActions.LoadBaseLayersSuccess;
|
||||
let baseLayers:ItemLayer[] = [];
|
||||
for (let item of a.items) {
|
||||
var l = new ItemLayer(item);
|
||||
l.visible = false;
|
||||
baseLayers.push(l);
|
||||
}
|
||||
var selectedBaseLayer: IItemLayer = null;
|
||||
var mapState = tassign(state.mapState);
|
||||
console.debug(`Base layerload: ${mapState.baseLayerCode}`)
|
||||
if (baseLayers.length > 0 && mapState.baseLayerCode != "") {
|
||||
selectedBaseLayer = baseLayers.filter(layer => layer.item.code === mapState.baseLayerCode)[0];
|
||||
selectedBaseLayer.visible = true;
|
||||
} else if (baseLayers.length > 0) {
|
||||
selectedBaseLayer = baseLayers[0];
|
||||
selectedBaseLayer.visible = true;
|
||||
mapState.baseLayerCode = selectedBaseLayer.item.code;
|
||||
}
|
||||
return tassign(state, { mapState:mapState, baseLayers: baseLayers, selectedBaseLayer: selectedBaseLayer });
|
||||
}
|
||||
case mapActions.SELECTBASELAYER: {
|
||||
let a = action as mapActions.SelectBaseLayer;
|
||||
let baseLayers = state.baseLayers.slice(0);
|
||||
baseLayers.forEach((l) => l.visible = false);
|
||||
let i = state.baseLayers.indexOf(a.itemLayer);
|
||||
baseLayers[i].visible = true;
|
||||
var mapState = tassign(state.mapState);
|
||||
mapState.baseLayerCode = a.itemLayer.item.code;
|
||||
return tassign(state, {mapState:mapState, baseLayers:baseLayers,selectedBaseLayer:a.itemLayer });
|
||||
}
|
||||
case mapActions.SELECTOVERLAYLAYER: {
|
||||
let a = action as mapActions.SelectOverlayLayer;
|
||||
return tassign(state, { selectedOverlayLayer: a.itemLayer });
|
||||
}
|
||||
case commonActions.ESCAPE: {
|
||||
let a = action as commonActions.Escape;
|
||||
let newQueryState = tassign(state.queryState, { query: null, tags: null, itemCode: null, parentCode: null, itemType: null });
|
||||
if (a.escapeKey) {
|
||||
return tassign(state, {
|
||||
panelVisible: false,
|
||||
panelCollapsed:false,
|
||||
selectedItem: null,
|
||||
selectedItemLayer: null,
|
||||
selectedFeature: null,
|
||||
queryState: newQueryState,
|
||||
clearEnabled: false,
|
||||
searchCollapsed: true,
|
||||
searchMinified: false,
|
||||
menuVisible:false,
|
||||
features: [],
|
||||
query:initialState.query
|
||||
});
|
||||
} else {
|
||||
return tassign(state, {});
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getMapState = (state: State) => state.mapState;
|
||||
export const getParentCode = (state: State) => state.parentCode;
|
||||
export const getFeatures = (state: State) => state.features;
|
||||
export const getPanelVisible = (state: State) => state.panelVisible;
|
||||
export const getPanelCollapsed = (state: State) => state.panelCollapsed;
|
||||
export const getSelectedFeature = (state: State) => state.selectedFeature;
|
||||
export const getSelectedItem = (state: State) => state.selectedItem;
|
||||
export const getQueryState = (state: State) => state.queryState;
|
||||
export const getClearEnabled = (state: State) => state.clearEnabled;
|
||||
export const getSearchCollapsed = (state: State) => state.searchCollapsed;
|
||||
export const getSearchMinified = (state: State) => state.searchMinified;
|
||||
export const getMenuVisible = (state: State) => state.menuVisible;
|
||||
export const getExtent = (state: State) => state.extent;
|
||||
export const getOverlayLayers = (state: State) => state.overlayLayers;
|
||||
export const getBaseLayers = (state: State) => state.baseLayers;
|
||||
export const getProjection = (state: State) => state.projection;
|
||||
export const getSelectedBaseLayer = (state: State) => state.selectedBaseLayer;
|
||||
export const getSelectedOverlayLayer = (state: State) => state.selectedOverlayLayer;
|
||||
export const getQuery = (state: State) => state.query;
|
||||
export const getSelectedItemLayer = (state: State) => state.selectedItemLayer;
|
||||
export const getPeriod = (state:State) => state.period;
|
||||
|
||||
export const selectMapState = createFeatureSelector<State>(MODULE_NAME);
|
||||
export const selectGetMapState= createSelector(selectMapState, getMapState);
|
||||
export const selectGetParentCode = createSelector(selectMapState, getParentCode);
|
||||
export const selectGetFeatures = createSelector(selectMapState, getFeatures);
|
||||
export const selectGetPanelVisible = createSelector(selectMapState, getPanelVisible);
|
||||
export const selectGetPanelCollapsed = createSelector(selectMapState, getPanelCollapsed);
|
||||
export const selectGetSelectedFeature = createSelector(selectMapState, getSelectedFeature);
|
||||
export const selectGetSelectedItem = createSelector(selectMapState, getSelectedItem);
|
||||
export const selectGetQueryState = createSelector(selectMapState, getQueryState);
|
||||
export const selectGetClearEnabled = createSelector(selectMapState, getClearEnabled);
|
||||
export const selectGetSearchCollapsed = createSelector(selectMapState, getSearchCollapsed);
|
||||
export const selectGetSearchMinified = createSelector(selectMapState, getSearchMinified);
|
||||
export const selectGetMenuVisible = createSelector(selectMapState, getMenuVisible);
|
||||
export const selectGetExtent = createSelector(selectMapState, getExtent);
|
||||
export const selectGetOverlayLayers = createSelector(selectMapState, getOverlayLayers);
|
||||
export const selectGetBaseLayers = createSelector(selectMapState, getBaseLayers);
|
||||
export const selectGetProjection = createSelector(selectMapState, getProjection);
|
||||
export const selectGetSelectedBaseLayer = createSelector(selectMapState, getSelectedBaseLayer);
|
||||
export const selectGetSelectedOverlayLayer = createSelector(selectMapState, getSelectedOverlayLayer);
|
||||
export const selectGetQuery = createSelector(selectMapState, getQuery);
|
||||
export const selectGetSelectedItemLayer = createSelector(selectMapState, getSelectedItemLayer);
|
||||
export const selectGetPeriod = createSelector(selectMapState, getPeriod);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user