-
Notifications
You must be signed in to change notification settings - Fork 5
/
osmarender.xsl
4590 lines (4032 loc) · 192 KB
/
osmarender.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<!--
==============================================================================
Osmarender 6.0 Alpha 6
with - orig area generation
- one node way filtered out
- filtered out missing multipolygon relation members from areas
- filtered out missing node ref from ways
==============================================================================
Copyright (C) 2006-2007 Etienne Cherdlu, Jochen Topf
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
==============================================================================
-->
<xsl:stylesheet
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:labels="http://openstreetmap.org/osmarender-labels-rtf"
xmlns:z="http://openstreetmap.org/osmarender-z-rtf"
exclude-result-prefixes="exslt msxsl"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8"/>
<!-- This msxsl script extension fools msxsl into interpreting exslt extensions as msxsl ones, so
we can write code using exslt extensions even though msxsl only recognises the msxsl extension
namespace. Thanks to David Carlisle for this: http://dpcarlisle.blogspot.com/2007/05/exslt-node-set-function.html -->
<msxsl:script language="JScript" implements-prefix="exslt">
this['node-set'] = function (x) {
return x;
}
</msxsl:script>
<xsl:param name="osmfile" select="/rules/@data"/>
<xsl:param name="title" select="/rules/@title"/>
<xsl:param name="scale" select="/rules/@scale"/>
<xsl:param name="symbolScale" select="/rules/@symbolScale"/>
<xsl:param name='textAttenuation' select='/rules/@textAttenuation'/>
<!-- TODO: Implement withOSMLayers again -->
<xsl:param name="withOSMLayers" select="/rules/@withOSMLayers"/>
<xsl:param name="svgBaseProfile" select="/rules/@svgBaseProfile"/>
<xsl:param name="symbolsDir" select="/rules/@symbolsDir"/>
<xsl:param name="showGrid" select="/rules/@showGrid"/>
<xsl:param name="showBorder" select="/rules/@showBorder"/>
<xsl:param name="showScale" select="/rules/@showScale"/>
<xsl:param name="showLicense" select="/rules/@showLicense"/>
<xsl:param name="showRelationRoute" select="/rules/@showRelationRoute"/>
<xsl:param name="meter2pixelFactor" select="/rules/@meter2pixel"/>
<xsl:param name="minlat"/>
<xsl:param name="maxlat"/>
<xsl:param name="minlon"/>
<xsl:param name="maxlon"/>
<xsl:key name="nodeById" match="/osm/node" use="@id"/>
<xsl:key name="wayById" match="/osm/way" use="@id"/>
<xsl:key name="wayByNode" match="/osm/way" use="nd/@ref"/>
<xsl:key name="relationByWay" match="/osm/relation" use="member/@ref"/>
<xsl:key name="relationById" match="/osm/relation" use="@id"/>
<xsl:variable name="data" select="document($osmfile)"/>
<!-- Use a web-service (if available) to get the current date -->
<xsl:variable name="now" select="document('http://xobjex.com/service/date.xsl')" />
<xsl:variable name="date">
<xsl:choose>
<xsl:when test="$now">
<xsl:value-of select="substring($now/date/utc/@stamp,1,10)" />
<!-- Assumes 4 digit year -->
</xsl:when>
<xsl:otherwise>2009-01-01</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="year">
<xsl:choose>
<xsl:when test="$now">
<xsl:value-of select="$now/date/utc/year" />
</xsl:when>
<xsl:otherwise>2009</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- extra height for marginalia at top -->
<xsl:variable name="marginaliaTopHeight">
<xsl:choose>
<xsl:when test="$title != ''">40</xsl:when>
<xsl:when test="($title = '') and ($showBorder = 'yes')">1.5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- extra height for marginalia at bottom -->
<xsl:variable name="marginaliaBottomHeight">
<xsl:choose>
<xsl:when test="($showScale = 'yes') or ($showLicense = 'yes')">45</xsl:when>
<xsl:when test="($showScale != 'yes') and ($showLicense != 'yes') and ($showBorder = 'yes')">1.5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- extra width for border -->
<xsl:variable name="extraWidth">
<xsl:choose>
<xsl:when test="$showBorder = 'yes'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- extra height for border -->
<xsl:variable name="extraHeight">
<xsl:choose>
<xsl:when test="($title = '') and ($showBorder = 'yes')">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Calculate bounding box.
Use the first given of min/max lat/lon parameters, bounds element from rules,
bounds elements from data or fallback to calculating based on file content -->
<xsl:variable name="bottomLeftLatitude">
<xsl:choose>
<xsl:when test="$minlat">
<xsl:value-of select="$minlat"/>
</xsl:when>
<xsl:when test="/rules/bounds">
<xsl:value-of select="/rules/bounds/@minlat"/>
</xsl:when>
<xsl:when test="$data/osm/bounds">
<xsl:for-each select="$data/osm/bounds/@minlat">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$data/osm/node/@lat">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="bottomLeftLongitude">
<xsl:choose>
<xsl:when test="$minlon">
<xsl:value-of select="$minlon"/>
</xsl:when>
<xsl:when test="/rules/bounds">
<xsl:value-of select="/rules/bounds/@minlon"/>
</xsl:when>
<xsl:when test="$data/osm/bounds">
<xsl:for-each select="$data/osm/bounds/@minlon">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$data/osm/node/@lon">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="topRightLatitude">
<xsl:choose>
<xsl:when test="$maxlat">
<xsl:value-of select="$maxlat"/>
</xsl:when>
<xsl:when test="/rules/bounds">
<xsl:value-of select="/rules/bounds/@maxlat"/>
</xsl:when>
<xsl:when test="$data/osm/bounds">
<xsl:for-each select="$data/osm/bounds/@maxlat">
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$data/osm/node/@lat">
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="topRightLongitude">
<xsl:choose>
<xsl:when test="$maxlon">
<xsl:value-of select="$maxlon"/>
</xsl:when>
<xsl:when test="/rules/bounds">
<xsl:value-of select="/rules/bounds/@maxlon"/>
</xsl:when>
<xsl:when test="$data/osm/bounds">
<xsl:for-each select="$data/osm/bounds/@maxlon">
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$data/osm/node/@lon">
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Derive the latitude of the middle of the map -->
<xsl:variable name="middleLatitude" select="($topRightLatitude + $bottomLeftLatitude) div 2.0"/>
<!--woohoo lets do trigonometry in xslt -->
<!--convert latitude to radians -->
<xsl:variable name="latr" select="$middleLatitude * 3.1415926 div 180.0"/>
<!--taylor series: two terms is 1% error at lat<68 and 10% error lat<83. we probably need polar projection by then -->
<xsl:variable name="coslat" select="1 - ($latr * $latr) div 2 + ($latr * $latr * $latr * $latr) div 24"/>
<xsl:variable name="projection" select="1 div $coslat"/>
<xsl:variable name="dataWidth" select="(number($topRightLongitude)-number($bottomLeftLongitude))*10000*$scale"/>
<xsl:variable name="dataHeight" select="(number($topRightLatitude)-number($bottomLeftLatitude))*10000*$scale*$projection"/>
<xsl:variable name="km" select="(0.0089928*$scale*10000*$projection)"/>
<xsl:variable name="documentWidth">
<xsl:choose>
<xsl:when test="$dataWidth > (number(/rules/@minimumMapWidth) * $km)">
<xsl:value-of select="$dataWidth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(/rules/@minimumMapWidth) * $km"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="documentHeight">
<xsl:choose>
<xsl:when test="$dataHeight > (number(/rules/@minimumMapHeight) * $km)">
<xsl:value-of select="$dataHeight"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(/rules/@minimumMapHeight) * $km"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="width" select="($documentWidth div 2) + ($dataWidth div 2)"/>
<xsl:variable name="height" select="($documentHeight div 2) + ($dataHeight div 2)"/>
<xsl:variable name="symbols">
<xsl:variable name="allSymbols">
<xsl:if test="$symbolsDir != ''">
<!-- Get all symbols mentioned in the rules file from the symbolsDir -->
<xsl:for-each select="/rules//symbol/@ref | /rules//areaSymbol/@ref">
<xsl:variable name="symbolName" select="."/>
<xsl:variable name="file" select="document(concat($symbolsDir,'/', $symbolName, '.svg'))"/>
<xsl:choose>
<xsl:when test="$file/svg:svg/svg:defs/svg:symbol">
<symbol>
<xsl:copy-of select="$file/svg:svg/svg:defs/svg:symbol/@*"/>
<xsl:copy-of select="$file/svg:svg/svg:defs/svg:symbol/*"/>
</symbol>
</xsl:when>
<xsl:otherwise>
<symbol>
<xsl:copy-of select="$file/svg:svg/@*"/>
<xsl:attribute name="id">
<xsl:value-of select="concat('symbol-', $symbolName)"/>
</xsl:attribute>
<xsl:copy-of select="$file/svg:svg/*"/>
</symbol>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
<xsl:for-each select="/rules/defs/svg:svg">
<symbol>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="*"/>
</symbol>
</xsl:for-each>
<xsl:copy-of select="/rules/defs/svg:symbol"/>
</xsl:variable>
<xsl:for-each select="exslt:node-set($allSymbols)/svg:symbol">
<xsl:sort select="@id"/>
<xsl:variable name="prev" select="preceding-sibling::svg:symbol[position()=1]"/>
<xsl:if test="not($prev) or $prev/@id != @id">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="labels" xmlns="http://openstreetmap.org/osmarender-labels-rtf">
<xsl:for-each select="$data/osm/relation[tag[@k='type' and @v='label']]">
<xsl:choose>
<xsl:when test="count(member[@role='object']) = 0"/>
<xsl:when test="count(member[@role='object']) = 1">
<area id="{member[@role='object']/@ref}">
<xsl:for-each select="member[@role='label']">
<label ref="{@ref}"/>
</xsl:for-each>
</area>
</xsl:when>
<xsl:otherwise>
<area id="{member[@role='object'][1]/@ref}">
<xsl:for-each select="member[@role='label']">
<label ref="{@ref}"/>
</xsl:for-each>
</area>
<area id="{member[@role='object'][position() != 1]/@ref}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="instructionZIndex" xmlns="http://openstreetmap.org/osmarender-z-rtf">
<instruction name="text" relative="true" value="1"/>
</xsl:variable>
<!-- Main template -->
<xsl:template match="/rules">
<!-- Include an external css stylesheet if one was specified in the rules file -->
<xsl:if test="@xml-stylesheet">
<xsl:processing-instruction name="xml-stylesheet">
href="<xsl:value-of select="@xml-stylesheet"/>" type="text/css"
</xsl:processing-instruction>
</xsl:if>
<xsl:variable name="svgWidth" select="$documentWidth + $extraWidth"/>
<xsl:variable name="svgHeight" select="$documentHeight + $marginaliaTopHeight + $marginaliaBottomHeight"/>
<svg id="main"
version="1.1"
baseProfile="{$svgBaseProfile}"
width="{$svgWidth}px"
height="{$svgHeight}px"
preserveAspectRatio="none"
viewBox="{-$extraWidth div 2} {-$extraHeight div 2} {$svgWidth} {$svgHeight}">
<xsl:if test="/rules/@interactive='yes'">
<xsl:attribute name="onscroll">fnOnScroll(evt)</xsl:attribute>
<xsl:attribute name="onzoom">fnOnZoom(evt)</xsl:attribute>
<xsl:attribute name="onload">fnOnLoad(evt)</xsl:attribute>
<xsl:attribute name="onmousedown">fnOnMouseDown(evt)</xsl:attribute>
<xsl:attribute name="onmousemove">fnOnMouseMove(evt)</xsl:attribute>
<xsl:attribute name="onmouseup">fnOnMouseUp(evt)</xsl:attribute>
</xsl:if>
<xsl:call-template name="metadata"/>
<!-- Include javaScript functions for all the dynamic stuff -->
<xsl:if test="/rules/@interactive='yes'">
<xsl:call-template name="javaScript"/>
</xsl:if>
<defs id="defs-rulefile">
<!-- Get any <defs> and styles from the rules file -->
<xsl:copy-of select="defs/*[local-name() != 'svg' and local-name() != 'symbol']"/>
</defs>
<!-- Symbols -->
<defs id="defs-symbols">
<xsl:copy-of select="$symbols"/>
</defs>
<!-- Included defs -->
<defs id="defs-included">
<xsl:for-each select="//include">
<xsl:copy-of select="document(@ref)/svg:svg/*"/>
</xsl:for-each>
</defs>
<!-- Pre-generate named path definitions for all ways -->
<xsl:variable name="allWays" select="$data/osm/way"/>
<defs id="defs-ways">
<xsl:for-each select="$allWays">
<xsl:call-template name="generateWayPaths"/>
</xsl:for-each>
</defs>
<!-- Clipping rectangle for map -->
<clipPath id="map-clipping">
<rect id="map-clipping-rect" x="0px" y="0px" height="{$documentHeight}px" width="{$documentWidth}px"/>
</clipPath>
<g id="map" clip-path="url(#map-clipping)" inkscape:groupmode="layer" inkscape:label="Map" transform="translate(0,{$marginaliaTopHeight})">
<!-- Draw a nice background layer -->
<rect id="background" x="0px" y="0px" height="{$documentHeight}px" width="{$documentWidth}px" class="map-background"/>
<!-- Process all the rules drawing all map features -->
<xsl:call-template name="processRules"/>
</g>
<!-- Draw map decoration -->
<g id="map-decoration" inkscape:groupmode="layer" inkscape:label="Map decoration" transform="translate(0,{$marginaliaTopHeight})">
<!-- Draw a grid if required -->
<xsl:if test="$showGrid='yes'">
<xsl:call-template name="drawGrid"/>
</xsl:if>
<!-- Draw a border if required -->
<xsl:if test="$showBorder='yes'">
<xsl:call-template name="drawBorder"/>
</xsl:if>
</g>
<!-- Draw map marginalia -->
<xsl:if test="($title != '') or ($showScale = 'yes') or ($showLicense = 'yes')">
<g id="marginalia" inkscape:groupmode="layer" inkscape:label="Marginalia">
<!-- Draw the title -->
<xsl:if test="$title!=''">
<xsl:call-template name="drawTitle">
<xsl:with-param name="title" select="$title"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="($showScale = 'yes') or ($showLicense = 'yes')">
<g id="marginalia-bottom" inkscape:groupmode="layer" inkscape:label="Marginalia (Bottom)" transform="translate(0,{$marginaliaTopHeight})">
<!-- Draw background for marginalia at bottom -->
<rect id="marginalia-background" x="0px" y="{$documentHeight + 5}px" height="40px" width="{$documentWidth}px" class="map-marginalia-background"/>
<!-- Draw the scale in the bottom left corner -->
<xsl:if test="$showScale='yes'">
<xsl:call-template name="drawScale"/>
</xsl:if>
<!-- Draw Creative commons license -->
<xsl:if test="$showLicense='yes'">
<xsl:call-template name="in-image-license">
<xsl:with-param name="dx" select="$documentWidth"/>
<xsl:with-param name="dy" select="$documentHeight"/>
</xsl:call-template>
</xsl:if>
</g>
</xsl:if>
</g>
</xsl:if>
<!-- Draw labels and controls that are in a static position -->
<g id="staticElements" transform="scale(1) translate(0,0)">
<!-- Draw the +/- zoom controls -->
<xsl:if test="/rules/@interactive='yes'">
<xsl:call-template name="zoomControl"/>
</xsl:if>
</g>
</svg>
</xsl:template>
<!-- Path Fragment Drawing -->
<xsl:template name="drawPath">
<xsl:param name='instruction' />
<xsl:param name='pathId'/>
<xsl:param name='extraClasses'/>
<xsl:param name='extraStyles'/>
<xsl:variable name="maskId" select="concat('mask_',$pathId)"/>
<xsl:call-template name='generateMask'>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name='pathId' select='$pathId'/>
<xsl:with-param name='maskId' select='$maskId'/>
</xsl:call-template>
<use xlink:href="#{$pathId}">
<!-- Copy all attributes from instruction -->
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes" />
<!-- Add in any extra classes -->
<xsl:attribute name="class">
<xsl:value-of select='$instruction/@class'/>
<xsl:text> </xsl:text>
<xsl:value-of select="$extraClasses"/>
</xsl:attribute>
<!-- If there is a mask class then include the mask attribute -->
<xsl:if test='$instruction/@mask-class'>
<xsl:attribute name="mask">url(#<xsl:value-of select="$maskId"/>)</xsl:attribute>
</xsl:if>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<!-- Add additional style definitions if set -->
<xsl:if test="string($extraStyles) != ''">
<xsl:attribute name="style">
<xsl:value-of select="$extraStyles"/>
</xsl:attribute>
</xsl:if>
</use>
</xsl:template>
<xsl:template name='generateMask'>
<xsl:param name='instruction' />
<xsl:param name='pathId'/>
<xsl:param name='maskId'/>
<!-- If the instruction has a mask class -->
<xsl:if test='$instruction/@mask-class'>
<mask id="{$maskId}" maskUnits="userSpaceOnUse">
<use xlink:href="#{$pathId}" class="{$instruction/@mask-class} osmarender-stroke-linecap-round osmarender-mask-black" />
<!-- Required for Inkscape bug -->
<use xlink:href="#{$pathId}" class="{$instruction/@class} osmarender-mask-white" />
<use xlink:href="#{$pathId}" class="{$instruction/@mask-class} osmarender-stroke-linecap-round osmarender-mask-black" />
</mask>
</xsl:if>
</xsl:template>
<!-- Draw a line for the current <way> element using the formatting of the current <line> instruction -->
<xsl:template name="drawWay">
<xsl:param name="instruction"/>
<xsl:param name="way"/>
<!-- The current way element if applicable -->
<xsl:variable name="layer">
<xsl:choose>
<xsl:when test="$way/tag[@k='layer']">
<xsl:value-of select="$way/tag[@k='layer']/@v"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="extraClasses">
<xsl:if test="$instruction/@suppress-markers-tag != ''">
<xsl:variable name="suppressMarkersTag" select="$instruction/@suppress-markers-tag" />
<xsl:variable name="firstNode" select="key('nodeById',$way/nd[1]/@ref)"/>
<xsl:variable name="firstNodeMarkerGroupConnectionCount"
select="count(key('wayByNode',$firstNode/@id)/tag[@k=$suppressMarkersTag and ( @v = 'yes' or @v = 'true' )])" />
<xsl:variable name="lastNode" select="key('nodeById',$way/nd[last()]/@ref)"/>
<xsl:variable name="lastNodeMarkerGroupConnectionCount"
select="count(key('wayByNode',$lastNode/@id)/tag[@k=$suppressMarkersTag and ( @v = 'yes' or @v = 'true' )])" />
<xsl:if test="$firstNodeMarkerGroupConnectionCount > 1">osmarender-no-marker-start</xsl:if>
<xsl:if test="$lastNodeMarkerGroupConnectionCount > 1"> osmarender-no-marker-end</xsl:if>
</xsl:if>
</xsl:variable>
<xsl:variable name='extraStyles'>
<!-- honor-width feature
If current instruction has 'honor-width' set to 'yes', make use of the
way's 'width' tag by adding an extra 'style' attribute to current way
(setting stroke-width to a new value).
-->
<xsl:if test="$instruction/@honor-width = 'yes'">
<!-- Get minimum width, use default of '0.1' if not set -->
<xsl:variable name='minimumWayWidth'>
<xsl:choose>
<xsl:when test='$instruction/@minimum-width'><xsl:value-of select='$instruction/@minimum-width'/></xsl:when>
<xsl:otherwise>0.1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Get maximum width, use default of '100' if not set -->
<xsl:variable name='maximumWayWidth'>
<xsl:choose>
<xsl:when test='$instruction/@maximum-width'><xsl:value-of select='$instruction/@maximum-width'/></xsl:when>
<xsl:otherwise>100</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name='givenWidth'>
<xsl:variable name='width'>
<xsl:choose>
<xsl:when test="contains($way/tag[@k = 'width']/@v, ' m')">
<xsl:value-of select="substring-before($way/tag[@k = 'width']/@v, ' m')" />
</xsl:when>
<xsl:when test="contains($way/tag[@k = 'width']/@v, 'm')">
<xsl:value-of select="substring-before($way/tag[@k = 'width']/@v, 'm')" />
</xsl:when>
<xsl:otherwise><xsl:value-of select="$way/tag[@k = 'width']/@v"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test='$width < $minimumWayWidth'><xsl:value-of select='$minimumWayWidth'/></xsl:when>
<xsl:when test='$width > $maximumWayWidth'><xsl:value-of select='$maximumWayWidth'/></xsl:when>
<xsl:otherwise><xsl:value-of select='$width'/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="number($givenWidth) > 0">
<!-- Get scaling factor, use default of '1' (no scaling) if not set -->
<xsl:variable name='ScaleFactor'>
<xsl:choose>
<xsl:when test="$instruction/@width-scale-factor != ''">
<xsl:value-of select='$instruction/@width-scale-factor'/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Set extraStyles' value -->
<xsl:if test="number($givenWidth) > 0">
<xsl:choose>
<xsl:when test="number($meter2pixelFactor)">
<xsl:value-of select="concat('stroke-width:', ($ScaleFactor * $givenWidth * $meter2pixelFactor), 'px')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('stroke-width:', ($ScaleFactor * $givenWidth * 0.1375), 'px')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$instruction/@smart-linecap='no'">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_normal_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses" select='$extraClasses'/>
<xsl:with-param name="extraStyles" select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="drawWayWithSmartLinecaps">
<xsl:with-param name="instruction" select="$instruction"/>
<xsl:with-param name="way" select="$way"/>
<xsl:with-param name="extraClasses" select='$extraClasses'/>
<xsl:with-param name="extraStyles" select='$extraStyles'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="drawWayWithSmartLinecaps">
<xsl:param name="instruction"/>
<xsl:param name="way"/>
<!-- The current way element if applicable -->
<xsl:param name="extraClasses"/>
<xsl:param name="extraStyles"/>
<xsl:variable name="layer">
<xsl:choose>
<xsl:when test="$way/tag[@k='layer']">
<xsl:value-of select="$way/tag[@k='layer']/@v"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- The first half of the first segment and the last half of the last segment are treated differently from the main
part of the way path. The main part is always rendered with a butt line-cap. Each end fragment is rendered with
either a round line-cap, if it connects to some other path, or with its default line-cap if it is not connected
to anything. That way, cul-de-sacs etc are terminated with round, square or butt as specified in the style for the
way. -->
<!-- First draw the middle section of the way with round linejoins and butt linecaps -->
<xsl:if test="count($way/nd) > 1">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_mid_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name='extraClasses'>osmarender-stroke-linecap-butt osmarender-no-marker-start osmarender-no-marker-end</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:if>
<!-- For the first half segment in the way, count the number of segments that link to the from-node of this segment.
Also count links where the layer tag is less than the layer of this way, if there are links on a lower layer then
we can safely draw a butt line-cap because the lower layer will already have a round line-cap. -->
<!-- Process the first segment in the way -->
<xsl:variable name="firstNode" select="key('nodeById',$way/nd[1]/@ref)"/>
<!-- Count the number of segments connecting to the from node. If there is only one (the current segment) then draw a default line. -->
<xsl:variable name="firstNodeConnectionCount" select="count(key('wayByNode',$firstNode/@id))" />
<!-- Count the number of connectors at a layer lower than the current layer -->
<xsl:variable name="firstNodeLowerLayerConnectionCount" select="
count(key('wayByNode',$firstNode/@id)/tag[@k='layer' and @v < $layer]) +
count(key('wayByNode',$firstNode/@id)[count(tag[@k='layer'])=0 and $layer > 0])
" />
<xsl:choose>
<xsl:when test="$firstNodeConnectionCount=1">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_start_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-no-marker-end</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$firstNodeLowerLayerConnectionCount>0">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_start_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-butt osmarender-no-marker-end</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_start_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-round osmarender-no-marker-end</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<!-- Process the last segment in the way -->
<xsl:variable name="lastNode" select="key('nodeById',$way/nd[last()]/@ref)"/>
<!-- Count the number of segments connecting to the last node. If there is only one (the current segment) then draw
a default line. -->
<xsl:variable name="lastNodeConnectionCount" select="count(key('wayByNode',$lastNode/@id))" />
<!-- Count the number of connectors at a layer lower than the current layer -->
<xsl:variable name="lastNodeLowerLayerConnectionCount" select="
count(key('wayByNode',$lastNode/@id)/tag[@k='layer' and @v < $layer]) +
count(key('wayByNode',$lastNode/@id)[count(tag[@k='layer'])=0 and $layer > 0])
" />
<xsl:choose>
<xsl:when test="$lastNodeConnectionCount=1">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_end_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-no-marker-start</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lastNodeLowerLayerConnectionCount>0">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_end_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-butt osmarender-no-marker-start</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathId' select="concat('way_end_',$way/@id)"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses"><xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-round osmarender-no-marker-start</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Draw a circle for the current <node> element using the formatting of the current <circle> instruction -->
<xsl:template name="drawCircle">
<xsl:param name="instruction"/>
<xsl:param name="lat"><xsl:value-of select="@lat" /></xsl:param>
<xsl:param name="lon"><xsl:value-of select="@lon" /></xsl:param>
<xsl:variable name="x" select="($width)-((($topRightLongitude)-($lon))*10000*$scale)"/>
<xsl:variable name="y" select="($height)+((($bottomLeftLatitude)-($lat))*10000*$scale*$projection)"/>
<circle cx="{$x}" cy="{$y}">
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes"/>
<!-- Copy all the svg attributes from the <circle> instruction -->
</circle>
</xsl:template>
<xsl:template name="renderSymbol">
<xsl:param name="instruction"/>
<xsl:param name="lon"/>
<xsl:param name="lat"/>
<xsl:variable name="x" select="($width)-((($topRightLongitude)-($lon))*10000*$scale)"/>
<xsl:variable name="y" select="($height)+((($bottomLeftLatitude)-($lat))*10000*$scale*$projection)"/>
<xsl:variable name="symbol" select="exslt:node-set($symbols)/svg:symbol[@id=concat('symbol-',$instruction/@ref)]"/>
<xsl:variable name="useElement">
<use>
<xsl:if test="$instruction/@ref">
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat('#symbol-', $instruction/@ref)"/>
</xsl:attribute>
</xsl:if>
<!-- Use symbol size by default -->
<xsl:attribute name="width">
<xsl:value-of select="$symbol/@width"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="$symbol/@height"/>
</xsl:attribute>
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes"/>
<!-- Copy all the attributes from the <symbol> instruction. Overwrite width and heigth if specified -->
<!-- Clear transform attribute. It's set later to <g> before symbolShift to make symbol centering work -->
<xsl:attribute name="transform"/>
</use>
</xsl:variable>
<!-- Move symbol based on position attribute -->
<xsl:variable name="symbolShift">
<xsl:if test="$instruction[@position='center']">
<xsl:value-of select="concat('translate(', -number(exslt:node-set($useElement)/svg:use/@width) div 2.0, ',', - number(exslt:node-set($useElement)/svg:use/@height) div 2.0, ')')"/>
</xsl:if>
</xsl:variable>
<g transform="translate({$x},{$y}) scale({$symbolScale}) {$instruction/@transform} {$symbolShift}">
<xsl:copy-of select="$useElement"/>
</g>
</xsl:template>
<!-- Draw a symbol for the current <node> element using the formatting of the current <symbol> instruction -->
<xsl:template name="drawSymbol">
<xsl:param name="instruction"/>
<xsl:call-template name="renderSymbol">
<xsl:with-param name="instruction" select="$instruction"/>
<xsl:with-param name="lon" select="@lon"/>
<xsl:with-param name="lat" select="@lat"/>
</xsl:call-template>
</xsl:template>
<!-- Render the appropriate attribute of the current <node> element using the formatting of the current <text> instruction -->
<xsl:template name="renderText">
<xsl:param name="instruction"/>
<xsl:param name="lon"/>
<xsl:param name="lat"/>
<xsl:param name="text"/>
<xsl:variable name="x" select="($width)-((($topRightLongitude)-($lon))*10000*$scale)"/>
<xsl:variable name="y" select="($height)+((($bottomLeftLatitude)-($lat))*10000*$scale*$projection)"/>
<text>
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes"/>
<xsl:attribute name="x">
<xsl:value-of select="$x"/>
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="$y"/>
</xsl:attribute>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</text>
</xsl:template>
<!-- Render the appropriate attribute of the current <segment> element using the formatting of the current <textPath> instruction -->
<xsl:template name="renderTextPath">
<xsl:param name="instruction"/>
<xsl:param name="pathId"/>
<xsl:param name="pathDirection"/>
<xsl:param name='text'/>
<xsl:variable name='pathLengthSquared'>
<xsl:call-template name='getPathLength'>
<xsl:with-param name='pathLengthMultiplier'>
<!-- This factor is used to adjust the path-length for comparison with text along a path to determine whether it will fit. -->
<xsl:choose>
<xsl:when test='$instruction/@textAttenuation'>
<xsl:value-of select='$instruction/@textAttenuation'/>
</xsl:when>
<xsl:when test='string($textAttenuation)'>
<xsl:value-of select='$textAttenuation'/>
</xsl:when>
<xsl:otherwise>99999999</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name='nodes' select='nd'/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name='textLength' select='string-length($text)' />
<xsl:variable name='textLengthSquared100' select='($textLength)*($textLength)' />
<xsl:variable name='textLengthSquared90' select='($textLength *.9)*($textLength*.9)' />
<xsl:variable name='textLengthSquared80' select='($textLength *.8)*($textLength*.8)' />
<xsl:variable name='textLengthSquared70' select='($textLength *.7)*($textLength*.7)' />
<xsl:choose>
<xsl:when test='($pathLengthSquared) > $textLengthSquared100'>
<text>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-text"/>
<textPath xlink:href="#{$pathId}">
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-textPath"/>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</textPath>
</text>
</xsl:when>
<xsl:when test='($pathLengthSquared) > ($textLengthSquared90)'>
<text>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-text"/>
<textPath xlink:href="#{$pathId}">
<xsl:attribute name='font-size'>90%</xsl:attribute>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-textPath"/>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</textPath>
</text>
</xsl:when>
<xsl:when test='($pathLengthSquared) > ($textLengthSquared80)'>
<text>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-text"/>
<textPath xlink:href="#{$pathId}">
<xsl:attribute name='font-size'>80%</xsl:attribute>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-textPath"/>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</textPath>
</text>
</xsl:when>
<xsl:when test='($pathLengthSquared) > ($textLengthSquared70)'>
<text>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-text"/>
<textPath xlink:href="#{$pathId}">
<xsl:attribute name='font-size'>70%</xsl:attribute>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-textPath"/>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</textPath>
</text>
</xsl:when>
<xsl:otherwise />
<!-- Otherwise don't render the text -->
</xsl:choose>
</xsl:template>
<xsl:template name='getPathLength'>
<xsl:param name='sumLon' select='number("0")' />
<!-- initialise sum to zero -->
<xsl:param name='sumLat' select='number("0")' />
<!-- initialise sum to zero -->
<xsl:param name='nodes'/>
<xsl:param name='pathLengthMultiplier'/>
<xsl:choose>
<xsl:when test='$nodes[1] and $nodes[2]'>
<xsl:variable name='fromNode' select='key("nodeById",$nodes[1]/@ref)'/>
<xsl:variable name='toNode' select='key("nodeById",$nodes[2]/@ref)'/>
<xsl:variable name='lengthLon' select='($fromNode/@lon)-($toNode/@lon)'/>
<xsl:variable name='absLengthLon'>
<xsl:choose>
<xsl:when test='$lengthLon < 0'>