2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 import { IActionHandler } from '../../../../framework/src/flux/action';
20 import { Feature } from "../model/Feature";
21 import { HighlightLinkAction, HighlightSiteAction, ZoomToSearchResultAction, AddAlarmAction, SetCoordinatesAction, SetStatistics, SetIconSwitchAction, RemoveHighlightingAction } from '../actions/mapActions';
23 export type location = {lat: number, lon:number}
25 export type mapState = {
26 selectedLink: Feature | null,
27 selectedSite: Feature | null,
28 zoomToElement: location | null,
29 alarmlement: Feature|null,
33 statistics:{links: string, sites: string},
34 allowIconSwitch: boolean
37 const initialState: mapState ={
45 statistics:{links:"Not counted yet.", sites: "Not counted yet."},
49 export const MapReducer: IActionHandler<mapState> = (state=initialState, action: any) => {
51 if(action instanceof HighlightLinkAction){
53 state = Object.assign({}, state, {selectedSite: null, selectedLink:{type: "Feature", geometry:{type:"LineString", coordinates:[[action.link.locationA.lon,action.link.locationA.lat ],[action.link.locationB.lon,action.link.locationB.lat ]]}}})
57 else if(action instanceof HighlightSiteAction){
59 state = Object.assign({}, state, {selectedLink: null, selectedSite:{type: "Feature", properties: {id: action.site.name, type:action.site.type}, geometry:{type:"Point", coordinates:[action.site.geoLocation.lon,action.site.geoLocation.lat ]}}})
61 }else if (action instanceof ZoomToSearchResultAction){
62 state = Object.assign({}, state, {zoomToElement:{lat: action.lat, lon: action.lon}});
63 }else if (action instanceof AddAlarmAction){
64 state = Object.assign({}, state, {alarmlement:action.element});
66 }else if(action instanceof SetCoordinatesAction){
67 state = Object.assign({}, state, {lat:action.lat, lon: action.lon, zoom:action.zoom});
69 }else if(action instanceof SetStatistics){
70 state = Object.assign({}, state, {statistics:{sites: action.siteCount, links: action.linkCount}});
72 }else if (action instanceof SetIconSwitchAction){
73 state = Object.assign({}, state, {allowIconSwitch: action.enable});
75 }else if(action instanceof RemoveHighlightingAction){
76 state = Object.assign({}, state, {selectedLink: null, selectedSite:null})