# -------------------------------------------------------------------
# This is the default mkgmap style file for converting OSM ways
# into Garmin lines.
# 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.

aeroway=runway [0x27 resolution 20]

# Contours take their name from the elevation setting.
contour=elevation & contour_ext=elevation_minor
	{ name '${ele|conv:m=>ft}'; }
	[0x20 resolution 22]
contour=elevation & contour_ext=elevation_medium
	{ name '${ele|conv:m=>ft}'; }
	[0x21 resolution 21]
contour=elevation & contour_ext=elevation_major
	{ name '${ele|conv:m=>ft}'; }
	[0x22 resolution 20]
contour=elevation | contour_ext=elevation
	{ name '${ele|conv:m=>ft}'; }
	[0x21 resolution 20]

# Set highway names to include the reference if there is one
highway=motorway {name '${ref|highway-symbol:hbox} ${name}' | '${ref|highway-symbol:hbox}' | '${name}' }
highway=trunk {name '${ref|highway-symbol:hbox} ${name}' | '${ref|highway-symbol:hbox}' | '${name}' }
highway=primary {name '${ref|highway-symbol:box} ${name}' | '${ref|highway-symbol:box}' | '${name}' }
highway=secondary {name '${ref|highway-symbol:oval} ${name}' | '${ref|highway-symbol:oval}' | '${name}' }
#highway=track {name '${ref} ${name}' | '${ref}' | '${name}' | '${tracktype} (${width} m)' | '${tracktype}' | '(${width} m)' }
highway=* {name '${ref} ${name}' | '${ref}' | '${name}' }

# Flag unpaved roads.
highway=*
& (surface=cobblestone | surface=compacted | surface=dirt |
   surface=earth | surface=grass | surface=grass_paver |
   surface=gravel | surface=grit | surface=ground | surface=mud |
   surface=pebblestone | surface=sand | surface=unpaved |
   mtb:scale=* |
   tracktype ~ 'grade[2-6]' |
   smoothness ~ '.*(bad|horrible|impassable)' |
   sac_scale ~ '.*(mountain|alpine)_hiking' |
   sport=via_ferrata)
{ add mkgmap:unpaved=1 }
(highway=bridleway | highway=path | highway=track | highway=unsurfaced)
& surface!=* & tracktype!=* & smoothness!=* & sac_scale!=*
{ add mkgmap:unpaved=1 }

# motorways and motorway_link
highway=motorway {add oneway = yes; add bicycle = no; add foot = no }
highway=motorway_link {add bicycle = no; add foot = no } # motorway_link may be 2-ways

junction=roundabout & (highway=motorway | highway=motorway_link)	[0x0c road_class=3 road_speed=4 resolution 12]
(bridge=yes | bridge=true) & highway=motorway [0x10600 resolution 12 continue]
(tunnel=yes | tunnel=true) & highway=motorway [0x10700 resolution 12 continue]
highway=motorway & (maxspeed>129 | maxspeed=none)	[0x01 road_class=4 road_speed=7 resolution 12]
highway=motorway & maxspeed>100				[0x01 road_class=4 road_speed=6 resolution 12]
highway=motorway & maxspeed>80				[0x01 road_class=4 road_speed=5 resolution 12]
highway=motorway & maxspeed>60				[0x01 road_class=3 road_speed=4 resolution 12]
highway=motorway & maxspeed<61				[0x01 road_class=3 road_speed=3 resolution 12]
highway=motorway					[0x01 road_class=4 road_speed=6 resolution 12]
(bridge=yes | bridge=true) & highway=motorway_link [0x10602 resolution 16 continue]
(tunnel=yes | tunnel=true) & highway=motorway_link [0x10702 resolution 16 continue]
highway=motorway_link [0x09 road_class=4 road_speed=3 resolution 16]

#trunk and trunk_link
junction=roundabout & (highway=trunk | highway=trunk_link)	[0x0c road_class=3 road_speed=4 resolution 16]
(bridge=yes | bridge=true) & highway=trunk [0x10601 resolution 16 continue]
(tunnel=yes | tunnel=true) & highway=trunk [0x10701 resolution 16 continue]
highway=trunk & maxspeed>100	[0x02 road_class=4 road_speed=6 resolution 16]
highway=trunk & maxspeed>80	[0x02 road_class=3 road_speed=5 resolution 16]
highway=trunk & maxspeed>60 	[0x02 road_class=3 road_speed=4 resolution 16]
highway=trunk & maxspeed>50	[0x02 road_class=3 road_speed=3 resolution 16]
highway=trunk & maxspeed<51	[0x02 road_class=3 road_speed=2 resolution 16]
highway=trunk 			[0x02 road_class=3 road_speed=5 resolution 16]
(bridge=yes | bridge=true) & highway=trunk_link [0x10602 resolution 16 continue]
(tunnel=yes | tunnel=true) & highway=trunk_link [0x10702 resolution 16 continue]
highway=trunk_link [0x09 road_class=3 road_speed=3 resolution 16]

#primary
junction=roundabout & (highway=primary | highway=primary_link)	[0x0c road_class=3 road_speed=3 resolution 18]
(bridge=yes | bridge=true) & highway=primary [0x10601 resolution 18 continue]
(tunnel=yes | tunnel=true) & highway=primary [0x10701 resolution 18 continue]
highway=primary & maxspeed>80 [0x03 road_class=3 road_speed=5 resolution 18]
highway=primary & maxspeed>60 [0x03 road_class=3 road_speed=4 resolution 18]
highway=primary & maxspeed>50 [0x03 road_class=3 road_speed=3 resolution 18]
highway=primary & maxspeed<51 [0x03 road_class=2 road_speed=2 resolution 18]
highway=primary		      [0x03 road_class=3 road_speed=5 resolution 18]

