SPB Git

Repository Public MIT

GlassMapPinExample.swift 3.9 KB 91 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Maps/GlassMapPinExample.swift8// Module           : Examples9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassMapPinExample: GlassExample {45    public static let componentID = "glass-map-pin"4647    private struct Place: Identifiable {48        let id: String49        let title: String50        let content: GlassMapPinContent51        let tint: GlassColorToken52        /// Position in the unit square of the placeholder map.53        let position: UnitPoint54    }5556    /// Fictitious places.57    private let places = [58        Place(id: "cafe", title: "Café Exemple", content: .symbol("cup.and.saucer.fill"), tint: .primary, position: UnitPoint(x: 0.25, y: 0.3)),59        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)),60        Place(id: "price", title: "Listing A-12", content: .text("$1.2M"), tint: .success, position: UnitPoint(x: 0.5, y: 0.55)),61        Place(id: "warning", title: "Road works", content: .symbol("exclamationmark.triangle.fill"), tint: .warning, position: UnitPoint(x: 0.2, y: 0.75)),62    ]63    @State private var selection: String? = "cafe"6465    public init() {}6667    public var body: some View {68        GeometryReader { proxy in69            SampleMapBackdrop()70                .overlay {71                    ForEach(places) { place in72                        Button {73                            selection = selection == place.id ? nil : place.id74                        } label: {75                            GlassMapPin(place.content, title: place.title, tint: place.tint, isSelected: selection == place.id)76                        }77                        .buttonStyle(.plain)78                        .position(x: proxy.size.width * place.position.x, y: proxy.size.height * place.position.y)79                    }80                    // Cluster markers: the count comes from the map engine, the pin only formats it.81                    GlassMapPin(clusterCount: 12)82                        .position(x: proxy.size.width * 0.8, y: proxy.size.height * 0.6)83                    GlassMapPin(clusterCount: 1_340, title: "Downtown")84                        .position(x: proxy.size.width * 0.75, y: proxy.size.height * 0.8)85                }86        }87    }88}8990#Preview("GlassMapPin") { GlassMapPinExample().glassTheme(.solar) }91
Files main
Menu

Theme