Mapper is designed for convenient production of graphics from the data in its output file. By itself, this output file is not particularly useful. You could view it using a text editor, but you would probably rather produce a picture: a plan or map, rather than coordinate data. This is possible by transforming the output data to Scalable Vector Graphics (SVG) format, and either using that directly or (more likely, for the present) then transforming the SVG to another graphics format (such as PNG).
The Mapper output file is in XML format. It can be transformed to SVG using Extensible Stylesheet Language Transformations (XSLT). The Mapper output format was designed to make this transformation relatively easy.
Recall that Mapper outputs data like this:
<?xml version="1.0" standalone="no"?>
<Map-Data x="0.000000" y="21.108714" width="21.285365" height="23.403744" precision="6">
<Units angle="degrees" length="m"/>
<Point x="21.285365" y="18.813459" id="ne"/>
<Point x="18.693655" y="-2.295030" id="se"/>
<Point x="0.000000" y="0.000000" id="sw"/>
<Point x="2.591519" y="21.108714" id="nw"/>
<Fixed-point x="0" y="0" point="sw"/>
<Constraint-group angle-uncertainty="5" length-uncertainty="1 + 10%">
<Cite>Measurements on Sunday 30 June 2002</Cite>
<Angle d="90" e="0.00" at="ne" to="se" from="nw"/>
<Angle d="90" e="0.00" at="se" to="sw" from="ne"/>
<Angle d="90" e="0.00" at="sw" to="nw" from="se"/>
<Angle d="90" e="0.00" at="nw" to="ne" from="sw"/>
<Bearing d="007" e="0.00" to="ne" from="se"/>
<Distance d="18" e="0.00" to="nw" from="ne"/>
<Distance d="16" e="0.00" to="se" from="ne"/>
</Constraint-group>
<Area-feature class="building">
<Name lang="en">My House</Name>
<Node x="21.285365" y="18.813459" point="ne"/>
<Line-segment x="18.693655" y="-2.295030" point="se"/>
<Line-segment x="0.000000" y="0.000000" point="sw"/>
<Line-segment x="2.591519" y="21.108714" point="nw"/>
</Area-feature>
</Map-Data>
In this example,
the important data is contained in the Area-feature element.
Let us imagine we want to draw the building as a grey area.
We need to transform this element to a path element, and
we need to construct the d attribute of the path
from the Node and Line-segment
children of the Area-feature.
We will have to transform the coordinates to produce graphics
of the desired scale and orientation.
The following style-sheet will do what we want:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="scale">5</xsl:variable>
<xsl:variable name="left">-10</xsl:variable>
<xsl:variable name="top">30</xsl:variable>
<xsl:variable name="height">200</xsl:variable>
<xsl:variable name="width">200</xsl:variable>
<xsl:output method="xml"
doctype-public="-//W3C//DTD SVG 20000802//EN"
doctype-system="http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd"
indent="yes"/>
<xsl:template match="Map-Data">
<xsl:element name="svg">
<xsl:attribute name="width"><xsl:value-of select="$width"/>pt</xsl:attribute>
<xsl:attribute name="height"><xsl:value-of select="$height"/>pt</xsl:attribute>
<g style="stroke-width:0; fill:#808080">
<xsl:apply-templates select="Area-feature[@class='building']"/>
</g>
</xsl:element>
</xsl:template>
<xsl:template match="Area-feature">
<xsl:element name="path">
<xsl:attribute name="d">
<xsl:apply-templates select="Node|Line-segment"/>
<xsl:text> z</xsl:text>
</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template match="Node">M <xsl:apply-templates select="./@x"/><xsl:text> </xsl:text><xsl:apply-templates select="./@y"/></xsl:template>
<xsl:template match="Line-segment"><xsl:text> L </xsl:text><xsl:apply-templates select="./@x"/><xsl:text> </xsl:text><xsl:apply-templates select="./@y"/></xsl:template>
<xsl:template match="@x">
<xsl:value-of select="(0 + . - ($left)) * $scale"/>
</xsl:template>
<xsl:template match="@y">
<xsl:value-of select="(0 + . - ($top)) * -1 * $scale"/>
</xsl:template>
</xsl:stylesheet>
Applying that style-sheet to the output data produces the following SVG:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd"> <svg width="200pt" height="200pt"> <g style="stroke-width:0; fill:#808080"> <path d="M 156.426825 55.932705 L 143.468275 161.47515 L 50 150 L 62.957595 44.45643 z"/> </g> </svg>
Here is the resulting graphic:
Of course, this is a trivia example. Realistic examples would have several types of terrain feature, with complex definitions, which should be displayed in different ways, with labels. That requires a rather more complex style-sheet. The principles are the same, however.
This documentation is still being written,
and is therefore incomplete.
$Revision: 6.4 $
$Date: 2002/07/06 15:38:35 $