-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.html
181 lines (163 loc) · 5.92 KB
/
index.html
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
<html>
<head>
<title>OSM & GeoJSON by Aaron Lidman</title>
<script type="text/javascript" src="osm_geojson.js"></script>
<script type="text/javascript">
function toGeo() {
var xml = document.getElementById('osmxml').value,
geojson = osm_geojson.osm2geojson(xml);
document.getElementById('geojson').value = JSON.stringify(geojson);
console.log(geojson);
}
function toXML() {
var json = document.getElementById('geojson').value,
xml = osm_geojson.geojson2osm(json);
document.getElementById('osmxml').value = xml;
console.log(xml);
}
</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 {
text-shadow: 0px 0px 1px black;
border-radius: 3px;
color: white;
background: #569834;
padding: 10px 15px;
font-weight: bold;
}
.button:hover {
background: #3A6623;
}
.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;
}
#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>
<div id="top">
<span id="name">OSM & GeoJSON</span> converts between OSM XML and GeoJSON.
</div>
<div id="example">
<div id="left">
<h3>OSM XML</h3>
<textarea id="osmxml" contenteditable="true"></textarea>
<span class="button" onclick="toGeo()">convert to GeoJSON →</span>
</div>
<div id="right">
<h3>GeoJSON</h3>
<textarea id="geojson" contenteditable="true"></textarea>
<span class="button" onclick="toXML()">← convert to OSM XML</span>
</div>
</div>
<div id="about">
<p>OSM & GeoJSON is a Javascript module for converting OSM XML to GeoJSON, and the inverse, GeoJSON to OSM XML. It is dependency free and works in the browser or nodejs. The OSM conversion is a fork of <a href="https://gist.github.com/tecoholic/1396990">OSM2GEO by tecoholic</a> with some improvements, most notably multipolygon support.</p>
<span style="font-weight: bold;">Usage: </span>
<ul>
<li>For the browser:
<ul>
<li><code><script src='osm_geojson.js'></script></code></li>
</ul>
</li>
<li>For nodejs:
<ul>
<li><code>npm install osm-and-geojson</code></li>
</ul>
</li>
</ul>
<ul>
<li><span style="font-weight: bold">osm_geojson.osm2geojson(OSM XML String or DOM)</span>
<ul>
<li class="disc">Convert a string or DOM of OSM XML to a GeoJSON object.</li>
<li class="disc">Add an optional second argument of <code>true</code>, osm_geojson.osm2geojson(yourOsm, true) to include metadata about the item in the properties, namespaced osm_*.</li>
</ul>
</li>
<li><span style="font-weight: bold;">osm_geojson.geojson2osm(GeoJSON String or Object)</span>
<ul>
<li class="disc">Convert a GeoJSON string or object into OSM XML.</li>
<li class="disc">Currently only points, polygons, and multipolygons (standalone or in feature collections), more coming soon.</li>
</ul>
</li>
</ul>
<div id="download">
<p><a class="button" style="text-decoration: none;" href="https://raw.github.com/aaronlidman/osm-and-geojson/master/osm_geojson.js" download="osm_geojson.js">download OSM & GeoJSON</a><br/><br/>
github: <a href="http://github.com/aaronlidman/osm-and-geojson">aaronlidman/osm-and-geojson</a><br/>
npm: <a href="https://npmjs.org/package/osm-and-geojson">osm-and-geojson</a><br/>
license: <a href="http://en.wikipedia.org/wiki/WTFPL">WTFPL</a><br/>
</p>
</div>
</div>
</table>
</body>
</html>