3 struct MapVertices: View {
5 @Environment(\.colorScheme) var colorScheme
10 let padding = CGFloat(4.0)
13 MapColor.colorForScheme(colorScheme)
17 ForEach(vertices, id: \.id) { vertex in
21 origin: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y)), size: vertexSize
23 }.fill(color.foreground)
24 Text(vertex.label).foregroundColor(color.secondary).offset(
26 width: w(vertex.position.x) + vertexSize.width + padding,
27 height: h(vertex.position.y)))
31 func h(_ dimension: CGFloat) -> CGFloat {
32 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
35 func w(_ dimension: CGFloat) -> CGFloat {
36 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
40 struct MapVertices_Previews: PreviewProvider {
41 static var previews: some View {
43 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
45 Vertex(id: 0, label: "A", position: CGPoint(x: 50.0, y: 50.0)),
46 Vertex(id: 0, label: "A", position: CGPoint(x: 10.0, y: 20.0)),