Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Apps/ORIXMaps/Sources/Tools/MeasurePanel.swift10// Module : Tools11// 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 ORIXMapRenderer91import ORIXMapStyle92import SwiftUI9394/// Distance and area measurement: tap the map to add points.95struct MeasurePanel: View {96 @Environment(AppModel.self) private var app97 @State private var points: [Coordinate] = []98 @State private var closed = false99100 var body: some View {101 VStack(alignment: .leading, spacing: ORIX.Spacing.l) {102 PanelHeader(title: String(localized: "Measure"), subtitle: String(localized: "Tap the map to add points")) { close() }103 HStack(spacing: ORIX.Spacing.l) {104 StatView("Distance", value: app.settings.formatter.distance(Geodesy.length(of: closed && points.count > 2 ? points + [points[0]] : points)))105 StatView("Area", value: closed && points.count > 2 ? app.settings.formatter.area(Geodesy.area(of: points)) : "—")106 StatView("Points", value: "\(points.count)")107 }108 AdaptiveStack {109 Button("Undo") { if !points.isEmpty { points.removeLast() }; if points.count < 3 { closed = false } }110 .buttonStyle(SecondaryButtonStyle()).disabled(points.isEmpty)111 Button(closed ? "Open shape" : "Close shape") { closed.toggle() }112 .buttonStyle(SecondaryButtonStyle()).disabled(points.count < 3)113 Button("Clear") { points = []; closed = false }114 .buttonStyle(SecondaryButtonStyle()).disabled(points.isEmpty)115 }116 NoticeView("Distances are measured on a sphere along straight segments; they are not survey-grade.")117 Spacer(minLength: 0)118 }119 .padding(ORIX.Spacing.l)120 .onAppear {121 app.tapInterceptor = { c in points.append(c); return true }122 }123 .onDisappear { app.tapInterceptor = nil; app.map.setOverlay(OverlayID.measure, features: []) }124 .onChange(of: points) { _, _ in redraw() }125 .onChange(of: closed) { _, _ in redraw() }126 .accessibilityElement(children: .contain)127 .accessibilityIdentifier("measure.panel")128 }129130 private func redraw() {131 var features = points.map { OverlayFeature(.point($0)) }132 if closed, points.count > 2 {133 features.append(OverlayFeature(.polygon([points])))134 features.append(OverlayFeature(.line(points + [points[0]])))135 } else if points.count > 1 {136 features.append(OverlayFeature(.line(points)))137 }138 app.map.setOverlay(OverlayID.measure, features: features)139 }140141 private func close() {142 app.tapInterceptor = nil143 app.map.setOverlay(OverlayID.measure, features: [])144 app.route = .home145 }146}147