]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapBlockers.swift
d943ba8bb61a8a72f00379518b111c10a17659b7
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapBlockers.swift
1 import SwiftUI
2
3 struct MapBlockers: View {
4
5 let mapSize: CGSize
6 let vertexSize: CGSize
7 let blockers: [Blocker]
8
9 let cornerSize = CGSize(width: 2.0, height: 2.0)
10
11 var body: some View {
12 ForEach(blockers, id: \.id) { vertex in
13 Path { path in
14 path.addRoundedRect(
15 in: CGRect(
16 origin: CGPoint(
17 x: w(vertex.position.x) + 3 * vertexSize.width,
18 y: h(vertex.position.y) - vertexSize.height * 2 / 3),
19 size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2)
20 ), cornerSize: cornerSize)
21 }.fill(Color.map.blockerColor)
22 }
23 }
24
25 func h(_ dimension: CGFloat) -> CGFloat {
26 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
27 }
28
29 func w(_ dimension: CGFloat) -> CGFloat {
30 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
31 }
32 }
33
34 struct MapBlockers_Previews: PreviewProvider {
35 static var previews: some View {
36 MapBlockers(
37 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
38 blockers: [
39 Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)),
40 Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)),
41 ])
42 }
43 }