[go: up one dir, main page]

VNX extensions

For VNX 0.11.0. Pre-release: these extensions and VNX itself may change at any time.

Agents do a great job of converting your files to VNX

Give your AI agent your trail data (GPX, KML, GeoJSON, spreadsheets or your own notes) and our VNX skill. It reads the files, builds the network and writes a VNX file that Viatrail opens.

Get the VNX skill

Give this prompt to your agent:

Convert my trail data to a Viatrail VNX file using the skill at https://viatrail.app/convert/SKILL.md. Follow its best practices.

Viatrail reads and writes VNX files. VNX defines trail networks, plans, tracks, points and areas, and it lets each application add its own data. This page lists what Viatrail adds. It is for developers and agents who want to read Viatrail's data from a VNX file, or write a file that Viatrail understands.

The general rules for extensions (data records, type IDs, application keys and attachments) are on vnx.tools. This page uses them and does not repeat them.

JSON Schema

Every type on this page is in one machine-readable file: viatrail-extensions.schema.json (JSON Schema 2020-12). The app's code generates it, so it matches the app. The tables below come from the same file.

Names and reading rules

Viatrail's type IDs and application keys all start with app.viatrail., because Viatrail owns the domain viatrail.app. Other applications must not define types under this prefix.

Viatrail reads two application keys: app.viatrail.datatypes (custom data types) and app.viatrail.rulesets (rule sets). The import reports any other application key and does not store it.

When Viatrail imports a file:

Data record types

Each record is an object in the data array of an item, with an @type and the fields below. Every field is optional. "Where" lists the places in a VNX document where Viatrail reads the type.

{
  "name": "Corrour bothy",
  "at": [-3.6878, 57.0221, 560],
  "data": [
    { "@type": "app.viatrail.shelter", "rating": 4, "booking": false, "beds": 8 },
    { "@type": "app.viatrail.water", "seasonal": false },
    { "@type": "app.viatrail.note", "text": "Burn **200 m** south. Bring a stove." }
  ]
}

Built-in types at a glance

The app supplies the label, hosts, fields and summary of each built-in type, so a file does not need to define them. A definition can name one of these types to change it in its folder and the folders below (see Two definitions of one type). It can add fields, change an enum's options, or replace the hosts or the summary. The type's name stays the app's. Tag, Photo and the internal types cannot be named.

TypeLabelHostsSummary
app.viatrail.campCampwaypointstars for rating
app.viatrail.shelterShelterwaypoint"★★★ · 4 beds"
app.viatrail.hotelHotelwaypoint"★★★★ · 12 rooms"
app.viatrail.shopShopwaypointthe resupply option
app.viatrail.settlementSettlementwaypoint, areanone
app.viatrail.waterWaterwaypoint"★★ · seasonal"
app.viatrail.tagTagall sixnone
app.viatrail.noteNoteall sixnone
app.viatrail.photoPhotoall sixnone
app.viatrail.routeRoutehighlightstars for rating
app.viatrail.terrainTerrainhighlightthe terrain option
app.viatrail.hazardHazardwaypoint, highlight, areathe first line of description

The app writes app.viatrail.routing and app.viatrail.compute-failed on arcs itself. A user never adds them, and they never title an item. In a routing record, the import reports a key that it does not define, in the record or in its config, as an unknown key. A source value that is not in the schema refuses the file. When source is "engine", config must have library-enabled, base-map-enabled, cross-country-enabled and forest-avoidance, or the import fails.

The app does not list Tag, Routing or Routing failed as data types in its menus, pickers or default rule set. Tag has its own chip control. A file can still hold records of all three, and the app imports and exports them unchanged.

app.viatrail.camp Camp

Where: points[], networks[].points[].

FieldTypeValuesMeaning
ratinginteger, 1 to 5 (stars)Overall rating?
flatinteger, 1 to 5 (stars)How flat is the ground?
shelteredinteger, 1 to 5 (stars)How sheltered is the camp from the wind?
waterinteger, 1 to 5 (stars)How convenient / clean is the water source?
bookingbooleanDoes the camp need booking?

app.viatrail.shelter Shelter

Where: points[], networks[].points[].

FieldTypeValuesMeaning
ratinginteger, 1 to 5 (stars)Overall rating?
bookingbooleanDoes the shelter need booking?
bedsintegerApproximately how many beds?

app.viatrail.hotel Hotel

Where: points[], networks[].points[].

FieldTypeValuesMeaning
ratinginteger, 1 to 5 (stars)Overall rating?
bookingbooleanDoes the hotel need booking?
roomsintegerApproximately how many rooms?

app.viatrail.shop Shop

Where: points[], networks[].points[].

FieldTypeValuesMeaning
resupplystringkiosk Kiosk, grocery Grocery, market MarketWhat can you resupply here?

app.viatrail.settlement Settlement

Where: points[], networks[].points[], areas[], networks[].areas[].

FieldTypeValuesMeaning
hotelsbooleanDoes this settlement have hotels?
resupplystringkiosk Kiosk, grocery Grocery, market MarketWhat can you resupply here?

app.viatrail.water Water

Where: points[], networks[].points[].

FieldTypeValuesMeaning
ratinginteger, 1 to 5 (stars)Overall rating?
seasonalbooleanIs this water source dry in some seasons?

app.viatrail.note Note

Where: networks[], tracks[], points[], networks[].points[], networks[].highlights[], plans[], areas[], networks[].areas[].

FieldTypeValuesMeaning
textstringText

