Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Maps/GlassMapControlsExample.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 SPGlassKit43#if canImport(MapKit)44import MapKit45#endif4647public struct GlassMapControlsExample: GlassExample {48 public static let componentID = "glass-map-controls"49 @State private var engine = SampleMapEngine()50 #if canImport(MapKit)51 @State private var usesMapKit = false52 @State private var mapKitEngine = GlassMapKitEngine(53 position: .camera(MapCamera(centerCoordinate: CLLocationCoordinate2D(latitude: 45.4215, longitude: -75.6972), distance: 6_000, heading: 30))54 )55 #endif5657 public init() {}5859 public var body: some View {60 VStack(spacing: 12) {61 #if canImport(MapKit)62 Toggle("Use the MapKit adapter (loads map tiles)", isOn: $usesMapKit)63 .padding(.horizontal)64 if usesMapKit {65 mapKitMap66 } else {67 placeholderMap68 }69 #else70 placeholderMap71 #endif72 }73 }7475 /// A provider-independent engine: the controls only see `GlassMapEngine`.76 private var placeholderMap: some View {77 SampleMapBackdrop(heading: engine.heading ?? 0, zoom: engine.zoomScale)78 .overlay(alignment: .topTrailing) {79 GlassMapControls(engine: engine) {80 GlassCompass(heading: engine.heading) { engine.resetNorth() }81 GlassIconButton(systemImage: "rotate.right", accessibilityLabel: "Rotate the sample map") {82 engine.rotate(by: 45)83 }84 }85 .padding()86 }87 .overlay(alignment: .bottom) {88 GlassMapControls(canZoomIn: engine.canZoomIn, canZoomOut: engine.canZoomOut, axis: .horizontal, size: .small) {89 engine.zoomIn()90 } onZoomOut: {91 engine.zoomOut()92 }93 .padding(.bottom, 40)94 }95 }9697 #if canImport(MapKit)98 private var mapKitMap: some View {99 Map(position: $mapKitEngine.position)100 .onMapCameraChange(frequency: .continuous) { context in101 mapKitEngine.cameraChanged(context.camera)102 }103 .overlay(alignment: .topTrailing) {104 GlassMapControls(engine: mapKitEngine)105 .padding()106 }107 }108 #endif109}110111#Preview("GlassMapControls") { GlassMapControlsExample().glassTheme(.ocean) }112