#secondary
junction=roundabout & (highway=secondary | highway=secondary_link)	[0x0c road_class=2 road_speed=2 resolution 20]
(bridge=yes | bridge=true) & highway=secondary [0x10601 resolution 20 continue]
(tunnel=yes | tunnel=true) & highway=secondary [0x10701 resolution 20 continue]
(highway=secondary | highway=secondary_link) & maxspeed>80	[0x04 road_class=3 road_speed=5 resolution 20]
(highway=secondary | highway=secondary_link) & maxspeed>60	[0x04 road_class=3 road_speed=4 resolution 20]
(highway=secondary | highway=secondary_link) & maxspeed>50	[0x04 road_class=2 road_speed=3 resolution 20]
(highway=secondary | highway=secondary_link) & maxspeed<51	[0x04 road_class=2 road_speed=2 resolution 20]
(highway=secondary | highway=secondary_link)			[0x04 road_class=2 road_speed=4 resolution 20]

# tertiary
junction=roundabout & (highway=tertiary | highway=tertiary_link) [0x0c road_class=1 road_speed=2 resolution 20]
(bridge=yes | bridge=true) & highway=tertiary [0x10602 resolution 20 continue]
(tunnel=yes | tunnel=true) & highway=tertiary [0x10702 resolution 20 continue]
(highway=tertiary | highway=tertiary_link) & maxspeed<51 [0x05 road_class=1 road_speed=2 resolution 20]
(highway=tertiary | highway=tertiary_link) [0x05 road_class=1 road_speed=3 resolution 20]

junction=roundabout & highway=unclassified [0x0c road_class=1 road_speed=1 resolution 21]
junction=roundabout [0x0c road_class=0 road_speed=1 resolution 21]

# Convert generic path to most specific
highway=path & bicycle=designated {set highway=cycleway }
highway=path & horse=designated {set highway=bridleway }
highway=path & foot=designated {set highway=footway }

# Ways that may or may not be useable

# Treat ways under construction as highway=path
highway=construction | highway=* & construction=* {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=1 resolution 22]
# Treat disused ways as highway=service, but at lower road_speed.
highway=* & disused=yes [0x07 road_class=0 road_speed=1 resolution 22]

# Other highways not set above
highway=bridleway {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 22]
highway=byway [0x16 road_class=0 road_speed=0 resolution 22]
highway=cycleway {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=1 resolution 22]
highway=footway {add access = no; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 22]
highway=minor [0x06 road_class=1 road_speed=2 resolution 21]
highway=pedestrian & area!=yes {add access = no; add foot = yes} [0x06 road_class=0 road_speed=0 resolution 22]
highway=primary_link [0x08 road_class=3 road_speed=3 resolution 19]
highway=residential & maxspeed=50 [0x06 road_class=0 road_speed=2 resolution 22]
highway=residential & maxspeed<50 | highway=living_street [0x06 road_class=0 road_speed=1 resolution 22]
highway=residential  [0x06 road_class=0 road_speed=2 resolution 22]
highway=secondary_link [0x08 road_class=2 road_speed=2 resolution 20]
highway=path {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 22]
highway=service [0x07 road_class=0 road_speed=1 resolution 22]
highway=steps {add access = no; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 22]
highway=track [0x0a road_class=0 road_speed=1 resolution 21]
highway=unclassified [0x06 road_class=1 road_speed=2 resolution 21]
highway=unsurfaced [0x0a road_class=0 road_speed=1 resolution 21]
highway=road [0x06 road_class=0 road_speed=1 resolution 21]

# Mop up any unrecognised highway types
highway=* & area!=yes [0x07 resolution 21]

natural=coastline [0x15 resolution 12]
power=line [0x29 resolution 20]

railway=abandoned [0x0a road_class=0 road_speed=1 resolution 21]
railway=light_rail & !(layer<0) [0x14 resolution 18]
railway=rail & !(layer<0) [0x14 resolution 18]
railway=subway & !(layer<0) [0x14 resolution 18]
railway=tram & !(layer<0) [0x14 resolution 18]
railway=platform {add access = no; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 22]

route=ferry {add mkgmap:ferry=1} [0x1b road_class=0 road_speed=0 resolution 18]

waterway=canal [0x1f resolution 21]
waterway=drain [0x1f resolution 22]
waterway=river [0x1f resolution 18]
waterway=stream [0x18 resolution 22]

man_made=pipeline {name '${operator}'} [0x28 resolution 22]

# The following boundary styles are after the highway rules because ways
# are frequently tagged with both and we want the highway to take priority.
boundary=administrative
{ name '${mkgmap:boundary_name}' |
  '${left:country}/${right:country}' |
  '${left:state}/${right:state}' |
  '${left:district}/${right:district}' |
  '${left:county}/${right:county}' |
  '${left:municipality}/${right:municipality}' |
  '${left:city}/${right:city}' |
  '${left:village}/${right:village}' |
  '${left:suburban}/${right:suburban}'
}
boundary=administrative & admin_level<3 [0x1e resolution 16]
boundary=administrative & admin_level<5 [0x1d resolution 18]
boundary=administrative & admin_level<7 [0x1c resolution 20]
boundary=administrative & admin_level<9 [0x1c resolution 21]
boundary=administrative [0x1c resolution 22]
boundary=national [0x1e resolution 18]
boundary=political [0x1c resolution 18]