app.viatrail.photo Photo

Where: networks[], tracks[], points[], networks[].points[], networks[].highlights[], plans[], areas[], networks[].areas[].

A data type definition cannot name this type. Its photos travel only in a .vnz, as the files it names.

FieldTypeValuesMeaning
photoslist of stringan archive entry, app.viatrail.photo/{id}.jpgPhotos

app.viatrail.route Route

Where: networks[].highlights[].

FieldTypeValuesMeaning
ratinginteger, 1 to 5 (stars)Overall rating?

app.viatrail.terrain Terrain

Where: networks[].highlights[].

FieldTypeValuesMeaning
terrainstringmajor_road Major Road, minor_road Minor Road, trail Trail, cross_country Cross-Country, bush_bash Bush BashTerrain type

app.viatrail.hazard Hazard

Where: points[], networks[].points[], networks[].highlights[], areas[], networks[].areas[].

FieldTypeValuesMeaning
descriptionstringDescription of the hazard

Internal types

The app does not list these as data types. Each one's own description says who may write it. Keep them unchanged when you write a file back.

app.viatrail.tag Tag

Internal. Where: networks[], tracks[], points[], networks[].points[], networks[].highlights[], plans[], areas[], networks[].areas[].

A free-text tag. Any application may write it. It is internal only in that the app does not list it as a data type: it shows tags as chips. A data type definition cannot name this type.

FieldTypeValuesMeaning
valuestringValue

app.viatrail.routing Routing (internal)

Internal. Where: plans[].arcs{}, networks[].arcs{}.

Written by Viatrail; do not write.

FieldTypeValuesMeaning
sourcestringengine, gpx-import, gps-recording, user-snap, user-drawn, copiedHow the arc's line was made. Only "engine" marks the arc as routed by an engine; with any other value, or no record, Viatrail does not route the arc again.
configobjectThe engine settings the arc was routed with. When source is "engine", config must have library-enabled, base-map-enabled, cross-country-enabled and forest-avoidance, or the import fails.

app.viatrail.compute-failed Routing failed

Internal. Where: plans[].arcs{}, networks[].arcs{}.

Written by Viatrail; do not write. Its presence on an arc says the engine could not route it, and the line is a straight placeholder. It has no fields.

No fields.

A record on an item whose app.viatrail. type the app does not know is kept as an unknown record. So is a record of a type in another namespace. On an arc, the import keeps only app.viatrail.routing and app.viatrail.compute-failed, and drops any other record with no report.

Photos

An app.viatrail.photo record holds an ordered list of photos for its item. In a VNX document, each photo is the entry name of a JPEG file in the same .vnz archive:

{ "@type": "app.viatrail.photo", "photos": ["app.viatrail.photo/3f2a9c41.jpg"] }

The files go in a folder named after the type, as VNX recommends (VNX §7.2):

doc.vnx
app.viatrail.photo/3f2a9c41.jpg
app.viatrail.photo/77b01e8d.jpg

Photo file rules

Each photo file must be:

The import drops a photo file that breaks one of these rules, and reports the item. It also drops, with a report, a photo that the record names and the archive does not hold. The rest of the item and the file import.

Look and behaviour

VNX defines no style. Viatrail carries how an item is drawn in data records of its own, one record type for each section of the app's style editor. Each record goes in the data array of the item it styles.

RecordEditor sectionOn
app.viatrail.style.markerMarkerpoints, areas, tracks, plans, networks
app.viatrail.style.lineLineareas, tracks, plans, networks
app.viatrail.style.fillFillareas
app.viatrail.style.cardCardpoints, areas, tracks, plans, networks
app.viatrail.behaviourBehaviourareas, tracks, plans, networks (a point is always selectable)

Highlights

A highlight is a light container for data records along a walk of its network's arcs. It has an optional name and no notes of its own. It has no look or behaviour records: the rules alone draw it. A look or behaviour record on a highlight is reported and not stored. With no name, its records title it in the app. A notes key on a highlight is not in VNX, so the reader reports it as an unknown key and drops it. The import trims a highlight's name, and a name of spaces alone is no name.

In GeoJSON and KML, the VNX writer names a highlight by its name. With no name, it gives the highlight a number that is unique in its network. A record's label is not a name, so a highlight titled only by its records gets a number too. GeoJSON puts the network's name in front ("Ridges / West ridge", "Ridges / 1"). KML writes the bare name in the network's folder ("West ridge", "1"). An import does not assume that a file came from Viatrail: a line's name becomes the highlight's name as the file spells it ("Ridges / 1" in GeoJSON, "1" in KML).

{
  "name": "Wild camp",
  "at": [-3.6878, 57.0221, 560],
  "data": [
    { "@type": "app.viatrail.camp", "rating": 4 },
    { "@type": "app.viatrail.style.marker", "icon": "lucide:tent", "hue": 105, "outline": "circle" },
    { "@type": "app.viatrail.style.card", "importance": 4, "show-card": "yes" }
  ]
}

app.viatrail.style.marker Marker

Where: points[], networks[].points[], plans[], tracks[], areas[], networks[].areas[], networks[].

The item's own marker. A rule styles markers with app.viatrail.style.marker.item and app.viatrail.style.marker.data instead. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.

FieldTypeValuesMeaning
iconstringAn icon: "lucide:<id>" for a Lucide icon or "emoji:<id>" for an emoji. "none" draws no glyph. An id the app does not have is dropped with a report.
hueinteger, 0 to 359
intensitystringpale, normal, intense
darknessstringlight, normal, dark
outlinestringcircle, square, hexagon, diamond, flag, none

