From OpenStreetMap Wiki
Jump to: navigation, search

This is proposal for new Osmarender features.

Main goals:

  • Make Osmarender rule file shorter and easier to manage
  • Reorder rules so that related features are close to each other. For example have highway casing and core in one place.

Current situation

Currently rendering instructions for one feature are scattered through rules file because position of instruction in rules file affects z-index of generated SVG element.

For example, tertiary road is mentioned in following instructions, every instruction is at different place in rules file:

  • bridge casing
  • bridge core
  • highway=tertiary area casing
  • normal tertiary road casing
  • highway=tertiary area core
  • normal tertiary road core
  • tunnel casing
  • road name
  • highway=tertiary area name
  • road ref

The same stands for other highway types.

Proposed new features


Every instruction can have one or more labels. Every instruction also have implicit label – it's the same as instruction name.

For example following instruction:

<line class="highway-tertiary-casing" labels="casing|highway"/>

has these labels: line, casing, highway


Position of element can be controlled using z-index and z-mode. Z-mode is either bottom, normal or top. When z-mode is bottom, elements are drawn below other elements, layer attribute is ignored. Elements with z-mode = top are drawn above other elements. z-mode = normal means elements are drawn as usual, layer attribute is respected.

Z-index sets position within the group of elements with the same z-mode (and layer in case of z-mode=normal).

Z-mode and z-index can be set for single instruction or group of instructions using labels and SetZIndex command.

Modification actions

Actions are instructions, that do not produce any SVG commands. Instead of that they modify behavior of other instructions. Labels are used to identify, which instructions should be modified. Actions can be either top level or inside <rule> elements. Top level actions apply to all elements, others apply only to selected elements.

Proposed actions
  • SetAttribute - sets value of attribute. It's intended especially for setting z-index and z-mode, but it could be used for any attribute. Useful for example to make all symbols drawn on top of other elements or draw highway casing below highway core.


name - name of attribute
value - new value.
  • Remove - removes instruction. Useful for osmarender:renderName, osmarender:renderRef, etc.



How it may be implemented

I've recently refactored layer handling in both XSLT and or/p. Both renderers now have at some point list of instructions, elements they apply to and position in svg file. It should be possible to go through all actions and execute them on generated elements.


Tertiary road will be defined in one place, like in following example. Only properties directly related to tertiary road are described here, properties related to all roads are described in next section. Position of instructions is no longer important because exact z-index is later defined using <SetLayer>

<rule e="way" k="highway" v="tertiary">
	<line class="highway-core highway-tertiary-core" labels="core"/>
	<line class="highway-casing highway-tertiary-casing" labels="casing"/>
	<text k="name" startOffset="50%" class="highway-name highway-tertiary-name" dy="0.5px" labels="ref"/>

Actions that will apply to all highways will be defined:

<!-- Following two lines says draw highway core always after highway casing -->
<setZIndex for-label="core" z-mode="normal" z-index="2"/>
<setLayer for-label="casing" z-mode="normal" z-index="1"/>

<!-- Draw refs at the topmost layer -->
<setLayer for-label="ref" z-mode="top"/>

<!-- Don't render ref if osmarender:render=yes is specified -->
<rule e="way" k="osmarender:renderRef" v="yes">
	<remove for-label="ref"/>

Other possible features

  • Do something about features which have both text and icon. Currently offset has to be used to make sure text and icon won't overlap. But it makes icon/text a bit of the center of the feature when only text/only icon is specified.