From f561064e6c0cd3c6aa1466882c72bbac53edae90 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Fri, 18 Jan 2019 11:19:40 +0000 Subject: [PATCH] shapes -> lines between points --- src/components/Map.jsx | 1 + src/components/MapNarratives.jsx | 1 + src/components/MapShapes.jsx | 59 ++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/components/Map.jsx b/src/components/Map.jsx index c8c0a4e..44dd942 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -151,6 +151,7 @@ class Map extends React.Component { renderShapes() { return ( {steps.map((s, idx) => this.renderNarrativeStep(idx, n))} diff --git a/src/components/MapShapes.jsx b/src/components/MapShapes.jsx index 19a842c..087d422 100644 --- a/src/components/MapShapes.jsx +++ b/src/components/MapShapes.jsx @@ -1,33 +1,56 @@ -import React from 'react'; +import React from 'react' +import { Portal } from 'react-portal' -function MapShapes({ map, shapes, mapTransformX, mapTransformY }) { +function MapShapes({ svg, map, shapes, mapTransformX, mapTransformY }) { function projectPoint(location) { - const latLng = new L.LatLng(location[0], location[1]); + const latLng = new L.LatLng(location[0], location[1]) return { x: map.latLngToLayerPoint(latLng).x + mapTransformX, y: map.latLngToLayerPoint(latLng).y + mapTransformY - }; + } } - function renderShape(shape) { - const coords = shape.points.map(projectPoint) - return coords.map(pt => ( -
- {shape.name} -
- )); + function renderShape(shape, lineStyle) { + const lineCoords = [] + const points = shape.points + .map(projectPoint) + + points.forEach((p1, idx) => { + if (idx < shape.points.length - 1) { + const p2 = points[idx+1] + lineCoords.push({ + x1: p1.x, + y1: p1.y, + x2: p2.x, + y2: p2.y + }) + } + }) + + return lineCoords.map(coords => ( + + + )) } - if (!shapes || !shapes.length) return null; + if (!shapes || !shapes.length) return null return ( -
- {shapes.map(renderShape)} -
+ + + {shapes.map(s => renderShape(s, { + strokeWidth: 3, + stroke: 'blue' + }))} + + ) } -export default MapShapes; +export default MapShapes