app.viatrail.style.line Line style

Where: plans[], tracks[], areas[], networks[].areas[], networks[].

How the item's line is drawn: on a plan, a track, a network or an area. In a rule: the line of each item it matches. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.

FieldTypeValuesMeaning
hueinteger, 0 to 359
intensitystringpale, normal, intense
darknessstringlight, normal, dark
widthinteger2, 4, 6
casingstringlight, dark
stripestringnone, solid, dashes, dots
show-namestringyes, no

app.viatrail.style.fill Fill style

Where: areas[], networks[].areas[].

How an area is filled. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.

FieldTypeValuesMeaning
hueinteger, 0 to 359
intensitystringpale, normal, intense
darknessstringlight, normal, dark
strengthstringlight, medium, strong
patternstringsolid, hatch, none

app.viatrail.style.card Card

Where: points[], networks[].points[], plans[], tracks[], areas[], networks[].areas[], networks[].

The item's card on the map. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.

FieldTypeValuesMeaning
importanceinteger (any 32-bit whole number)Any whole number a 32-bit signed integer holds. The map places the labels of an item with a higher importance first. 0 is the default.
show-cardstringyes, no
tag-fillstringcard, solid

app.viatrail.behaviour Behaviour

Where: points[], networks[].points[], plans[], tracks[], areas[], networks[].areas[], networks[].

Whether a tap selects the item. In a rule, hide hides the items it matches; an item cannot hide itself. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.

FieldTypeValuesMeaning
hidestringyes, no
selectablestringyes, noWhether a tap on the map can select the item. It has no effect on a "waypoint" or a "highlight" item, which is always selectable; an item's own settings on one are refused. "waypoint" means a VNX point, top-level or in a network.

The marker shape used by markers in rules

FieldTypeValuesMeaning
iconstringAn icon: "lucide:<id>" for a Lucide icon or "emoji:<id>" for an emoji. "none" draws no glyph. An id the app does not have is dropped with a report.
hueinteger, 0 to 359
intensitystringpale, normal, intense
darknessstringlight, normal, dark
outlinestringcircle, square, hexagon, diamond, flag, none

Icon IDs

A marker's icon (on an item, in a rule, or in a custom data type) is one of three things:

ValueMeaning
lucide:<id>A Lucide icon. The id is Lucide's own icon name, for example lucide:tent or lucide:mountain-snow.
emoji:<id>An emoji, named by an id made from its Unicode name (below), for example emoji:tent for ⛺.
noneNo glyph: the marker is drawn with nothing in it.

Viatrail accepts only the ids in its two lists. They are published here so that a writer can look an id up:

An icon whose id is not in its list, a value with no lucide: or emoji: prefix, and a bare word such as tent are dropped with a report. The rest of the record is kept.

How an emoji id is made

The emoji set is Unicode Emoji 15.1: every fully-qualified emoji, without skin-tone variants. The id is the emoji's Unicode name, changed to ASCII snake_case in three steps:

  1. Spell # as "number sign" and * as "asterisk".
  2. Decompose the name (Unicode NFKD) and drop every character that is not ASCII. Accents go, and so does a curly apostrophe, with no space in its place.
  3. Lower-case it, change each run of characters other than a–z and 0–9 to one _, and trim _ from both ends.
EmojiUnicode nameValue
#️⃣keycap: #emoji:keycap_number_sign
🥇1st place medalemoji:1st_place_medal
🪅piñataemoji:pinata
🇨🇮flag: Côte d’Ivoireemoji:flag_cote_divoire

Style samples in notes

Any markdown text in Viatrail, such as the text of an app.viatrail.note record, can draw a small sample of a map style inline: a line, a marker or an area. The app draws it exactly as the map draws that style. Use samples to write a key that tells the reader what each style on the map means.

A sample is a markdown link with the viatrail-style: scheme:

[Main trail](viatrail-style:line?hue=120&width=4&stripe=dashes)
[Campsite](viatrail-style:marker?icon=lucide:tent&hue=30&outline=circle)
[Protected area](viatrail-style:area?fill-hue=120&fill-pattern=hatch&line-hue=120&line-stripe=dashes)

The keys

A line sample:

KeyValuesRequiredDefault
hue0 to 359yes
intensitypale, normal, intensenonormal
darknesslight, normal, darknonormal
width2, 4, 6no4
casinglight, darknodark
stripenone, solid, dashes, dotsnonone

A marker sample:

KeyValuesRequiredDefault
iconan icon ID with its set, such as lucide:tent or emoji:tent (see Icon IDs); not noneyes
hue0 to 359yes
intensitypale, normal, intensenonormal
darknesslight, normal, darknonormal
outlinecircle, square, hexagon, diamond, flag, nonenonone

An area sample has an outline and a fill. The outline takes the line keys with the prefix line-, and the fill takes these keys with the prefix fill-:

KeyValuesRequiredDefault
line-hue0 to 359yes
line-intensity, line-darkness, line-width, line-casing, line-stripeas for a linenoas for a line
fill-hue0 to 359yes
fill-intensitypale, normal, intensenonormal
fill-darknesslight, normal, darknonormal
fill-strengthlight, medium, strongnomedium
fill-patternsolid, hatch, nonenosolid

A sample that is not valid

