From 10b62e1e23e44e0ea2b5d3ff365032f1a1df3cd4 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Fri, 18 Jan 2019 12:09:37 +0000 Subject: [PATCH] add optional styling for shapes from redux store --- src/components/Map.jsx | 31 ++++++++--------- .../presentational/Map/Narratives.jsx | 8 ++--- src/components/presentational/Map/Shapes.jsx | 33 ++++++++++--------- src/store/initial.js | 7 ++++ 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/components/Map.jsx b/src/components/Map.jsx index c1df193..97a4160 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -9,15 +9,14 @@ import 'leaflet'; import { isNotNullNorUndefined } from '../js/utilities'; -import MapSites from './presentational/Map/Sites.jsx'; -import MapShapes from './presentational/Map/Shapes.jsx'; -import MapEvents from './presentational/Map/Events.jsx'; -import MapSelectedEvents from './presentational/Map/SelectedEvents.jsx'; -import MapNarratives from './presentational/Map/Narratives.jsx'; -import MapDefsMarkers from './presentational/Map/DefsMarkers.jsx'; +import Sites from './presentational/Map/Sites.jsx'; +import Shapes from './presentational/Map/Shapes.jsx'; +import Events from './presentational/Map/Events.jsx'; +import SelectedEvents from './presentational/Map/SelectedEvents.jsx'; +import Narratives from './presentational/Map/Narratives.jsx'; +import DefsMarkers from './presentational/Map/DefsMarkers.jsx'; class Map extends React.Component { - constructor() { super(); this.projectPoint = this.projectPoint.bind(this) @@ -147,7 +146,7 @@ class Map extends React.Component { renderSites() { return ( - ) } renderNarratives() { return ( - @@ -198,7 +198,7 @@ class Map extends React.Component { renderEvents() { return ( - - + ) } @@ -278,7 +278,8 @@ function mapStateToProps(state) { }, ui: { dom: state.ui.dom, - narratives: state.ui.style.narratives + narratives: state.ui.style.narratives, + shapes: state.ui.style.shapes } } } diff --git a/src/components/presentational/Map/Narratives.jsx b/src/components/presentational/Map/Narratives.jsx index e2ffbea..84452e8 100644 --- a/src/components/presentational/Map/Narratives.jsx +++ b/src/components/presentational/Map/Narratives.jsx @@ -1,17 +1,17 @@ import React from 'react' import { Portal } from 'react-portal' -function MapNarratives ({ narrativeProps, onSelectNarrative, svg, narrative, narratives, projectPoint }) { +function MapNarratives ({ styles, onSelectNarrative, svg, narrative, narratives, projectPoint }) { function getNarrativeStyle(narrativeId) { - const styleName = (narrativeId && narrativeId in narrativeProps) + const styleName = (narrativeId && narrativeId in styles) ? narrativeId : 'default' - return narrativeProps[styleName] + return styles[styleName] } function getStepStyle(name) { if (name === 'None') return null - return narrativeProps.stepStyles[name] + return styles.stepStyles[name] } function hasNoLocation(step) { diff --git a/src/components/presentational/Map/Shapes.jsx b/src/components/presentational/Map/Shapes.jsx index 44514bc..5fab671 100644 --- a/src/components/presentational/Map/Shapes.jsx +++ b/src/components/presentational/Map/Shapes.jsx @@ -1,8 +1,8 @@ import React from 'react' import { Portal } from 'react-portal' -function MapShapes({ svg, shapes, projectPoint }) { - function renderShape(shape, lineStyle) { +function MapShapes({ svg, shapes, projectPoint, styles }) { + function renderShape(shape) { const lineCoords = [] const points = shape.points .map(projectPoint) @@ -19,15 +19,21 @@ function MapShapes({ svg, shapes, projectPoint }) { } }) - return lineCoords.map(coords => ( - - - )) + return lineCoords.map(coords => { + const shapeStyles = (shape.name in styles) + ? styles[shape.name] + : styles.default + + return ( + + + ) + }) } if (!shapes || !shapes.length) return null @@ -35,10 +41,7 @@ function MapShapes({ svg, shapes, projectPoint }) { return ( - {shapes.map(s => renderShape(s, { - strokeWidth: 3, - stroke: 'blue' - }))} + {shapes.map(renderShape)} ) diff --git a/src/store/initial.js b/src/store/initial.js index b30daea..9c3326a 100644 --- a/src/store/initial.js +++ b/src/store/initial.js @@ -102,6 +102,13 @@ const initial = { stroke: 'red', strokeWidth: 3 } + }, + shapes: { + default: { + stroke: 'blue', + strokeWidth: 3, + opacity: 0.9 + } } }, dom: {