Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassMapPinExample: GlassExample {5 public static let componentID = "glass-map-pin"67 private struct Place: Identifiable {8 let id: String9 let title: String10 let content: GlassMapPinContent11 let tint: GlassColorToken12 /// Position in the unit square of the placeholder map.13 let position: UnitPoint14 }1516 /// Fictitious places.17 private let places = [18 Place(id: "cafe", title: "Café Exemple", content: .symbol("cup.and.saucer.fill"), tint: .primary, position: UnitPoint(x: 0.25, y: 0.3)),19 Place(id: "museum", title: "Musée fictif des très longs noms de lieux", content: .symbol("building.columns.fill"), tint: .accent, position: UnitPoint(x: 0.7, y: 0.25)),20 Place(id: "price", title: "Listing A-12", content: .text("$1.2M"), tint: .success, position: UnitPoint(x: 0.5, y: 0.55)),21 Place(id: "warning", title: "Road works", content: .symbol("exclamationmark.triangle.fill"), tint: .warning, position: UnitPoint(x: 0.2, y: 0.75)),22 ]23 @State private var selection: String? = "cafe"2425 public init() {}2627 public var body: some View {28 GeometryReader { proxy in29 SampleMapBackdrop()30 .overlay {31 ForEach(places) { place in32 Button {33 selection = selection == place.id ? nil : place.id34 } label: {35 GlassMapPin(place.content, title: place.title, tint: place.tint, isSelected: selection == place.id)36 }37 .buttonStyle(.plain)38 .position(x: proxy.size.width * place.position.x, y: proxy.size.height * place.position.y)39 }40 // Cluster markers: the count comes from the map engine, the pin only formats it.41 GlassMapPin(clusterCount: 12)42 .position(x: proxy.size.width * 0.8, y: proxy.size.height * 0.6)43 GlassMapPin(clusterCount: 1_340, title: "Downtown")44 .position(x: proxy.size.width * 0.75, y: proxy.size.height * 0.8)45 }46 }47 }48}4950#Preview("GlassMapPin") { GlassMapPinExample().glassTheme(.solar) }51