1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
<xsl:stylesheet
|
3
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
4
|
xmlns:svg="http://www.w3.org/2000/svg"
|
5
|
xmlns:gml="http://www.opengis.net/gml"
|
6
|
version="1.0">
|
7
|
<!--
|
8
|
Description: Convert GML to wz_jsgraphics function calls.
|
9
|
Precondition: <coordinates> have been converted to <coords> (using
|
10
|
GmlCoordinates2Coord.xsl).
|
11
|
Author: Nedjo Rogers nedjo ATgworks.ca, Cameron Shorter cameron ATshorter.net
|
12
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
13
|
|
14
|
$Id$
|
15
|
$Name$
|
16
|
-->
|
17
|
<xsl:output method="xml" encoding="utf-8"/>
|
18
|
|
19
|
<xsl:param name="width" select="400"/>
|
20
|
<xsl:param name="height" select="200"/>
|
21
|
<xsl:param name="bBoxMinX" select="-180"/>
|
22
|
<xsl:param name="bBoxMinY" select="-90"/>
|
23
|
<xsl:param name="bBoxMaxX" select="180"/>
|
24
|
<xsl:param name="bBoxMaxY" select="90"/>
|
25
|
<xsl:param name="lineColor" select="'red'"/>
|
26
|
<xsl:param name="lineWidth" select="1"/>
|
27
|
<xsl:param name="crossSize" select="0"/>
|
28
|
<xsl:param name="skinDir"/>
|
29
|
<xsl:param name="pointWidth" select="5"/>
|
30
|
|
31
|
<xsl:variable name="xRatio" select="$width div ( $bBoxMaxX - $bBoxMinX )"/>
|
32
|
<xsl:variable name="yRatio" select="$height div ( $bBoxMaxY - $bBoxMinY )"/>
|
33
|
|
34
|
<!-- Root node -->
|
35
|
<xsl:template match="/">
|
36
|
<xsl:param name="geoWidth" select="$bBoxMaxX - $bBoxMinX"/>
|
37
|
<xsl:param name="geoHeight" select="$bBoxMaxY - $bBoxMinY"/>
|
38
|
<xsl:element name="svg">
|
39
|
<xsl:attribute name="width"><xsl:value-of select="$width"/><xsl:text>px</xsl:text></xsl:attribute>
|
40
|
<xsl:attribute name="height"><xsl:value-of select="$height"/><xsl:text>px</xsl:text></xsl:attribute>
|
41
|
<xsl:attribute name="viewBox">
|
42
|
<xsl:value-of select="$bBoxMinX"/>
|
43
|
<xsl:text> </xsl:text>
|
44
|
<xsl:value-of select="$bBoxMinY"/>
|
45
|
<xsl:text> </xsl:text>
|
46
|
<xsl:value-of select="$geoWidth"/>
|
47
|
<xsl:text> </xsl:text>
|
48
|
<xsl:value-of select="$geoHeight"/>
|
49
|
</xsl:attribute>
|
50
|
<xsl:element name="g">
|
51
|
<xsl:attribute name="style"><xsl:text>fill-rule:evenodd; fill:none; stroke:none; stroke-antialiasing:true;</xsl:text></xsl:attribute>
|
52
|
<xsl:attribute name="transform"><xsl:text>matrix(1 0 0 -1 0 0)</xsl:text></xsl:attribute>
|
53
|
<xsl:apply-templates/>
|
54
|
</xsl:element>
|
55
|
</xsl:element>
|
56
|
</xsl:template>
|
57
|
|
58
|
<!-- Match and render a GML Point -->
|
59
|
<xsl:template match="gml:pointMember/gml:Point | gml:pointProperty/gml:Point">
|
60
|
<xsl:variable name="x0" select="gml:coord/gml:X"/>
|
61
|
<xsl:variable name="y0" select="gml:coord/gml:Y"/>
|
62
|
<xsl:element name="circle">
|
63
|
<xsl:attribute name="cx"><xsl:value-of select="$x0"/></xsl:attribute>
|
64
|
<xsl:attribute name="cy"><xsl:value-of select="$y0"/></xsl:attribute>
|
65
|
<xsl:attribute name="r"><xsl:value-of select="$pointWidth"/></xsl:attribute>
|
66
|
</xsl:element>
|
67
|
</xsl:template>
|
68
|
|
69
|
<!-- Match and render a LineString -->
|
70
|
<xsl:template match="gml:LineString">
|
71
|
<xsl:choose>
|
72
|
<!-- Draw a line -->
|
73
|
<xsl:when test="count(gml:coord)!=1">
|
74
|
<xsl:element name="polyline">
|
75
|
<xsl:attribute name="points">
|
76
|
<xsl:for-each select="gml:coord">
|
77
|
<xsl:value-of select="gml:X"/>
|
78
|
<xsl:text> </xsl:text>
|
79
|
<xsl:value-of select="floor($height - (number(gml:Y) -$bBoxMinY)*$yRatio)"/>
|
80
|
<xsl:if test="following-sibling::gml:coord">
|
81
|
<xsl:text>,</xsl:text>
|
82
|
</xsl:if>
|
83
|
</xsl:for-each>
|
84
|
</xsl:attribute>
|
85
|
</xsl:element>
|
86
|
</xsl:when>
|
87
|
<!-- When one coord, draw point -->
|
88
|
<xsl:otherwise>
|
89
|
<xsl:variable name="x0" select="gml:coord/gml:X"/>
|
90
|
<xsl:variable name="y0" select="gml:coord/gml:Y"/>
|
91
|
<xsl:element name="circle">
|
92
|
<xsl:attribute name="cx"><xsl:value-of select="$x0"/></xsl:attribute>
|
93
|
<xsl:attribute name="cy"><xsl:value-of select="$y0"/></xsl:attribute>
|
94
|
<xsl:attribute name="r"><xsl:value-of select="$pointWidth"/></xsl:attribute>
|
95
|
</xsl:element>
|
96
|
</xsl:otherwise>
|
97
|
</xsl:choose>
|
98
|
</xsl:template>
|
99
|
|
100
|
<xsl:template match="text()|@*"/>
|
101
|
|
102
|
</xsl:stylesheet>
|