SPB Git

Repository Public MIT

GlassMapPanelExample.swift 4.1 KB 96 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Maps/GlassMapPanelExample.swift8// Module           : Examples9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0313//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 GlassMapPanelExample: GlassExample {45    public static let componentID = "glass-map-panel"46    @State private var isPresented = false47    @State private var detent = GlassMapPanelDetent.half48    @State private var selection: String?49    @State private var query = ""50    @State private var engine = SampleMapEngine()5152    /// Fictitious results.53    private let results = [54        GlassMapResult(id: "1", title: "Café Exemple", subtitle: "Sample data · café", systemImage: "cup.and.saucer.fill", detail: "120 m"),55        GlassMapResult(id: "2", title: "Bibliothèque fictive", subtitle: "Sample data · library", systemImage: "books.vertical.fill", detail: "350 m"),56        GlassMapResult(id: "3", title: "A place with a very long name that wraps over several lines in a narrow panel", subtitle: "Sample data · 1.2 km"),57        GlassMapResult(id: "4", title: "مقهى تجريبي", subtitle: "Sample data · 2 km", systemImage: "cup.and.saucer"),58        GlassMapResult(id: "5", title: "Parc d’essai", subtitle: "Sample data · 2.4 km", systemImage: "tree"),59    ]6061    private var filteredResults: [GlassMapResult] {62        let trimmed = query.trimmingCharacters(in: .whitespaces)63        return trimmed.isEmpty ? results : results.filter { $0.title.localizedStandardContains(trimmed) }64    }6566    public init() {}6768    public var body: some View {69        GlassMapPanel("Nearby", isPresented: $isPresented, detent: $detent) {70            SampleMapBackdrop(heading: engine.heading ?? 0, zoom: engine.zoomScale)71                .overlay(alignment: .topTrailing) {72                    // The map and its controls stay usable while the panel is open.73                    GlassMapControls(engine: engine)74                        .padding()75                }76                .overlay(alignment: .bottomTrailing) {77                    GlassButton(isPresented ? "Hide results" : "Show results", systemImage: "list.bullet") {78                        isPresented.toggle()79                    }80                    .padding()81                }82        } content: {83            VStack(alignment: .leading, spacing: 12) {84                TextField("Search sample places", text: $query)85                    .textFieldStyle(.roundedBorder)86                GlassMapResultList(results: filteredResults, selection: selection) { result in87                    selection = result.id88                    detent = .peek89                }90            }91        }92    }93}9495#Preview("GlassMapPanel") { GlassMapPanelExample().glassTheme(.ocean) }96
Files main
Menu

Theme