A sample with an unknown kind, an unknown or repeated key, a value that is not in the tables, or a missing required key is not drawn. The app shows its label as plain text, and logs the problem. A sample with no label and an error shows nothing.

Other markdown viewers do not know the viatrail-style: scheme. They show the label as a link.

A key table

A key is a plain markdown table whose first column holds samples. Put it in the note of a network that uses several styles. When every cell of a table's header row is empty, the app does not show the header row.

| | |
|---|---|
| [](viatrail-style:line?hue=120&width=4) | Main trail |
| [](viatrail-style:line?hue=30&stripe=dots) | Alternative |
| [](viatrail-style:marker?icon=lucide:tent&hue=30) | Campsite |
| [](viatrail-style:area?fill-hue=120&line-hue=120&fill-pattern=hatch) | Protected area |

Custom data types

A data type definition tells Viatrail about records of a type that you own, for example org.example.rapid. Users can also make one in the app. With a definition, the app can:

Records of a type with no definition are still kept, and rules can still style them. But the settings page does not offer the type, and its records have no label or summary, so they never title an item.

Where a definition goes

Definitions travel in the top-level application key app.viatrail.datatypes. Its value is a list. Each entry is one data type set: a named set of types, which shows in the library like a folder's other items. Its keys are in the Data type set table below.

A type

Each entry of types describes one type. Its keys are in the Type table below.

The marker

marker is the type's own icon and colour. The app shows it on the type's page and on the Camps settings rows. On the map, a custom type a point can hold shows this marker with no rule needed; a rule set can change it. It is drawn in a circle, at normal intensity and darkness.

"marker": {"icon": "lucide:tent", "hue": 105}

Behaviours

behaviours is a list of names: plan, list and camp.

"behaviours": ["plan", "list", "camp"]

Labels and notes

A label is an object from language code to text:

"label": {"en": "Rapid", "fr": "Rapide"}

The app shows the text for the app language, else the English text.

A field and an option have a label too, and can have a note with the same shape. A note is a short help text that the settings page shows under the control. In the app, a custom field's note is its "Description", and a custom option has one too. The app edits them in the app language. An empty description removes the note in every language. A built-in option's note is the app's own, and the app does not edit it. An option that a folder adds to a built-in Choice can have its own note.

On the first definition of a built-in type, a built-in option's note is used only when the option also has its own label, and only when the app has no note of its own for that option (for example, Terrain's options have one). Any other note on a built-in option of that definition is one that the app never shows: the import removes it and reports it. A later definition of the same type does not change an option's note.

Hosts

hosts is a list of these:

HostItem
networka whole network
tracka track
waypointa waypoint, in the library or inside a network
highlighta highlight inside a network
plana plan in the library
areaan area, in the library or inside a network

Fields

Each entry of fields is one field. Its keys are in the Field table below. The settings page shows the fields in list order.

The kinds, and the value a record holds for each:

KindRecord value
texta string, one line
markdowna string, shown as markdown
booltrue or false
numbera number
integera whole number
starsa rating from 1 to 5. No rating is an absent key, not 0.
enumone option's value, a string
datea string: ISO 8601 in UTC with a Z, for example 2026-10-10T08:30:00Z

The kind reference is refused in a custom type.

Two definitions of one type

Two definitions in scope can name the same datatype. The app takes them in this order: the root's items first, then each folder's items down to the item's folder. In one folder, items go in order of name, then of id. In one item, types go in list order. A built-in type is always first: the app supplies it before any definition.

A later definition:

Names never change. The first definition that defines a type, a field or an option gives its label and note. A later definition's label for the same type, field name or option value is not used, even when a definition in between left the option out. A new field or a new option uses its own label. Labels are still required everywhere, because the folder decides whether a definition comes first.

A definition of a built-in type is different. The built-in type is always first, so its own name and the names of its own fields are always used, and the definition needs no label for them. The built-in type names an option of a built-in field, unless a definition gives the option a label. Then the first definition that labels it names it in that folder, language by language: in a language that the definition has, its label shows; in any other language, the built-in name shows. A field or an option that the built-in type does not have still needs a label.

On import, a type that restates a field of a built-in type with another kind is not imported, and the report says so.

For example, this definition extends the built-in Camp type with one field. It names the built-in type and gives only the new field, with no label or hosts:

{"datatype": "app.viatrail.camp",
 "fields": [{"name": "tents", "kind": "integer", "label": {"en": "Tents"}}]}

A complete example

This file holds one folder and one data type set:

{
  "vnx": "0.11.0",
  "folders": [{"id": "f1", "name": "Rivers"}],
  "app.viatrail.datatypes": [
    {
      "name": "Paddling types",
      "folder": "f1",
      "types": [
        {
          "datatype": "org.example.rapid",
          "label": {"en": "Rapid", "fr": "Rapide"},
          "hosts": ["waypoint"],
          "fields": [
            {
              "name": "grade",
              "kind": "enum",
              "label": {"en": "Grade", "fr": "Classe"},
              "options": [
                {"value": "2", "label": {"en": "Grade 2", "fr": "Classe 2"}},
                {"value": "3", "label": {"en": "Grade 3", "fr": "Classe 3"}},
                {"value": "4", "label": {"en": "Grade 4", "fr": "Classe 4"}, "note": {"en": "Look at it from the bank first."}}
              ]
            },
            {"name": "portages", "kind": "integer", "label": {"en": "Portages", "fr": "Portages"}},
            {"name": "notes", "kind": "markdown", "label": {"en": "Notes", "fr": "Notes"}}
          ],
          "summary": "{{option \"grade\"}}{{with whole .portages}}{{if ne . \"0\"}}, {{t \"portages\" .}}{{end}}{{end}}",
          "strings": {
            "portages": {
              "en": {"one": "{n} portage", "other": "{n} portages"},
              "fr": {"one": "{n} portage", "other": "{n} portages"}
            }
          }
        }
      ]
    }
  ]
}

