forked from FreemapSlovakia/FreemapDiSK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osmarender.xsl
4032 lines (3601 loc) · 202 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.8
with - fixed mask
- new area generation
- selective bezier hint
- 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, Jozef Vince
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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
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:osmxapi='http://www.informationfreeway.org/osmxapi/0.5'
xmlns:exslt="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
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/@file"/>
<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'/>
<xsl:param name='lineSpacing' select='/rules/@lineSpacing'/>
<xsl:param name="withOSMLayers" select="/rules/@withOSMLayers"/>
<xsl:param name="svgBaseProfile" select="/rules/@svgBaseProfile"/>
<xsl:param name="symbolsDir" select="/rules/@symbolsDir"/>
<!-- skip generating ways and areas - for freemaps names layer -->
<xsl:param name="processWays" select="/rules/@processWays"/>
<!-- Show relations -->
<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="date">2011-01-01</xsl:variable>
<xsl:variable name="year">2011</xsl:variable>
<!-- Calculate the size of the bounding box based on the file content -->
<xsl:variable name="bllat">
<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:variable>
<xsl:variable name="bllon">
<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:variable>
<xsl:variable name="trlat">
<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:variable>
<xsl:variable name="trlon">
<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:variable>
<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:value-of select="$data/osm/bounds/@minlat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$bllat"/>
</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:value-of select="$data/osm/bounds/@minlon"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$bllon"/>
</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:value-of select="$data/osm/bounds/@maxlat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$trlat"/>
</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:value-of select="$data/osm/bounds/@maxlon"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$trlon"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="dataWidth" select="(number($topRightLongitude)-number($bottomLeftLongitude))*$scale"/>
<xsl:variable name="dataHeight" select="(number($topRightLatitude)-number($bottomLeftLatitude))*$scale"/>
<xsl:variable name="km" select="($scale)"/>
<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 + $dataWidth) div 2"/>
<xsl:variable name="height" select="($documentHeight + $dataHeight) div 2"/>
<!-- 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"/>
<xsl:variable name="svgHeight" select="$documentHeight"/>
<svg id="main"
version="1.1"
baseProfile="{$svgBaseProfile}"
width="{$svgWidth}px"
height="{$svgHeight}px"
preserveAspectRatio="none"
viewBox="0 0 {$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>
<!-- required for some of the filters working with backgroud images -->
<xsl:if test="/rules/@withFilters='yes'">
<xsl:attribute name="enable-background">new</xsl:attribute>
</xsl:if>
<xsl:call-template name="metadata"/>
<defs id="defs-rulefile">
<!-- Get any <defs> and styles from the rules file -->
<xsl:copy-of select="defs/*"/>
</defs>
<!-- Symbols -->
<xsl:if test="$symbolsDir != ''">
<!-- Get all symbols mentioned in the rules file from the symbolsDir -->
<defs id="defs-symbols">
<xsl:for-each select="/rules//symbol/@ref">
<xsl:copy-of select="document(concat($symbolsDir,'/', ., '.svg'))/svg:svg/svg:defs/svg:symbol"/>
</xsl:for-each>
</defs>
</xsl:if>
<defs id="defs-included">
<!-- Included defs -->
<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:if test="$processWays='yes'">
<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>
</xsl:if>
<!-- 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,0)">
<!-- 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>
</svg>
</xsl:template>
<!-- Path Fragment Drawing -->
<xsl:template name="drawPath">
<xsl:param name='instruction' />
<xsl:param name='pathId'/>
<xsl:param name='pathPrefix'/>
<xsl:param name='extraClasses'/>
<xsl:param name='extraStyles'/>
<xsl:variable name="maskRef">
<xsl:if test="$instruction/@mask-class != ''">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="concat('mask_',$instruction/@mask-class,'_',$pathId)"/>
<xsl:with-param name="replace" >
<xsl:text > </xsl:text>
</xsl:with-param>
<xsl:with-param name="with" >
<xsl:text >_</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:variable >
<xsl:variable name="pathRef" select="concat($pathPrefix,'',$pathId)"/>
<xsl:call-template name='generateMask'>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name='pathRef' select='$pathRef'/>
<xsl:with-param name='maskRef' select='$maskRef'/>
<xsl:with-param name="maskMode" select="'way'" />
</xsl:call-template>
<use xlink:href="#{$pathRef}">
<!-- 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">
<xsl:value-of select ="concat('url(#',$maskRef,')')" />
</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='pathRef'/>
<xsl:param name='maskRef'/>
<xsl:param name='maskMode'/>
<!-- If the instruction has a mask class -->
<xsl:if test='$instruction/@mask-class'>
<xsl:message>
maskRef: <xsl:value-of select='$maskRef'/>
pathRef: <xsl:value-of select='$pathRef'/>
</xsl:message>
<mask id="{$maskRef}" maskUnits="userSpaceOnUse">
<!-- Required for Inkscape bug -->
<xsl:choose>
<xsl:when test="$maskMode = 'area'">
<use xlink:href="#{$pathRef}" class="{$instruction/@mask-class}" />
</xsl:when>
<xsl:when test="$maskMode = 'way'">
<use xlink:href="#{$pathRef}" class="{$instruction/@mask-class} osmarender-stroke-linecap-round osmarender-mask-black" />
<use xlink:href="#{$pathRef}" class="{$instruction/@class} osmarender-mask-white" />
<use xlink:href="#{$pathRef}" class="{$instruction/@mask-class} osmarender-stroke-linecap-round osmarender-mask-black" />
</xsl:when>
</xsl:choose>
</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:param name="layer"/>
<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>
<!-- 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:variable name='extraStyles'>
<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>
<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>
<xsl:variable name='pixelOffset'>
<xsl:choose>
<xsl:when test="$instruction/@pixel-offset != ''">
<xsl:value-of select='$instruction/@pixel-offset'/>
</xsl:when>
<xsl:otherwise>0</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 + $pixelOffset), 'px')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('stroke-width:', ($scaleFactor * $givenWidth * 0.1375 + $pixelOffset), 'px')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:variable>
<xsl:if test ="$extraStyles != ''">
<xsl:message>
WayId: <xsl:value-of select='$way/@id'/>
extraStyles: <xsl:value-of select='$extraStyles'/>
</xsl:message>
</xsl:if>
<xsl:choose>
<!-- !!! Dodi -->
<xsl:when test="$instruction/@bezier-hint='no'">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'x_way_normal_'" />
<xsl:with-param name='pathId' select="$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:when test="$instruction/@smart-linecap='no'">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_normal_'"/>
<xsl:with-param name='pathId' select="$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="layer" select="$layer"/>
<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="layer"/>
<xsl:param name="extraClasses"/>
<xsl:param name="extraStyles"/>
<!-- 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 fragement 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. -->
<!-- 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 node in the way -->
<xsl:variable name="firstNode" select='key("nodeById",$way/nd[key("nodeById",@ref)][1]/@ref)'/>
<!-- Process the last node in the way -->
<xsl:variable name="lastNode" select='key("nodeById",$way/nd[key("nodeById",@ref)][last()]/@ref)'/>
<!-- Count the number of ways connecting to the from node. If there is only one (the current way) then draw a default line. -->
<xsl:variable name="firstNodeConnectionCount" select="count(key('wayByNode',$firstNode/@id))" />
<!-- Count the number of ways connecting to the last node. If there is only one (the current way) 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="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]) " />
<!-- Count the number of connectors at a layer higher than the current layer -->
<!-- <xsl:variable name="firstNodeUpperLayerConnectionCount" 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]) " /> -->
<!-- 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]) " />
<!-- Count the number of connectors at a layer higher than the current layer -->
<!-- <xsl:variable name="lastNodeUpperLayerConnectionCount" 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:if test='count($way/nd[key("nodeById",@ref)]) > 1'>
<xsl:choose>
<xsl:when test="($firstNodeConnectionCount > 1) and
($lastNodeConnectionCount > 1) and
($firstNodeLowerLayerConnectionCount=0) and
($lastNodeLowerLayerConnectionCount=0)">
<!-- most common "special case" - we can safely draw round line ends for core and casing -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_normal_'" />
<xsl:with-param name='pathId' select="$way/@id"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses">
<xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-round
</xsl:with-param>
<xsl:with-param name="extraStyles" select='$extraStyles' />
</xsl:call-template>
</xsl:when>
<xsl:when test="($firstNodeConnectionCount > 1) and
($lastNodeConnectionCount > 1) and
($firstNodeLowerLayerConnectionCount > 0) and
($lastNodeLowerLayerConnectionCount > 0)">
<!-- most common "special case - bridges " - we can safely draw round line ends for cores and butt for casings -->
<xsl:choose>
<!-- round for cores -->
<xsl:when test="$instruction/@smart-linecap='core'">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_normal_'" />
<xsl:with-param name='pathId' select="$way/@id"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses">
<xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-round
</xsl:with-param>
<xsl:with-param name="extraStyles" select='$extraStyles' />
</xsl:call-template>
</xsl:when>
<xsl:otherwise >
<!-- butt for casings -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_normal_'" />
<xsl:with-param name='pathId' select="$way/@id"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses">
<xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-butt
</xsl:with-param>
<xsl:with-param name="extraStyles" select='$extraStyles' />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose >
</xsl:when>
<!-- other less common cases -->
<xsl:otherwise >
<!-- First draw the middle section of the way with round linecaps -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_mid_'" />
<xsl:with-param name='pathId' select="$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 osmarender-no-marker-end
</xsl:with-param>
<xsl:with-param name="extraStyles" select='$extraStyles' />
</xsl:call-template>
<xsl:choose>
<!-- No connection to node - SMART SQUARE END-->
<xsl:when test="$firstNodeConnectionCount=1">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_start_'" />
<xsl:with-param name='pathId' select="$way/@id"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses" >
<xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-square osmarender-no-marker-end
</xsl:with-param>
<xsl:with-param name="extraStyles" select='$extraStyles' />
</xsl:call-template>
</xsl:when>
<xsl:when test="$firstNodeLowerLayerConnectionCount>0">
<!-- lower layer node/way exists -->
<xsl:choose>
<!-- smart line caps for cores -->
<xsl:when test="$instruction/@smart-linecap='core'">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_start_'" />
<xsl:with-param name='pathId' select="$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 >
<!-- smart line caps for casings -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_start_'" />
<xsl:with-param name='pathId' select="$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:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- has node/way on current or on higher layer-->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_start_'" />
<xsl:with-param name='pathId' select="$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>
<xsl:choose>
<!-- No connection to node - SMART SQUARE END-->
<xsl:when test="$lastNodeConnectionCount=1">
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_end_'" />
<xsl:with-param name='pathId' select="$way/@id"/>
<xsl:with-param name='instruction' select='$instruction'/>
<xsl:with-param name="extraClasses">
<xsl:value-of select="$extraClasses"/> osmarender-stroke-linecap-square osmarender-no-marker-start
</xsl:with-param>
<xsl:with-param name='extraStyles' select='$extraStyles'/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lastNodeLowerLayerConnectionCount>0">
<!-- lower layer node/way exists -->
<xsl:choose>
<xsl:when test="$instruction/@smart-linecap='core'">
<!-- smart line caps for cores -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_end_'" />
<xsl:with-param name='pathId' select="$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:when>
<xsl:otherwise >
<!-- smart line caps for casings -->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_end_'" />
<xsl:with-param name='pathId' select="$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:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- has node/way on current or on higher layer-->
<xsl:call-template name='drawPath'>
<xsl:with-param name='pathPrefix' select="'way_end_'" />
<xsl:with-param name='pathId' select="$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:otherwise>
</xsl:choose >
</xsl:if >
</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:variable name="x" select="(@lon*$scale)"/>
<xsl:variable name="y" select="(@lat*$scale)"/>
<circle cx="{$x}" cy="{$y}">
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes"/>
<!-- Copy all the svg attributes from the <circle> instruction -->
</circle>
</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:variable name="x" select="(@lon*$scale)"/>
<xsl:variable name="y" select="(@lat*$scale)"/>
<g transform="translate({$x},{$y}) scale({$symbolScale})">
<use>
<xsl:if test="$instruction/@ref">
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat('#symbol-', $instruction/@ref)"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="$instruction/@*" mode="copyAttributes"/>
<!-- Copy all the attributes from the <symbol> instruction -->
</use>
</g>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</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:variable name="xo" select="(@lon*$scale)"/>
<xsl:variable name="yo" select="(@lat*$scale)"/>
<xsl:variable name="x" select="round($xo*256) div 256"/>
<xsl:variable name="y" select="round($yo*256) div 256"/>
<xsl:variable name="text_orig">
<xsl:value-of select="$instruction/@text-prefix"/>
<xsl:value-of select="tag[@k=$instruction/@k]/@v"/>
<xsl:value-of select="$instruction/@text-postfix"/>
</xsl:variable>
<xsl:variable name="text2">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select='$text_orig' />
<xsl:with-param name="replace" >
<xsl:text > nad </xsl:text>
</xsl:with-param>
<xsl:with-param name="with" >
<xsl:text > nad_</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text3">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select='$text2' />
<xsl:with-param name="replace">
<xsl:text > pod </xsl:text>
</xsl:with-param>
<xsl:with-param name="with" >
<xsl:text > pod_</xsl:text>
</xsl:with-param>
</xsl:call-template >
</xsl:variable>
<xsl:variable name="text4">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select='$text3' />
<xsl:with-param name="replace" >
<xsl:text > pri </xsl:text>
</xsl:with-param>
<xsl:with-param name="with">
<xsl:text > pri_</xsl:text>
</xsl:with-param>
</xsl:call-template >
</xsl:variable>
<xsl:variable name="text5">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select='$text4' />
<xsl:with-param name="replace" >
<xsl:text > na </xsl:text>
</xsl:with-param>
<xsl:with-param name="with">
<xsl:text > na_</xsl:text>
</xsl:with-param>
</xsl:call-template >
</xsl:variable>
<xsl:variable name="text">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select='$text5' />
<xsl:with-param name="replace" >
<xsl:text > - </xsl:text>
</xsl:with-param>
<xsl:with-param name="with">
<xsl:text > -_</xsl:text>
</xsl:with-param>
</xsl:call-template >
</xsl:variable>
<xsl:variable name="wordCount" select="1 + string-length($text) - string-length(translate($text,' ',''))"/>
<xsl:variable name='clineSpacing'>
<xsl:choose>
<xsl:when test='$instruction/@x-line-spacing'>
<xsl:value-of select='$instruction/@x-line-spacing'/>
</xsl:when>
<xsl:when test='number($lineSpacing)'>
<xsl:value-of select='$lineSpacing'/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test='$wordCount > 0 and $clineSpacing > 0'>
<!-- ked nie je nastavena hodnota line spacing... potom radsej nechat text v jednom riadku-->
<xsl:variable name='sy'>
<xsl:choose>
<xsl:when test='$instruction/@x-text-block-anchor = "top"'>
<xsl:value-of select ="$y - (($wordCount - 1 ) * $clineSpacing) "/>
</xsl:when>
<xsl:when test='$instruction/@x-text-block-anchor = "bottom"'>
<xsl:value-of select ="$y"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select ="$y - ((($wordCount - 1 ) * $clineSpacing) div 2)"/>
</xsl:otherwise>
</xsl:choose >
</xsl:variable >
<xsl:call-template name ='renderTextLines'>
<xsl:with-param name="instruction" select ="$instruction"/>
<xsl:with-param name='text' select ="$text"/>
<xsl:with-param name='wordCount' select ="$wordCount"/>
<xsl:with-param name='lineSpacing' select ="$clineSpacing"/>
<xsl:with-param name='x' select ="$x"/>
<xsl:with-param name='y' select ="$sy"/>
</xsl:call-template>
</xsl:when >
<xsl:otherwise >
<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_orig"/>
</text>
</xsl:otherwise>
</xsl:choose >
</xsl:template>
<xsl:template name="renderTextPathLabels">
<xsl:param name="instruction"/>
<xsl:param name="pathId"/>
<xsl:param name='text'/>
<xsl:param name='labelNo'/>
<xsl:param name='offsetStep'/>
<xsl:choose >
<xsl:when test ='$labelNo > 1 '>
<xsl:call-template name='renderTextPathLabels'>
<xsl:with-param name="instruction" select ="$instruction"/>
<xsl:with-param name="pathId" select ="$pathId"/>
<xsl:with-param name='text' select ="$text"/>
<xsl:with-param name='labelNo' select ="$labelNo - 1"/>
<xsl:with-param name='offsetStep' select ="$offsetStep"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
<text>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-text"/>
<textPath xlink:href="#{$pathId}">
<xsl:attribute name='startOffset'>
<xsl:value-of select ='($labelNo - 0.5) * $offsetStep'/>%
</xsl:attribute>
<xsl:apply-templates select="$instruction/@*" mode="renderTextPath-textPath"/>
<xsl:call-template name="getSvgAttributesFromOsmTags"/>
<xsl:value-of select="$text"/>
</textPath>
</text>
</xsl:template>
<!-- Render the appropriate attribute of the current <way> 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"/>