
meta {
    title: "Hiking routes";
    description: "Limited hiking routes example for standard JOSM (unpatched), see comments below";
    version: "0.1_2011-12-15";
}

/*
 * Limitations:
 * - multiple relations with same color not displayed (there's one example with blue to test 
 *   against previous matches, but there's no unique tag that would be reliable to do so)
 * - selector duplication by the need to use two "passes" for counting and actual execution
 * - declaration repetitions with only the color changing by the need to distinguish multiple
 *   matching relations by exact value
 * - no symbols
 */

way::osmc {
	_width: 12;
  _opacity: 0.7;
  _dashes_width: 6;
  _font_size: 9;
  _text_offset: 11;

  _count: 0;
}

/*
 * First "pass": Count matching parent relations and set dashes size accordingly 
 * Note: selectors must match with those of the second pass.
 */

relation[osmc:symbol=~/^blue:/] > way::osmc { 
  _index_blue: prop(_count); 
  _count: prop(_count) + 1; 
  _name_blue1: parent_tag(name);
}
relation[osmc:symbol=~/^blue:/][eval(!(tag(name) == prop(_name_blue1)))] > way::osmc { 
  _index_blue2: prop(_count); 
  _count: prop(_count) + 1; 
}
relation[osmc:symbol=~/^yellow:/] > way::osmc { 
  _index_yellow: prop(_count);
  _count: prop(_count) + 1; 
}
relation[osmc:symbol=~/^green:/] > way::osmc {
  _index_green: prop(_count);
  _count: prop(_count) + 1;
}
relation[osmc:symbol=~/^red:/] > way::osmc {
  _index_red: prop(_count);
  _count: prop(_count) + 1; 
}
relation[osmc:symbol=~/^black:/] > way::osmc {
  _index_black: prop(_count);
  _count: prop(_count) + 1; 
}
relation[!osmc:symbol][type=route][route=hiking] > way::osmc,
relation[!osmc:symbol][type=route][route=foot] > way::osmc { 
  _index_none: prop(_count);
  _count: prop(_count) + 1; 
}

way::osmc {
  _dashes_space: (prop(_count) > 1) ? 2 : 0;
  _dashes: list(prop(_dashes_width), (prop(_dashes_width) * (prop(_count) - 1)) + prop(_dashes_space));
}

/*
 * Second "pass": dashed route lines + text
 * Note: selectors must match with those of the first pass.
 */

relation[osmc:symbol=~/^blue:/] > way::osmc_blue {
	color: darkblue;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_blue, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: blue;
  text-offset: prop(_text_offset, osmc) * (prop(_index_blue, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[osmc:symbol=~/^blue:/][eval(!(tag(name) == prop(_name_blue1, osmc)))] > way::osmc_blue2 {
	color: darkblue;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_blue2, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: blue;
  text-offset: prop(_text_offset, osmc) * (prop(_index_blue2, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[osmc:symbol=~/^yellow:/] > way::osmc_yellow {
	color: gold;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_yellow, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: yellow;
  text-offset: prop(_text_offset, osmc) * (prop(_index_yellow, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[osmc:symbol=~/^green:/] > way::osmc_green {
	color: darkgreen;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_green, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: green;
  text-offset: prop(_text_offset, osmc) * (prop(_index_green, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[osmc:symbol=~/^red:/] > way::osmc_red {
	color: darkred;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_red, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: red;
  text-offset: prop(_text_offset, osmc) * (prop(_index_red, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[osmc:symbol=~/^black:/] > way::osmc_black {
  /* can't use black because of black background in JOSM */
	color: darkgray;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_black, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: white;
  text-offset: prop(_text_offset, osmc) * (prop(_index_black, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

relation[!osmc:symbol][type=route][route=hiking] > way::osmc_none,
relation[!osmc:symbol][type=route][route=foot] > way::osmc_none {
	color: dimgrey;
  dashes: prop(_dashes, osmc);
  dashes-offset: prop(_index_none, osmc) * prop(_dashes_width, osmc);
	width: prop(_width, osmc);
  opacity: prop(_opacity, osmc);
  z-index: -1;

  text: eval(parent_tag("name"));
  text-color: grey;
  text-offset: prop(_text_offset, osmc) * (prop(_index_none, osmc) + 1);
  font-size: prop(_font_size, osmc);
}

