GlassMapPin
Configurable marker with selection and an accessible label; clustering is left to the map engine.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-map-pin
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-map-pinCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-map-pin |
|---|---|
| Module | SPGlassMaps |
| Kind | content-component — an opaque tinted pin with a tail; no glass |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Maps/GlassMapPinExample.swift |
Minimal usage
GlassMapPin(.symbol("fork.knife"), title: "Chez Sample")Variants
| Variant | Use |
|---|---|
.symbol(name) | An SF Symbol in the marker. Always give a title: it is the accessibility label. |
.text(string) | A short text (price, letter, rank), cut after 4 characters. |
init(clusterCount:cap:) | A cluster marker: a disc with a halo and no tail, showing the localised count, or the cap followed by "+" ("99+"). |
isSelected: true | Larger pin, thicker outline and the title on a chip under the tip. |
tint: | Any colour role of the theme (.primary, .accent, .success, .warning, …). Text and symbol take the legible colour for that fill. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
content | GlassMapPinContent | — | What the marker shows. |
title | String? | nil | Name of the place: accessibility label, and visible label when selected. |
tint | GlassColorToken | .primary (.secondary for clusters) | Colour role of the marker. |
isSelected | Bool | false | Selected appearance and trait. |
clusterCount | Int | — | Number of places the cluster stands for; negative values count as 0. |
cap | Int | 99 | Largest count shown as a number. |
Anchoring. The tip of the tail is the bottom centre of the view in every state: anchor the annotation there (Annotation(…, anchor: .bottom) in MapKit). The title of a selected pin hangs under the tip without taking part in the layout, so selecting a pin does not move it. A cluster has no tail: anchor it at its centre. GlassMapPinShape (the capsule with its tail) is public for hosts that draw their own marker.
States
Normal and selected. The pin has no pressed state of its own: it is a plain view, and the tap belongs to the annotation of the map engine (or to a Button wrapped around it).
Advanced example
// MapKit; any other engine hosts the same view in its own annotation type.
Map(position: $engine.position, selection: $selection) {
ForEach(places) { place in
Annotation(place.name, coordinate: place.coordinate, anchor: .bottom) {
GlassMapPin(.symbol(place.symbol), title: place.name, tint: .accent, isSelected: selection == place.id)
}
.tag(place.id)
.annotationTitles(.hidden)
}
ForEach(clusters) { cluster in // computed by the host or the engine
Annotation("", coordinate: cluster.coordinate) {
GlassMapPin(clusterCount: cluster.count, cap: 999)
}
}
}Accessibility
- One element per pin. Its label is the title, or the marker text when there is no title; clusters read "132 places" (after the title if there is one).
- A selected pin has the
.isSelectedtrait; selection is also visible by size, outline and the title, not by colour. - The marker grows with Dynamic Type (
@ScaledMetric).
Limits
- Clustering is left to the map engine: the pin does not know coordinates, does not merge and does not split. It only formats the count it is given.
- A symbol-only pin without
titlehas an empty accessibility label. - The marker is a capsule without a pointer tail; anchor the annotation on its centre or its bottom edge as the design requires.
Example
import SwiftUI
import SPGlassKit
public struct GlassMapPinExample: GlassExample {
public static let componentID = "glass-map-pin"
private struct Place: Identifiable {
let id: String
let title: String
let content: GlassMapPinContent
let tint: GlassColorToken
/// Position in the unit square of the placeholder map.
let position: UnitPoint
}
/// Fictitious places.
private let places = [
Place(id: "cafe", title: "Café Exemple", content: .symbol("cup.and.saucer.fill"), tint: .primary, position: UnitPoint(x: 0.25, y: 0.3)),
Place(id: "museum", title: "Musée fictif des très longs noms de lieux", content: .symbol("building.columns.fill"), tint: .accent, position: UnitPoint(x: 0.7, y: 0.25)),
Place(id: "price", title: "Listing A-12", content: .text("$1.2M"), tint: .success, position: UnitPoint(x: 0.5, y: 0.55)),
Place(id: "warning", title: "Road works", content: .symbol("exclamationmark.triangle.fill"), tint: .warning, position: UnitPoint(x: 0.2, y: 0.75)),
]
@State private var selection: String? = "cafe"
public init() {}
public var body: some View {
GeometryReader { proxy in
SampleMapBackdrop()
.overlay {
ForEach(places) { place in
Button {
selection = selection == place.id ? nil : place.id
} label: {
GlassMapPin(place.content, title: place.title, tint: place.tint, isSelected: selection == place.id)
}
.buttonStyle(.plain)
.position(x: proxy.size.width * place.position.x, y: proxy.size.height * place.position.y)
}
// Cluster markers: the count comes from the map engine, the pin only formats it.
GlassMapPin(clusterCount: 12)
.position(x: proxy.size.width * 0.8, y: proxy.size.height * 0.6)
GlassMapPin(clusterCount: 1_340, title: "Downtown")
.position(x: proxy.size.width * 0.75, y: proxy.size.height * 0.8)
}
}
}
}
#Preview("GlassMapPin") { GlassMapPinExample().glassTheme(.solar) }
Registry entry
| Identifier | glass-map-pin |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassMapPinContent, GlassMapPinFormatting, GlassMapPinLayout, GlassMapPinShape, GlassMapPin |
| Licence | MIT |
| Manifest | manifest.json |
Files
Maps/Maps/GlassMapPin.swift11563 bytes · sha256 34af5140ae29…