SPB Git

Repository Public BSD-3-Clause

PlaceCard.swift 7.4 KB 160 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Sources/Panel/PlaceCard.swift10// Module           : Panel11// Repository       : https://git.spboucher.ai/orix-maps12// Created          : 2026-11-2513// Last Modified    : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ORIXDesignSystem89import ORIXGeoCore90import ORIXMapStyle91import SwiftUI92import UIKit9394/// The card of a selected place. Coordinates are always shown and usable, with or without an address.95struct PlaceCard: View {96    @Environment(AppModel.self) private var app97    let place: PlaceSelection98    @State private var saving = false99100    var body: some View {101        let saved = app.library.savedPlace(near: place.coordinate)102        ScrollView {103            VStack(alignment: .leading, spacing: ORIX.Spacing.l) {104                PanelHeader(title: saved?.name ?? place.title, subtitle: place.subtitle) { app.clearSelection() }105                if let note = saved?.note, !note.isEmpty {106                    Label(note, systemImage: "note.text").font(.subheadline).foregroundStyle(.secondary)107                }108                AdaptiveStack {109                    Button { app.startDirections(to: place) } label: { Label("Directions", systemImage: "arrow.triangle.turn.up.right.diamond.fill") }110                        .buttonStyle(PrimaryButtonStyle(tint: AppColor.primaryFill))111                        .accessibilityIdentifier("place.directions")112                    Button { saving = true } label: { Label(saved == nil ? "Save" : "Saved", systemImage: saved == nil ? "bookmark" : "bookmark.fill") }113                        .buttonStyle(SecondaryButtonStyle())114                        .accessibilityIdentifier("place.save")115                }116                VStack(alignment: .leading, spacing: ORIX.Spacing.s) {117                    Text("Coordinates").font(.caption).foregroundStyle(.secondary)118                    ForEach(CoordinateText.Style.allCases, id: \.self) { style in119                        let text = CoordinateText.format(place.coordinate, style: style)120                        Button {121                            UIPasteboard.general.string = text122                            app.showToast(String(localized: "Coordinates copied"))123                        } label: {124                            HStack {125                                Text(verbatim: text).font(.callout.monospacedDigit()).foregroundStyle(.primary)126                                Spacer()127                                Image(systemName: "doc.on.doc").font(.footnote).foregroundStyle(.secondary)128                            }129                            .frame(minHeight: 36)130                            .contentShape(.rect)131                        }132                        .buttonStyle(.plain)133                        .accessibilityLabel(Text("Copy \(text)"))134                    }135                }136                .padding(ORIX.Spacing.m)137                .background(.quaternary.opacity(0.6), in: .rect(cornerRadius: ORIX.Radius.control))138                if app.directions.points.count >= 2, !app.directions.isNavigating {139                    Button { app.map.setOverlay(OverlayID.selection, features: []); app.route = .directions; app.directions.addStop(place) } label: { Label("Add stop to the current route", systemImage: "plus.circle") }140                        .buttonStyle(SecondaryButtonStyle())141                }142                ShareLink(item: shareText) { Label("Share", systemImage: "square.and.arrow.up") }143                    .buttonStyle(SecondaryButtonStyle())144                    .accessibilityIdentifier("place.share")145            }146            .padding(ORIX.Spacing.l)147        }148        .accessibilityIdentifier("place.card")149        .sheet(isPresented: $saving) { SavePlaceSheet(selection: place, existing: app.library.savedPlace(near: place.coordinate)) }150        .task(id: place.id) { await app.library.record(place: place) }151    }152153    /// A `geo:` URI plus a readable line: works in any app, depends on no service.154    private var shareText: String {155        let c = place.coordinate156        let geo = String(format: "geo:%.6f,%.6f", locale: Locale(identifier: "en_US_POSIX"), c.latitude, c.longitude)157        return "\(place.title)\n\(CoordinateText.format(c, style: .decimalDegrees))\n\(geo)"158    }159}160
Files main
Menu

Theme