A waypoint in the folder "Rivers" can then carry this record:

{"@type": "org.example.rapid", "grade": "3", "portages": 2}

In English, its summary is "Grade 3, 2 portages". If the waypoint has no name, its title is "Rapid · Grade 3, 2 portages".

Field tables

These tables come from the JSON Schema.

Data type set

FieldTypeValuesMeaning
name requiredstringThe data type set's name. It may be empty.
folderstringThe id of a folder in the same document. Absent or empty: the import places it where the user chooses. A folder the document does not have: the import places it there too, and reports it.
pinnedstringWhen the data type set was pinned: a VNX timestamp (§4.3).
types requiredlist of datatype-type

Type

One type. A type that breaks a rule is left out at import, alone, with a report; an unknown key is removed with a report.

FieldTypeValuesMeaning
datatype requiredstringThe @type of the records this type describes. Inside app.viatrail. it must be one of the built-in types a definition may name (x-nameable-built-in-types), spelled exactly: such a type is extended, not replaced.
labelobject: label-mapCustom types only, and required there: the type's name. An extended built-in type has the registry's name.
hostslist of stringsnetwork, track, waypoint, highlight, plan, areaCustom types only: the item kinds the type is meant for. Viatrail does not check it on import. "waypoint" means a VNX point, top-level or in a network.
fieldslist of datatype-field
summarystringA template for a one-line summary of a record. A fault drops the summary, not the type.
stringsobjectPhrases a summary can use: phrase key, then language, then a text or a text for each plural form. English is required, and a plural table needs every form the language uses.
behaviourslist of stringsplan, list, campCustom types only. plan: a highlight with a record of the type can start a plan along its line. list: the network lists the records of the type on its highlights. camp: a point with a record of the type can end a day of a plan.
markerobjectCustom types only: the type's icon and hue. Absent: lucide:shapes at hue 0. An unusable value is removed with a report, and the type then has that default.

Field

FieldTypeValuesMeaning
name requiredstringThe key in the record body.
kind requiredstringtext, markdown, bool, number, integer, stars, enum, date
labelobject: label-mapRequired, except on a field the extended built-in type already has.
noteobject: label-map
optionslist of datatype-optionThe values of an enum field. Kept but not used on a field of another kind.

Enum option

FieldTypeValuesMeaning
value requiredstring
labelobject: label-mapRequired, except on an option the extended built-in field already has.
noteobject: label-map

Label

Text by language: each key is two or three lowercase letters (en, fr, gsw); en-GB and EN are refused. English is required. A text may not be blank.

Summary templates

What a summary is

A summary is a short text about one record, for example "4 beds" or "Trail". The app shows it in two places:

If the summary is empty, the row and the title show the label alone.

A summary comes from the type's summary key: one Go text/template string. One template serves every language. Phrases in other languages come from the type's strings table (see Strings and plurals).

Only a file can supply strings. The app's type editor can change a template, but it cannot add or change phrases: it keeps the strings table that the file gave. So a template that uses t must come from a file. The one exception: a type that extends a built-in type already has the built-in type's phrases, and its template can use them.

The full Go template language is available: if, else, with, range, and, or, not, eq, printf, index, len and the rest. A template sees only the record and the helpers below. It cannot read files, use the network or start programs.

Template values

A template can read these values with a dot:

ValueWhat it is
.<field name>The record's value for a field that the definition names, for example .portages. A field that the record does not hold is its kind's zero value (see below).
.LangThe app language code, for example en or fr.

Do not name a field Lang. .Lang replaces it.

Field values

Every field that the definition names is present, with a value of this type:

KindValue in the templateWhen the record does not hold it
boola booleanfalse
number, integer, starsa floating-point number0
text, markdown, enum, datea string""

Notes on the Go template language

Helpers

These are all the helpers that a template can call:

HelperUseResult
tt "key" or t "key" countThe phrase key from the type's strings table, in the app language, else English. With a count, the plural form for that count, with {n} replaced by the count. The key must be a literal string. A count must be a number, or a string that holds a number.
optionoption "field"The label of the record's option for an enum field, in the app language, else English. "" if the record has no value, or a value that the field does not define. The run stops with an error if the field is not an enum field.
hashas "field"true if the record holds the key and its value is not null.
wholewhole xx as a whole number in plain text, with no thousands separator, for example "4" or "1500". "" if x is not a whole number, or if its size is more than 2⁵³. Use it for a count that you give to t or repeat.
numnum xx as text in its shortest form, written in the app language: 2.5, 4, 1,000,000 in English, 1 000 000 in French. "" if x is not a number.
firstLinefirstLine xThe first line of markdown text that has words in it, as plain text. Heading marks, quote and list marks, emphasis, code marks and link targets are removed. "" if x is not a string.
repeatrepeat "s" ns written n times. n must be a whole number, 0 or more. More than 100 is cut to 100.

