# -------------------------------------------------------------------
# This is the default mkgmap style file for applying rules on
# OSM relations.  Usually you will set tags on the
# elements that make up the relation, and the tags will be
# processed by the rules defined in the "points" or "lines" files.
#
# Any line prefaced with # is a comment and will not be applied.
# Each line is a rule, of the generalised format:
#  OSM_tag(s)_to_match  [Garmin_type_code resolution]
# See http://wiki.openstreetmap.org/wiki/Mkgmap/help/style_rules
# and http://wiki.openstreetmap.org/wiki/Mkgmap/help/Custom_styles
# for more information.

# Names of administrative boundaries.
# We could want to sort the relations in ascending order of admin_level
# and alphabetically by name first.
# Currently, the matching relations will be processed and the names
# appended to the boundary lines in an arbitrary order.
(type=boundary | type=multipolygon) & boundary=administrative & name=*
{ apply
  {
    set mkgmap:boundary_name='$(mkgmap:boundary_name)/${name}' | '${name}';
  }
}

# European E-Road network
route=road & network=e-road { apply { add ref='${ref}'; add int_ref='${int_ref'}; add network=e-road }

# Public transportation routes.
# We could want to sort the matching relations by ref first.
type=route
& (route=bus|route=trolleybus|route=ferry|route=subway|route=train|route=tram)
& (ref=* | name=*)
{
  add ref='${name}'; # if ref is missing, use name
  # Append the ref of the route relation to the route_ref attribute of
  # the member nodes recursively (even to members of subrelations).
  # Stops can be grouped within subrelations comprising the vehicle
  # stop node and the passenger wait node.
  apply { # node role ~ '(start_|end_)stop'
    set route_ref='$(route_ref),${ref}' | '${ref}';

    # In route relations, stops may be defined as relations that group
    # the passenger wait area and the vehicle stop area.  If such
    # subrelations exist, copy the ref to them too.
    set mkgmap:relref='${ref}';

    apply role=passengers {
      set route_ref='$(route_ref),${mkgmap:relref}' | '${mkgmap:relref}';
    }

    delete mkgmap:relref;
  }
  # We could want to copy the route relation name to unnamed route=ferry ways.
  # apply way { add name='${name}' }
}
