Skip to content

Commit

Permalink
refactor styles as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Dec 30, 2024
1 parent 90009ea commit f8faf97
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions frontend/src/Map/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,13 @@ function DataLayer(){
type: 'FeatureCollection',
features: data.corridors.flatMap(c=>c.geojsonFeaturesPoint)
}
const nodeStyle = {
id:'corridor-nodes',
type:'circle',
paint:{
'circle-radius': 8,
'circle-color': 'red',
'circle-opacity': 0.2,
'circle-stroke-width': 2,
'circle-stroke-color': 'red'
}
}
const lineStyle = {
id:'corridor-links',
type:'line',
paint:{'line-width': 3, 'line-color': 'black'},
layout: {'line-cap': 'round'}
}
return (
<>
<Source id='corridor-links' type='geojson'data={corridorsGeojsonLinear}>
<Layer {...lineStyle}/>
<Layer {...styles.corridors.lines}/>
</Source>
<Source id='corridor-nodes' type='geojson'data={corridorsGeojsonPoint}>
<Layer {...nodeStyle}/>
<Layer {...styles.corridors.nodes}/>
</Source>
</>
)
Expand Down Expand Up @@ -107,7 +90,34 @@ function NodeLayer(){
geometry: node.geometry
}) )
}
const style = {
return (
<Source id='nodes' type='geojson'data={nodesGeoJSON}>
<Layer {...styles.nodes}/>
</Source>
)
}

const styles = {
corridors: {
nodes: {
id:'corridor-nodes',
type:'circle',
paint:{
'circle-radius': 8,
'circle-color': 'red',
'circle-opacity': 0.2,
'circle-stroke-width': 2,
'circle-stroke-color': 'red'
}
},
lines: {
id:'corridor-links',
type:'line',
paint:{'line-width': 3, 'line-color': 'black'},
layout: {'line-cap': 'round'}
}
},
nodes: {
id:'nodes',
type:'circle',
paint:{
Expand All @@ -118,9 +128,4 @@ function NodeLayer(){
'circle-stroke-color': 'grey'
}
}
return (
<Source id='nodes' type='geojson'data={nodesGeoJSON}>
<Layer {...style}/>
</Source>
)
}
}

0 comments on commit f8faf97

Please sign in to comment.