diff options
Diffstat (limited to 'Map/MapRenderComponents/MapStages.swift')
| -rw-r--r-- | Map/MapRenderComponents/MapStages.swift | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Map/MapRenderComponents/MapStages.swift b/Map/MapRenderComponents/MapStages.swift new file mode 100644 index 0000000..052a315 --- /dev/null +++ b/Map/MapRenderComponents/MapStages.swift @@ -0,0 +1,60 @@ +import SwiftUI + +struct MapStages: View { + + @Environment(\.colorScheme) var colorScheme + + let mapSize: CGSize + let lineWidth: CGFloat + let stages: [CGFloat] + let opacity = 0.1 + + var color: MapColor { + MapColor.colorForScheme(colorScheme) + } + + var body: some View { + + ZStack(alignment: .topLeading) { + Path { path in + path.addRect(CGRect(x: 0, y: 0, width: w(stages[0]), height: mapSize.height)) + }.fill(color.stages.i) + Path { path in + path.addRect( + CGRect(x: w(stages[0]), y: 0, width: w(stages[1]) - w(stages[0]), height: mapSize.height)) + }.fill(color.stages.ii) + Path { path in + path.addRect( + CGRect(x: w(stages[1]), y: 0, width: w(stages[2]) - w(stages[1]), height: mapSize.height)) + }.fill(color.stages.iii) + Path { path in + path.addRect( + CGRect(x: w(stages[2]), y: 0, width: mapSize.width - w(stages[2]), height: mapSize.height) + ) + }.fill(color.stages.iv) + + Path { path in + path.move(to: CGPoint(x: w(stages[0]), y: 0)) + path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height)) + path.move(to: CGPoint(x: w(stages[1]), y: 0)) + path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height)) + path.move(to: CGPoint(x: w(stages[2]), y: 0)) + path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height)) + path.move(to: CGPoint(x: w(stages[0]), y: 0)) + path.closeSubpath() + }.strokedPath(StrokeStyle(lineWidth: lineWidth, dash: [10.0])).stroke(color.foreground) + } + } + + func w(_ dimension: CGFloat) -> CGFloat { + max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) + } +} + +struct MapStages_Previews: PreviewProvider { + static var previews: some View { + MapStages( + mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0), + stages: [25.0, 50.0, 75.0]) + } +} |