gpx2html.xslt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. geohash
  4. Copyright (c) 2020-2021 Marcus Rohrmoser mobile Software http://mro.name/~me. All rights reserved.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. https://www.w3.org/TR/xslt-10/
  16. -->
  17. <xsl:stylesheet
  18. xmlns="http://www.w3.org/1999/xhtml"
  19. xmlns:g="http://www.topografix.com/GPX/1/1"
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  21. exclude-result-prefixes="g"
  22. version="1.0">
  23. <xsl:variable name="dlon" select="0.3"/>
  24. <xsl:variable name="dlat" select="0.3"/>
  25. <xsl:variable name="zoom" select="11"/>
  26. <xsl:variable name="pin">📍</xsl:variable>
  27. <xsl:variable name="globe">🌐</xsl:variable>
  28. <xsl:variable name="camel">🐫</xsl:variable>
  29. <xsl:output
  30. method="html"
  31. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  32. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  33. <xsl:variable name="Geo2Rdf">
  34. <!--
  35. bookmarklet to conveniently pick geo coordinates from OSM/Google Maps.
  36. http://heimat.mro.name/bayern/allgaeu/steiner1994/#
  37. -->
  38. <![CDATA[ javascript:(
  39. function(bas)
  40. {
  41. /* selection has highest precendence: */
  42. var sel = null;
  43. if (window.getSelection) {
  44. sel = window.getSelection();
  45. } else if (document.getSelection) {
  46. sel = document.getSelection();
  47. } else if (document.selection) {
  48. sel = document.selection.createRange().text;
  49. }
  50. var tocheck = new Array();
  51. if(sel)
  52. tocheck.push(sel.toString());
  53. /* also test #link/@href (that's how google maps, share link does it. */
  54. sel = document.getElementById('link');
  55. if(sel && sel.href)
  56. tocheck.push(sel.href);
  57. /* last, not least, document location: */
  58. tocheck.push(document.location.href);
  59. /* patterns to test: */
  60. var pattern = [
  61. /#map=(?:[0-9]+)\/(-?[0-9.]+)\/(-?[0-9.]+)/, /* http://openstreetmap.org/ */
  62. /[?&]lat=(-?[0-9.]+)[?&]lon=(-?[0-9.]+)/, /* http://openstreetmap.de/ */
  63. /[?&]lon=(-?[0-9.]+)[?&]lat=(-?[0-9.]+)/, /* http://openstreetmap.de/ */
  64. /maps\/.*?@(-?[0-9.]+),(-?[0-9.]+),[0-9]+z/, /* https://maps.google.de/ */
  65. /[?&]ll=(-?[0-9.]+),(-?[0-9.]+)/, /* https://maps.google.com/ */
  66. ];
  67. for(var k=0;k<tocheck.length;k++) {
  68. var href = tocheck[k];
  69. for(var i=0;i<pattern.length;i++) {
  70. var m = href.match(pattern[i]);
  71. if(m) {
  72. var latlon = m[1] + ',' + m[2];
  73. window.prompt('#🌐 Geohash',bas+'?q='+latlon);
  74. /* window.location.href = bas+'?q='+latlon; */
  75. return;
  76. }
  77. }
  78. }
  79. window.alert('No coord found in '+bas);
  80. }('../')); ]]>
  81. </xsl:variable>
  82. <xsl:template match="/">
  83. <xsl:apply-templates select="g:gpx"/>
  84. </xsl:template>
  85. <xsl:template match="g:gpx">
  86. <html xmlns="http://www.w3.org/1999/xhtml">
  87. <xsl:call-template name="head"/>
  88. <xsl:variable name="bbox" select="g:metadata/g:bounds"/>
  89. <xsl:variable name="wpt" select="g:wpt[1]"/>
  90. <body>
  91. <iframe src="https://www.openstreetmap.org/export/embed.html?bbox={$bbox/@minlon},{$bbox/@minlat},{$bbox/@maxlon},{$bbox/@maxlat}&amp;marker={$wpt/@lat},{$wpt/@lon}"/>
  92. <form action="." id="search_form" name="search_form">
  93. <input name="q" placeholder="geo:lat,lon" size="24" value="geo:{$wpt/@lat},{$wpt/@lon}" autofocus="autofocus" />
  94. <!--
  95. <span>Target URL</span>
  96. <input name="redir" size="60" placeholder="https://www.openstreetmap.org/?mlat={lat}&amp;mlon={lon}#map={zoom}/{lat}/{lon}">
  97. <xsl:attribute name="value">https://www.openstreetmap.org/?mlat={lat}&amp;mlon={lon}#map={zoom}/{lat}/{lon}</xsl:attribute>
  98. </input>
  99. <xsl:text> </xsl:text>
  100. -->
  101. <button type="submit">Go</button>
  102. <small id="standalone">
  103. <xsl:value-of select="$globe"/>
  104. <xsl:variable name="mapurl">
  105. https://www.openstreetmap.org/?mlat=<xsl:value-of select="$wpt/@lat"/>&amp;mlon=<xsl:value-of select="$wpt/@lon"/>
  106. </xsl:variable>
  107. <a href="{$mapurl}"><xsl:value-of select="$mapurl"/></a>
  108. </small>
  109. <xsl:text> </xsl:text>
  110. <small id="credits">Powered by <a href="./about">http://purl.mro.name/geohash <xsl:value-of select="$camel"/></a></small>
  111. <xsl:text> </xsl:text>
  112. <small>
  113. <a id="bookmarklet" href="{$Geo2Rdf}"><xsl:value-of select="$globe"/> Geohash Bookmarklet</a>
  114. <script>
  115. /* MIT License https://github.com/joliss/js-string-escape/blob/master/index.js */
  116. function jsStringEscape(string) {
  117. return ('' + string).replace(/["'\\\n\r\u2028\u2029]/g, function (character) {
  118. // Escape all characters not included in SingleStringCharacters and
  119. // DoubleStringCharacters on
  120. // http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
  121. switch (character) {
  122. case '"':
  123. case "'":
  124. case '\\':
  125. return '\\' + character
  126. // Four possible LineTerminator characters need to be escaped:
  127. case '\n':
  128. return '\\n'
  129. case '\r':
  130. return '\\r'
  131. case '\u2028':
  132. return '\\u2028'
  133. case '\u2029':
  134. return '\\u2029'
  135. }
  136. })
  137. }
  138. var a = document.getElementById("bookmarklet");
  139. a.href = a.href.replace("}('../'));", "}('"+jsStringEscape(window.location)+"/../'));");
  140. </script>
  141. </small>
  142. </form>
  143. </body>
  144. </html>
  145. </xsl:template>
  146. <xsl:template name="head">
  147. <head>
  148. <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
  149. <!-- https://developer.apple.com/library/IOS/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html#//apple_ref/doc/uid/TP40006509-SW26 -->
  150. <!-- http://maddesigns.de/meta-viewport-1817.html -->
  151. <!-- meta name="viewport" content="width=device-width"/ -->
  152. <!-- http://www.quirksmode.org/blog/archives/2013/10/initialscale1_m.html -->
  153. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  154. <title>#<xsl:value-of select="$globe"/> Geohash</title>
  155. <style type="text/css">
  156. /*<![CDATA[*/
  157. body {
  158. margin: 0;
  159. }
  160. iframe {
  161. border:0;
  162. height:100%;
  163. position:fixed; /* https://stackoverflow.com/a/2425694/349514 */
  164. width:100%;
  165. }
  166. form {
  167. left: 58px;
  168. line-height: 4ex;
  169. position: absolute;
  170. top: 4px;
  171. width: calc(100% - 59px);
  172. }
  173. input {
  174. background: white;
  175. }
  176. small {
  177. /* https://alligator.io/css/prevent-line-break/ */
  178. background-color: hsla(0,0%,100%,0.75);
  179. border: 2px solid #ccc;
  180. overflow: hidden;
  181. padding: 1.1ex;
  182. text-overflow: ellipsis;
  183. white-space: nowrap;
  184. }
  185. input,button {
  186. font-family: monospace;
  187. font-size: 10pt;
  188. padding: 0.8ex 1.5ex;
  189. }
  190. input,button,small {
  191. border-radius: 1ex;
  192. margin: 1.2ex;
  193. }
  194. /*]]>*/ </style>
  195. </head>
  196. </xsl:template>
  197. </xsl:stylesheet>