SPB Git

Repository Public MIT

glass-map-pin.md 3.5 KB

# GlassMapPin

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

swift
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

swift
// 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 .isSelected trait; 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 title has 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.
Files main
Menu

Theme