num and the {n} of t write a number in the app language. English groups the digits with , and uses . for a decimal point (1,500.5). French groups them with a narrow no-break space (U+202F) and uses , for a decimal point (1 500,5). num reads the value as a number and writes it in its shortest form, so 1.50 becomes 1.5 and 1e3 becomes 1,000. (A field's value in a record panel is different: there every digit stays as the record has it.)

To show a grouped number in a summary, use num: {{num .beds}} gives 1,500, but a bare {{.beds}} gives 1500.

whole does not group. Its text is for the helpers that read a number back: t and repeat. A count can also be what num wrote, so {{t "beds" (num .beds)}} works.

Output

The app cleans the template's output:

A run that writes more than 64 KiB stops with an error.

The built-in templates

The built-in types use the same mechanism. Their summary files are below. They are good examples.

Camp and Route: stars for a rating from 1 to 5. Nothing for no rating, or for a rating that is not whole. The two files are the same.

{
  "summary": "{{if has \"rating\"}}{{if and (ge .rating 1.0) (le .rating 5.0)}}{{with whole .rating}}{{repeat \"★\" .}}{{end}}{{end}}{{end}}"
}

Hazard: the first line of the hazard's markdown text.

{
  "summary": "{{firstLine .description}}"
}

Hotel: the stars of a rating from 1 to 5, then the number of rooms with a plural phrase, joined with " · ". Either part can be missing.

{
  "summary": "{{$s := \"\"}}{{if has \"rating\"}}{{if and (ge .rating 1.0) (le .rating 5.0)}}{{with whole .rating}}{{$s = repeat \"★\" .}}{{end}}{{end}}{{end}}{{$o := \"\"}}{{if has \"rooms\"}}{{with whole .rooms}}{{$o = t \"rooms\" .}}{{end}}{{end}}{{$s}}{{if and $s $o}} · {{end}}{{$o}}",
  "strings": {
    "rooms": {
      "en": {"one": "{n} room", "other": "{n} rooms"},
      "fr": {"one": "{n} chambre", "other": "{n} chambres"}
    }
  }
}

Shelter: the stars, then the number of beds, as Hotel. Zero beds is "0 beds" in English and "0 lit" in French, because the two languages use different forms for zero.

{
  "summary": "{{$s := \"\"}}{{if has \"rating\"}}{{if and (ge .rating 1.0) (le .rating 5.0)}}{{with whole .rating}}{{$s = repeat \"★\" .}}{{end}}{{end}}{{end}}{{$o := \"\"}}{{if has \"beds\"}}{{with whole .beds}}{{$o = t \"beds\" .}}{{end}}{{end}}{{$s}}{{if and $s $o}} · {{end}}{{$o}}",
  "strings": {
    "beds": {
      "en": {"one": "{n} bed", "other": "{n} beds"},
      "fr": {"one": "{n} lit", "other": "{n} lits"}
    }
  }
}

Shop: the label of an enum option, for example "Grocery". Terrain is the same over its terrain field, for example "Trail".

{
  "summary": "{{option \"resupply\"}}"
}

Water: the stars, then one phrase with no plural, only when a bool field is true, as Hotel.

{
  "summary": "{{$s := \"\"}}{{if has \"rating\"}}{{if and (ge .rating 1.0) (le .rating 5.0)}}{{with whole .rating}}{{$s = repeat \"★\" .}}{{end}}{{end}}{{end}}{{$o := \"\"}}{{if .seasonal}}{{$o = t \"seasonal\"}}{{end}}{{$s}}{{if and $s $o}} · {{end}}{{$o}}",
  "strings": {
    "seasonal": {
      "en": "seasonal",
      "fr": "saisonnière"
    }
  }
}

Strings and plurals

strings is an object from phrase key to languages. Each language has one of two shapes:

The rules:

The app chooses plural forms from the CLDR 32 rules. Do not try to choose a form in the template: English and French differ at zero ("0 beds", "0 lit"). A count that is not whole always takes other. t "key" with no count takes other.

In a phrase, {n} is replaced by the count. A phrase in a language that the table does not have is taken from English.

What the import reports

The import checks each data type definition and shows a report line for each problem. The report line names the type, but not the reason. The reason is an English phrase in the app's log, with the place in the file, for example /app.viatrail.datatypes/0.

Report lineWhat happened
Skipping {type}: its definition has an error.The type breaks a rule in Custom data types. The type is not stored. Other types in the same set still import.
Skipping an untitled data type set: its definition has an error.The same, for a set whose name is "", when the problem is with the set and not with one type.
Ignoring {key} in {type}: this app does not know it.The definition has a key that this page does not list. The key is not stored. The type still imports.
Not using the summary of {type}: its template has an error.The summary or the strings breaks a rule. The type imports without it, so its items show the type label alone.
Not using the marker of {type}: it has an error.The marker breaks a rule (see The marker). The type imports with the default marker.
Not using the descriptions on built-in options in {type}.A note on a built-in option that the app never shows (see Labels and notes). The note is not stored. The type still imports. The log lists each field.option.
The data type set "{name}" belongs to a folder that is not in the file, so it was put in the folder you imported into.folder names a folder that the file does not have.
The file carries something in its data type sets that this app cannot read, so it was not imported.app.viatrail.datatypes is not a list, or an entry is not an object, or its name or folder is not a string.

If types is absent, or no type in the set can be used, the whole set is skipped.

A field name or option value with a character other than a–z, 0–9 and _ skips its type. The log names it:

Skipping org.example.rapid: field key 'one-way' may only use a–z, 0–9 and _.
Skipping org.example.rapid: option value 'bush-bash' of field grade may only use a–z, 0–9 and _.

A summary is not used when:

The log line holds the detail. For a template that does not parse, the detail is the error from Go's template parser, which names the line. For example, a template with an {{if}} and no {{end}}:

Not using the summary of org.example.rapid: its summary template cannot be used (the summary template does not parse: template: summary:1: unexpected EOF).

And a template that asks for a phrase that strings does not have:

Not using the summary of org.example.rapid: its summary template cannot be used (t's phrase "portage" is not in strings).

Errors when a template runs

The import cannot run a template on every record. A template that parses can still stop with an error on one record, for example when it compares a number with a string, or reads a field of the wrong type. Then:

No report line shows. Test your template on records with every field absent, present, and holding unusual values.

Rule sets

A rule set is an ordered list of rules. It says how the map draws the items in a folder and in every folder below it. Rule sets travel in the top-level application key app.viatrail.rulesets, as a list. A file holds only the user's own rule sets. Viatrail's default rule set is never exported, whether the user changed it or not.

"app.viatrail.rulesets": [
  {
    "name": "Highlight wet ground",
    "enabled": true,
    "rules": [
      {
        "name": "Boggy stretches in blue",
        "item-types": ["highlight"],
        "conditions": [{ "field": "tag", "operator": "contains", "value": "boggy" }],
        "style": [
          { "@type": "app.viatrail.style.line", "hue": 210, "intensity": "intense", "width": 6, "stripe": "dashes" }
        ]
      },
      {
        "name": "Water sources",
        "item-types": ["waypoint"],
        "style": [
          { "@type": "app.viatrail.style.marker.data", "markers": [
            { "type": "app.viatrail.water", "marker": { "icon": "lucide:droplet", "hue": 210 }, "marker-type": "primary", "boost": 2 }
          ] }
        ]
      }
    ]
  }
]

A rule's style list holds app.viatrail.style.line, .fill and .card records, the same as on an item, plus two that only a rule has: app.viatrail.style.marker.item (a marker for each item kind the rule matches) and app.viatrail.style.marker.data (the data types the rule styles: for each, a marker, a marker-type of none, primary or secondary, and a boost). A rule's behaviour key holds the same app.viatrail.behaviour record as on an item, and only a rule may set its hide, which hides the matched items from the map. The rule's other fields (item-types, match-any, conditions) say which items it matches. In these lists, "waypoint" means a VNX point.

How rules apply

A rule set with enabled: false does not apply. For each item, the app goes through the enabled rule sets in this order:

  1. the built-in default rule set;
  2. the root's rule sets;
  3. the rule sets of each folder from the root down to the item's folder.

In one folder, rule sets go in order of name, then of id. In a rule set, rules go in list order.

A rule applies to an item when the item's type is in the rule's item-types and its conditions pass. Each property that a rule sets replaces the value from earlier rules. A property that a rule does not set keeps the earlier value. Last, the item's own look and behaviour records replace every rule.

Rule details

marker-type says how the type's records show:

A later rule's marker-type replaces an earlier one's. When no rule sets it, the default rule set's value holds: secondary for app.viatrail.note and app.viatrail.photo, and primary for the other types with a marker, including a custom type that a point can hold. A shown record with no icon gets a letter chip: the first letter of its type's label. A shown record's boost (0 by default, any 32-bit whole number) moves it up or down the card and adds to the item's rank.

hide (yes or no) in a rule's behaviour takes the items that the rule matches off the map, as if each item were hidden. no, or no hide, does not hide them. A later rule's no shows an item again that an earlier rule hid. A rule that hides a network hides every item in that network. hide is independent of an item's own hidden state (VNX hidden), and applies to every item type.

The import checks each value. It drops a value that it cannot use, with a report line, and keeps the rest of the rule. It drops a rule whose item-types lists only types that it does not know.

Conditions

A text condition tests a text of the item:

{"field": "name", "operator": "contains", "value": "bothy"}
fieldTests
namethe item's name
textthe name, then each text and markdown field of the item's records whose type is built-in or defined. One match is enough.
folderthe name of the item's folder
paththe names of the item's folders from the root, joined with /
tagthe value of each tag record. One match is enough.
operatorPasses when
containsthe text contains value, in any letter case
starts_withthe text starts with value, in any letter case
matches_regexthe Go regular expression value matches. Letter case counts unless the expression starts with (?i).

A data condition tests the item's records:

{"field": "data", "type": "org.example.rapid", "operator": "ge", "data-field": "portages", "operand": 1}
OperatorsForoperand
present, absentthe type itself: the item has, or does not have, a record of typenone
set, unsetany fieldnone
eq, ne, lt, le, gt, genumber, integer, starsa number (1 to 5 for stars)
is_true, is_falseboolnone
is, is_notenuman option value, a string
one_ofenuma list of one or more option values
contains, starts_with, matches_regextext, markdowna string
before, afterdatea day, YYYY-MM-DD

A data condition works the same way for built-in types, custom types and types with no definition.

A condition with a field or operator that the app does not know is kept and reported. It never passes. A data condition that breaks a rule above is kept and reported too.

An example

"app.viatrail.rulesets": [
  {
    "name": "Rapids",
    "enabled": true,
    "folder": "f1",
    "rules": [
      {
        "name": "Show rapids",
        "item-types": ["waypoint"],
        "conditions": [],
        "style": [
          {"@type": "app.viatrail.style.marker.data", "markers": [
            {"type": "org.example.rapid", "marker": {"icon": "lucide:waves", "hue": 206, "intensity": "intense", "outline": "circle"}, "marker-type": "primary", "boost": 1}
          ]}
        ]
      },
      {
        "name": "Hide closed rapids",
        "item-types": ["waypoint"],
        "conditions": [{"field": "tag", "operator": "contains", "value": "closed"}],
        "behaviour": {"@type": "app.viatrail.behaviour", "hide": "yes"}
      }
    ]
  }
]

Field tables

These tables come from the JSON Schema.

Rule set

FieldTypeValuesMeaning
name requiredstring
enabled requiredboolean
folderstringThe id of a folder in the same document. Absent or empty: the import places it where the user chooses. A folder the document does not have drops the rule set with a report.
ruleslist of rule
pinnedstringWhen the rule set was pinned: a VNX timestamp (§4.3).

Rule

FieldTypeValuesMeaning
namestring
item-typeslist of stringswaypoint, plan, track, highlight, area, networkThe kinds of item the rule matches. An empty list matches nothing. "waypoint" means a VNX point, top-level or in a network.
match-anybooleanTrue: an item matches when any condition holds. Absent or false: all must hold.
conditionslist of condition
stylelist of records: app.viatrail.style.line, app.viatrail.style.fill, app.viatrail.style.card, app.viatrail.style.marker.item, app.viatrail.style.marker.dataThe rule's style: its style records, each an object with its @type, at most one of each type.
behaviourobject: app.viatrail.behaviour

Condition

A condition the app does not know (field or operator) is kept with a report and never matches.

FieldTypeValuesMeaning
field requiredstringname, text, folder, path, tag, dataWhat the condition tests: one of the item's texts, or (data) its data records.
operator requiredstring
valuestringA text condition's text. A data condition has none.
typestringA data condition's data type: any @type, built-in, custom or undefined.
data-fieldstringA data condition's field, for an operator that tests a field.
operandany JSON valueA data condition's value; its shape is the operator's (x-data-operators).
Conditionfieldoperator
Text conditionname, text, folder, path, tagcontains, starts_with, matches_regex
Data conditiondatapresent, absent, contains, starts_with, matches_regex, set, unset, is_true, is_false, eq, ne, lt, le, gt, ge, is, is_not, one_of, before, after

app.viatrail.style.marker.item Item markers

A rule's marker for each item kind it lists in item-types: at most one entry per kind. Rules only. "waypoint" means a VNX point, top-level or in a network.

FieldTypeValuesMeaning
markerslist of object

Each entry in markers:

FieldTypeValuesMeaning
type requiredstringwaypoint, plan, track, highlight, area, network
markerobject: marker

app.viatrail.style.marker.data Data markers

A rule's data types and their markers: one entry per data type the rule styles, at most one per type, in the rule's order. Rules only. marker-type: none (no marker, no card row), primary (its own marker on the map and its own named row on cards) or secondary (a small icon in one shared row on cards; on the map only when the item has no primary marker, then only the strongest). An entry with only its type picks the type and changes nothing.

FieldTypeValuesMeaning
markerslist of object

Each entry in markers:

FieldTypeValuesMeaning
type requiredstringThe data type's id: a string that is not empty.
markerobject: marker
marker-typestringnone, primary, secondary
boostinteger (any 32-bit whole number)Any whole number a 32-bit signed integer holds. It adds to the importance of an item with a record of the type, and orders the item's marks and records: within a marker type, a higher boost comes first. 0 is the default.

A minimal program

This Go program writes a small valid file: one network with three nodes, two arcs, a highlight and a water point. Run it in an empty folder:

go mod init example && go get github.com/dave/vnx/go@main
go run .
go run github.com/dave/vnx/go/cmd/vnx@main validate out.vnx
package main

import (
	"log"
	"os"

	"github.com/dave/vnx/go/pkg/vnx"
)

func main() {
	doc := &vnx.Document{Version: vnx.Version}
	doc.Folders = []vnx.Folder{{ID: "f1", Name: "Example trails"}}
	doc.Networks = []vnx.Network{{
		Folder: "f1",
		Name:   "Example valley",
		// Nodes are trail ends and junctions; positions are lon, lat.
		Nodes: map[string]vnx.Vertex{
			"car-park": {Lon: 10.000, Lat: 46.000},
			"junction": {Lon: 10.010, Lat: 46.010},
			"lake":     {Lon: 10.020, Lat: 46.020},
		},
		// An arc joins two different nodes; pips are the points between them.
		Arcs: map[string]vnx.Arc{
			"valley-path": {From: "car-park", To: "junction",
				Pips: []vnx.Vertex{{Lon: 10.004, Lat: 46.005}}},
			"lake-path": {From: "junction", To: "lake"},
		},
		// A highlight is a named walk over the arcs.
		Highlights: []vnx.Highlight{{Name: "Lake trail", Walk: []vnx.Pass{
			{Arc: "valley-path", From: &vnx.Endpoint{Node: "car-park"}},
			{Arc: "lake-path", To: &vnx.Endpoint{Node: "lake"}},
		}}},
		Points: []vnx.Point{{Name: "Lake spring", At: vnx.Position{Lon: 10.019, Lat: 46.019},
			Data: []vnx.Record{{Type: "app.viatrail.water", Body: map[string]any{"seasonal": true}}}}},
	}}
	raw, err := vnx.Encode(doc)
	if err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("out.vnx", raw, 0o644); err != nil {
		log.Fatal(err)
	}
}