clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

main
atlas / internal / generate / icons / icons.go
icons.go 2.4K
1// Package icons carries the standard icon library a source may name instead of2// shipping artwork of its own.3//4// Some publishers have no artwork at all. The IAU Gazetteer names two thousand5// places on Mars and draws none of them; a city's open data publishes geometry6// and attributes and nothing to put on a pin. What those sources do have is a7// vocabulary -- a crater, a mountain, a monument -- so instead of inventing8// pictures they name one, through the registered atlas.icon.std attribute, and9// composition makes good on the name here.10//11// The library is a curated subset of Mapbox's Maki set, public-domain map12// glyphs vendored so that resolution is as offline as everything else. Only the13// names some source actually speaks are vendored: the embed is the vocabulary,14// and a name outside it fails the build one table edit before it would have15// shipped a bundle with a hole in its legend.16//17// A resolved standard icon is one more asset in a bundle's icons tree, tinted18// and haloed like any glyph a source shipped itself. The application never19// learns this package exists.20//21// # Naming a glyph is not choosing one22//23// This package resolves what a source already named. Deciding that a collection24// which named nothing should carry a standard glyph -- and which -- is a25// judgement made after two sources have been folded together, and belongs to the26// enrich lane's stdicons enricher (issue #5 ยง5.3). The two meet at the27// attribute: an enricher writes the name, and packing it is the same work as28// packing any other artwork.29package icons3031import (32 "embed"33 "fmt"34 "strings"35)3637//go:embed standard/maki/*.svg standard/maki/LICENSE.txt38var standard embed.FS3940// Standard resolves a set/name reference from the atlas.icon.std attribute to41// the glyph's bytes and the asset name it ships under.42//43// The asset name spells its provenance -- std--maki-mountain.svg -- so a44// bundle's icon listing reads honestly, and a source's own artwork can never be45// shadowed by a standard glyph that happened to share its key.46func Standard(ref string) (data []byte, asset string, err error) {47 set, name, found := strings.Cut(ref, "/")48 if !found || set != "maki" {49 return nil, "", fmt.Errorf("standard icon %q names no vendored set", ref)50 }51 data, err = standard.ReadFile("standard/maki/" + name + ".svg")52 if err != nil {53 return nil, "", fmt.Errorf("standard icon %q is not vendored", ref)54 }55 return data, "std--maki-" + name + ".svg", nil56}