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/Map/MapImages.swift10// Module : Map11// 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 ORIXMapStyle89import UIKit9091/// Bitmaps of the style images, drawn from SF Symbols on demand (the renderer asks for an image the first time a92/// style layer needs it). No sprite sheet is shipped.93enum MapImages {94 static func image(named name: String, dark: Bool) -> UIImage? {95 if let group = POIGroup.all.first(where: { $0.imageName == name }) {96 let c = dark ? group.nightColor : group.dayColor97 return badge(symbol: group.symbol, fill: UIColor(c), diameter: 26, symbolPoint: 13)98 }99 switch name {100 case OverlayID.pinImage: return pin(fill: UIColor(named: "AccentColor") ?? .systemTeal, symbol: "mappin")101 case OverlayID.selectionImage: return pin(fill: .systemRed, symbol: "circle.fill", scale: 1.15)102 case OverlayID.headingImage: return heading()103 case OverlayID.onewayImage: return symbol("arrow.right", point: 16, color: dark ? .white : .darkGray)104 default:105 // Custom pin icons are named "orix-pin-<sf symbol>-<hex colour>".106 if name.hasPrefix("orix-pin-") {107 let parts = name.dropFirst("orix-pin-".count).split(separator: "|")108 if parts.count == 2, let color = HexColor(String(parts[1])) { return pin(fill: UIColor(color), symbol: String(parts[0])) }109 }110 return nil111 }112 }113114 private static func symbol(_ name: String, point: CGFloat, color: UIColor, weight: UIImage.SymbolWeight = .bold) -> UIImage? {115 UIImage(systemName: name, withConfiguration: UIImage.SymbolConfiguration(pointSize: point, weight: weight))?.withTintColor(color, renderingMode: .alwaysOriginal)116 }117118 private static func badge(symbol name: String, fill: UIColor, diameter: CGFloat, symbolPoint: CGFloat) -> UIImage {119 let size = CGSize(width: diameter + 4, height: diameter + 4)120 return UIGraphicsImageRenderer(size: size).image { ctx in121 let rect = CGRect(x: 2, y: 2, width: diameter, height: diameter)122 ctx.cgContext.setShadow(offset: CGSize(width: 0, height: 0.5), blur: 1.5, color: UIColor.black.withAlphaComponent(0.25).cgColor)123 UIColor.white.setFill()124 UIBezierPath(ovalIn: rect).fill()125 ctx.cgContext.setShadow(offset: .zero, blur: 0, color: nil)126 fill.setFill()127 UIBezierPath(ovalIn: rect.insetBy(dx: 1.5, dy: 1.5)).fill()128 if let s = symbol(name, point: symbolPoint, color: .white, weight: .semibold) {129 let scale = min(1, (diameter - 9) / max(s.size.width, s.size.height))130 let w = s.size.width * scale, h = s.size.height * scale131 s.draw(in: CGRect(x: rect.midX - w / 2, y: rect.midY - h / 2, width: w, height: h))132 }133 }134 }135136 /// A drop-shaped pin whose tip is at the bottom centre (the style anchors it there).137 private static func pin(fill: UIColor, symbol name: String, scale: CGFloat = 1) -> UIImage {138 let w: CGFloat = 34 * scale, h: CGFloat = 44 * scale139 return UIGraphicsImageRenderer(size: CGSize(width: w + 6, height: h + 4)).image { ctx in140 let cg = ctx.cgContext141 cg.translateBy(x: 3, y: 1)142 let r = w / 2143 let path = UIBezierPath()144 path.addArc(withCenter: CGPoint(x: r, y: r), radius: r, startAngle: .pi * 0.85, endAngle: .pi * 0.15, clockwise: true)145 path.addQuadCurve(to: CGPoint(x: r, y: h), controlPoint: CGPoint(x: r + r * 0.55, y: h * 0.78))146 path.addQuadCurve(to: CGPoint(x: r - r * cos(.pi * 0.15), y: r + r * sin(.pi * 0.15)), controlPoint: CGPoint(x: r - r * 0.55, y: h * 0.78))147 path.close()148 cg.setShadow(offset: CGSize(width: 0, height: 1.5), blur: 3, color: UIColor.black.withAlphaComponent(0.3).cgColor)149 UIColor.white.setFill(); path.fill()150 cg.setShadow(offset: .zero, blur: 0, color: nil)151 cg.saveGState()152 cg.translateBy(x: r, y: r); cg.scaleBy(x: 0.88, y: 0.9); cg.translateBy(x: -r, y: -r * 0.97)153 fill.setFill(); path.fill()154 cg.restoreGState()155 if let s = symbol(name, point: 14 * scale, color: .white, weight: .bold) {156 let k = min(1, (w * 0.5) / max(s.size.width, s.size.height))157 s.draw(in: CGRect(x: r - s.size.width * k / 2, y: r - s.size.height * k / 2, width: s.size.width * k, height: s.size.height * k))158 }159 }160 }161162 /// The heading wedge drawn under the position dot; it points up (north) and the style rotates it.163 private static func heading() -> UIImage {164 let size: CGFloat = 64165 return UIGraphicsImageRenderer(size: CGSize(width: size, height: size)).image { ctx in166 let c = CGPoint(x: size / 2, y: size / 2)167 let path = UIBezierPath()168 path.move(to: c)169 path.addArc(withCenter: c, radius: size / 2, startAngle: -.pi / 2 - 0.5, endAngle: -.pi / 2 + 0.5, clockwise: true)170 path.close()171 let accent = UIColor(named: "AccentColor") ?? .systemTeal172 let colors = [accent.withAlphaComponent(0.55).cgColor, accent.withAlphaComponent(0).cgColor] as CFArray173 ctx.cgContext.addPath(path.cgPath); ctx.cgContext.clip()174 if let g = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: colors, locations: [0, 1]) {175 ctx.cgContext.drawRadialGradient(g, startCenter: c, startRadius: 6, endCenter: c, endRadius: size / 2, options: [])176 }177 }178 }179}180181extension UIColor {182 convenience init(_ c: HexColor) {183 self.init(red: CGFloat(c.red) / 255, green: CGFloat(c.green) / 255, blue: CGFloat(c.blue) / 255, alpha: CGFloat(c.alpha) / 255)184 }185}186