-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmaps.xsl
More file actions
168 lines (164 loc) · 9.31 KB
/
maps.xsl
File metadata and controls
168 lines (164 loc) · 9.31 KB
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
<xsl:stylesheet
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://www.tei-c.org/ns/1.0"
xmlns:x="http://www.w3.org/1999/xhtml"
xmlns:srophe="https://srophe.app"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:local="http://syriaca.org/ns"
exclude-result-prefixes="xs t x saxon local" version="3.0">
<xsl:output name="html" encoding="UTF-8" method="xhtml" indent="no" omit-xml-declaration="yes"/>
<!-- XSLT to generate leaflet maps -->
<xsl:template name="leafletMap">
<xsl:param name="nodes"/>
<xsl:variable name="coords" select="$nodes/descendant::t:geo"/>
<xsl:variable name="geojson">
<xsl:call-template name="geojson"><xsl:with-param name="nodes" select="$nodes"/></xsl:call-template>
</xsl:variable>
<div id="map-data" style="margin-bottom:3em;">
<!-- Leaflet javascript -->
<script type="text/javascript" src="/resources/leaflet/leaflet.js"/>
<div id="map"/>
<xsl:if test="count($coords) > 0">
<div class="hint map pull-right small">
* This map displays <xsl:value-of select="count($coords)"/> records. Only places with coordinates are displayed.
<button class="btn btn-default btn-sm" data-toggle="modal" data-target="#map-selection" id="mapFAQ">See why?</button>
</div>
</xsl:if>
<script type="text/javascript">
<xsl:text disable-output-escaping="yes"><![CDATA[
var terrain = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}');
var streets = L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{attribution: "OpenStreetMap"});
var imperium = L.tileLayer('https://dh.gu.se/tiles/imperium/{z}/{x}/{y}.png', {maxZoom: 10});
var placesgeo = ]]></xsl:text><xsl:sequence select="$geojson"/><xsl:text disable-output-escaping="yes"> <![CDATA[
var geojson = L.geoJson(placesgeo, {onEachFeature: function (feature, layer){
var typeText = feature.properties.type
var popupContent =
"<a href='" + feature.properties.uri + "' class='map-pop-title'>" +
feature.properties.name + "</a>" + (feature.properties.type ? "Type: " + typeText : "") +
(feature.properties.desc ? "<span class='map-pop-desc'>"+ feature.properties.desc +"</span>" : "");
layer.bindPopup(popupContent);
}
})
var map = L.map('map').fitBounds(geojson.getBounds(),{maxZoom: 5});
terrain.addTo(map);
L.control.layers({
"Terrain (default)": terrain,
"Streets": streets }).addTo(map);
geojson.addTo(map);
]]></xsl:text>
</script>
<div>
<div class="modal fade" id="map-selection" tabindex="-1" role="dialog" aria-labelledby="map-selectionLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true"> x </span>
<span class="sr-only">Close</span>
</button>
</div>
<div class="modal-body">
<div id="popup" style="border:none; margin:0;padding:0;margin-top:-2em;"/>
</div>
<div class="modal-footer">
<a class="btn" href="/documentation/faq.html" aria-hidden="true">See all FAQs</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
<![CDATA[
$('#mapFAQ').click(function(){
$('#popup').load( '/documentation/faq.html #map-selection',function(result){
$('#map-selection').modal({show:true});
});
});
]]>
</script>
</div>
</xsl:template>
<xsl:template name="geojson">
<xsl:param name="nodes"/>
<xsl:variable name="id">
<xsl:choose>
<xsl:when test="string(/*/@id)">
<xsl:value-of select="string(/*/@id)"/>
</xsl:when>
<xsl:when test="$nodes/descendant::t:publicationStmt/t:idno[@type='URI'][starts-with(.,$base-uri)]">
<xsl:value-of select="replace(replace($nodes/descendant::t:publicationStmt[1]/t:idno[@type='URI'][starts-with(.,$base-uri)][1],'/tei',''),'/source','')"/>
</xsl:when>
<xsl:when test="$nodes/descendant::t:publicationStmt/t:idno[@type='URI']">
<xsl:value-of select="replace(replace($nodes/descendant::t:publicationStmt[1]/t:idno[@type='URI'][1],'/tei',''),'/source','')"/>
</xsl:when>
<xsl:when test="$nodes/descendant::t:idno[@type='URI'][starts-with(.,$base-uri)]">
<xsl:value-of select="replace(replace($nodes/descendant::t:idno[@type='URI'][starts-with(.,$base-uri)][1],'/tei',''),'/source','')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($base-uri,'/0000')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="title">
<xsl:apply-templates select="normalize-space(string-join($nodes/descendant-or-self::t:titleStmt/t:title[1],''))"/>
</xsl:variable>
<xsl:variable name="desc">
<xsl:if test="$nodes/descendant::t:desc"><xsl:value-of select="normalize-space(string-join($nodes/descendant::t:desc[1],' '))"/></xsl:if>
</xsl:variable>
<xsl:variable name="type">
<xsl:choose>
<xsl:when test="$nodes/descendant::t:relationType != ''">
<xsl:value-of select="normalize-space(string-join($nodes/descendant::t:relationType))"/>
</xsl:when>
<xsl:when test="$nodes/descendant::t:place/@type">
<xsl:value-of select="$nodes/descendant::t:place/@type"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="coords">
<xsl:choose>
<xsl:when test="$nodes/descendant::t:location[@subtype = 'preferred']">
<xsl:value-of select="$nodes/descendant::t:location[@subtype = 'preferred']/t:geo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$nodes/descendant::t:geo[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="xml">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="type">FeatureCollection</string>
<array key="features">
<xsl:for-each select="$coords">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="type">Feature</string>
<map key="properties">
<string key="name"><xsl:value-of select="$title"/></string>
<xsl:if test="$desc != ''">
<string key="desc" xmlns="http://www.w3.org/2005/xpath-functions"><xsl:value-of select="replace($desc, '[\t\p{Zs}]', ' ')"/></string>
</xsl:if>
<xsl:if test="$type != ''">
<string key="type" xmlns="http://www.w3.org/2005/xpath-functions"><xsl:value-of select="$type"/></string>
</xsl:if>
</map>
<map key="geometry">
<string key="type">Point</string>
<array key="coordinates">
<number><xsl:value-of select="tokenize($coords,' ')[2]"/></number>
<number><xsl:value-of select="tokenize($coords,' ')[1]"/></number>
</array>
</map>
</map>
</xsl:for-each>
</array>
</map>
</xsl:variable>
<!-- OUTPUT -->
<xsl:value-of select="xml-to-json($xml, map { 'indent' : true() })"/>
</xsl:template>
</xsl:stylesheet>