From 412d95f07aaffc65b6474a597b997e1d740ae4ed Mon Sep 17 00:00:00 2001 From: uwap Date: Fri, 27 Oct 2017 16:43:17 +0200 Subject: [PATCH] First sketch of layers --- .flowconfig | 1 + src/appbar.js | 14 ++++++++++++++ src/config.js | 19 ++++++++++++++++++- src/index.jsx | 3 +-- src/map.js | 19 ++++++++++++++----- src/state.js | 3 ++- types/types.js | 14 +++++++++++--- webpack.config.js | 2 +- 8 files changed, 62 insertions(+), 13 deletions(-) diff --git a/.flowconfig b/.flowconfig index da47905..6b800d7 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,4 +1,5 @@ [ignore] +.*node_modules/react-event-listener/.* [include] src/ diff --git a/src/appbar.js b/src/appbar.js index 4ff1165..e7d7cf6 100644 --- a/src/appbar.js +++ b/src/appbar.js @@ -4,11 +4,24 @@ import AppBar from "material-ui/AppBar"; import CircularProgress from "material-ui/CircularProgress"; import MapIcon from "material-ui/svg-icons/maps/map"; import PhonelinkOffIcon from "material-ui/svg-icons/hardware/phonelink-off"; +import LayersIcon from "material-ui/svg-icons/maps/layers"; import IconMenu from "material-ui/IconMenu"; import IconButton from "material-ui/IconButton"; import MenuItem from "material-ui/MenuItem"; import { orange400, grey50 } from "material-ui/styles/colors"; +const TopBarLayerSelector = (props: Object) => ( + + + } + style={{width:48, height:48}}> + + +) + const TopBarIndicatorMenu = (props: Object) => ( ( } + iconElementRight={} className="nav" />); diff --git a/src/config.js b/src/config.js index 7f9c5e7..2083a4b 100644 --- a/src/config.js +++ b/src/config.js @@ -212,7 +212,24 @@ const config : Config = { } ] } - } + }, + layers: [ + { + image: "img/layers/rzl/rooms.png", + forceVisibility: "on", + name: "RaumZeitLabor" + }, + { + image: "img/layers/rzl/details.png", + forceVisibility: "on", + name: "Details" + }, + { + image: "img/layers/rzl/labels.png", + forceVisibility: "on", + name: "Labels" + } + ] }; export default config; diff --git a/src/index.jsx b/src/index.jsx index 6fb8e87..f16f446 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -45,8 +45,7 @@ return ( - + );} diff --git a/src/map.js b/src/map.js index 0809212..55c703b 100644 --- a/src/map.js +++ b/src/map.js @@ -6,6 +6,7 @@ import R from "ramda"; import Config from "./config"; import { Actions } from "./state"; import { keyOf } from "./util"; +import { store } from "./state"; import ActionInfo from 'material-ui/svg-icons/action/info'; import ReactDOM from "react-dom"; @@ -34,18 +35,26 @@ const Markers = (props) => R.values(R.mapObjIndexed((el,key) => ( iconSize: Leaflet.point(32,32) })}> props.store.dispatch({type: Actions.CHANGE_UI, payload: key})} - onClose={() => props.store.dispatch({type: Actions.CHANGE_UI})}> + onOpen={() => store.dispatch({type: Actions.CHANGE_UI, payload: key})} + onClose={() => store.dispatch({type: Actions.CHANGE_UI})}> {el.name} ), R.propOr({}, "controls", Config))); -const SpaceMap = (props: Object) => ( +const Layer = (layer: Layer, bounds: Array>) => ( + +); + +const visibleLayers = (state: State) => R.filter( + x => (x.forceVisibility == null && R.contains(state.visibleLayers, x.image)) + || x.forceVisibility == "on", Config.layers) + +const SpaceMap = (props: { state: State, width: number, height: number, + zoom: number, image: string}) => ( - + {R.map(x => Layer(x, [c([0,0]), c([props.width, props.height])]), visibleLayers(props.state))} {Markers(props)} ); diff --git a/src/state.js b/src/state.js index b2af3dd..22d4218 100644 --- a/src/state.js +++ b/src/state.js @@ -17,7 +17,8 @@ const initState : State = { topic => { return { internal: keyOf(topic.values, topic.defaultValue), actual: topic.defaultValue - }}, Config.topics) + }}, Config.topics), + visibleLayers: [] }; const onMessage = (state: State, action: StateAction) => { diff --git a/types/types.js b/types/types.js index cfe6b3a..6c2daea 100644 --- a/types/types.js +++ b/types/types.js @@ -41,7 +41,8 @@ declare type Controls = Map; declare type Config = { topics: Topics, - controls: Controls + controls: Controls, + layers: Array }; declare type State = { @@ -53,10 +54,17 @@ declare type State = { // topic, for example given by: // values: { off: "OFF", on: "ON" } // and actual is the value of that or whatever is given by mqtt. - values: Map + values: Map, + visibleLayers: Array +}; + +declare type Layer = { + image: string, + name: string, + forceVisibility?: "on"|"off" }; declare type StateAction = { type: "DISCONNECT" | "CONNECT" | "MESSAGE" | "UI_POPUP", payload?: any -} +}; diff --git a/webpack.config.js b/webpack.config.js index 4126c0f..28967d4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,7 +13,7 @@ module.exports = { extensions: ['.js', '.jsx'] }, entry: [ - path.resolve(__dirname, 'src/index.js') + path.resolve(__dirname, 'src/index.jsx') ], output: { path: path.resolve(__dirname, 'dist'),