UNPKG

osmtogeojson

Version:
203 lines (185 loc) 6.53 kB
<!-- demo page / introduction for osmtogeojson https://tyrasd.github.io/osmtogeojson https://github.com/tyrasd/osmtogeojson this page is based on https://github.com/aaronlidman/osm-and-geojson (c)Aaron Lidman, WTFPL --> <html> <head> <title>osmtogeojson</title> <script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script> <script type="text/javascript" src="osmtogeojson.js"></script> <script type="text/javascript"> function toGeo(e) { e.preventDefault(); var data = document.getElementById('osmxml').value || "<osm></osm>", geojson; try { data = $.parseXML(data); } catch(e) { data = JSON.parse(data); } geojson = osmtogeojson(data); document.getElementById('geojson').value = JSON.stringify(geojson, null, 4); console.log(geojson); } $(function() { $("#toGeo").click(toGeo); }); </script> <style type="text/css"> body { font-size: 18px; background: white; font-family: "Helvetica Neue", Helvetica, sans-serif; width: 960px; margin: 50px auto; color: #222; line-height: 1.7em } a { color: black; } li { line-height: 1.7em; text-align: left; list-style: none; } textarea, input { outline: none; } #left { width: 49%; float: left; text-align: center; } #osmxml, #geojson { width: 100%; background: white; border: 1px solid #ccc; height: 320px; overflow: auto; margin-bottom: 20px; } #right { width: 49%; float: right; text-align: center; } .button { display: inline-block; text-shadow: 0px 0px 1px black; border-radius: 3px; color: white; background: #A33; padding: 10px 15px; font-weight: bold; text-decoration: none; } .button:hover { background: #833; } .button:active { box-shadow: inset 0 0 10px rgba(0,0,0,0.75); } textarea { font-size: 13px; line-height: 1.5em; padding: 7px 10px; } #top { font-size: 22px; text-align: center; margin-bottom: 25px; } #name { font-size: 44px; letter-spacing: -1px; font-weight: bold; margin-right: 5px; } #example { clear: both; width: 100%; height: 500px; text-align: center; } #about { width: 720px; margin: 0 auto; } #download { margin: 50px auto 0 auto; text-align: center; } #dl { background: #569834; padding: 7px 10px; border-radius: 3px; color: white; font-weight: bold; font-size: 32px; } .disc { list-style: disc; } </style> </head> <body> <a href="https://github.com/tyrasd/osmtogeojson"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> <div id="top"> <span id="name">osmtogeojson</span> converts OSM data to GeoJSON. </div> <div id="example"> <div id="left"> <h3>OSM data</h3> <textarea id="osmxml" contenteditable="true"></textarea> </div> <div id="right"> <h3>GeoJSON</h3> <textarea id="geojson" contenteditable="true"></textarea> </div> <a class="button" href="" id="toGeo">convert to GeoJSON &rarr;</a> </div> <div id="about"> <p>osmtogeojson is a Javascript module for converting OSM data (OSM XML or Overpass JSON) to GeoJSON. It works in the browser, nodejs and can also be used as a command line tool. This OSM conversion code was written for and is maintained by the <a href="https://github.com/tyrasd/overpass-turbo">overpass-turbo</a> project.</p> <span style="font-weight: bold;">Usage: </span> <ul> <li>In the browser: <ul> <li><code> &lt;script src='osmtogeojson.js'>&lt;/script> </code></li> <li><code> osmtogeojson(osm_data); </code></li> </ul> </li> <li>As a nodejs library: <ul> <li><code> $ npm install osmtogeojson </code></li> <li><code> var osmtogeojson = require('osmtogeojson');<br> osmtogeojson(xml_data); </code></li> </ul> </li> <li>As a command line tool: <ul> <li><code> $ npm install -g osmtogeojson </code></li> <li><code> $ osmtogeojson file.osm > file.geojson </code></li> </ul> </li> </ul> Read more about the API in the official <a href="https://github.com/tyrasd/osmtogeojson#usage">documentation</a>. <div id="download"> <p><a class="button" href="https://github.com/tyrasd/osmtogeojson/raw/gh-pages/osmtogeojson.js">download osmtogeojson.js</a><br/><br/> github: <a href="https://github.com/tyrasd/osmtogeojson">tyrasd/osmtogeojson</a><br/> npm: <a href="https://npmjs.org/package/osmtogeojson">osmtogeojson</a><br/> license: <a href="https://github.com/tyrasd/osmtogeojson/blob/gh-pages/LICENSE">MIT</a><br/> </p> </div> </div> </table> </body> </html>