forked from tibetty/osm2geojson-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
270 lines (243 loc) · 9.26 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
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
<!--
demo page / introduction for osm2geojson-lite
https://github.com/tibetty/osm2geojson-lite
this page is based on https://github.com/aaronlidman/osm-and-geojson (c)Aaron Lidman, WTFPL
-->
<html>
<head>
<title>osm2geojson-lite</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="dist/osm2geojson-lite.js"></script>
<script type="text/javascript">
$(() => {
$("#toGeo").click(e => {
e.preventDefault();
let g = $('#geojson');
let osm = $('#osmdata').val() || '<osm></osm>';
let geojson = osm2geojson(osm, {completeFeature: true});
console.log(geojson);
let s = $('#snackbar');
$.ajax({
url: 'http://geojsonlint.com/validate',
type: 'post',
data: JSON.stringify(geojson),
dataType: 'json',
success: res => {
if (res.status === 'ok') {
s.html(`Converted geojson passed <a class="link" target="_blank" href="http://geojsonlint.com/">geojsonlint</a>'s validation`);
s.css('color', 'black');
s.attr('class', 'show');
setTimeout(() => s.attr('class', s.attr('class').replace('show', '')), 3000);
} else if (res.status === 'error') {
console.log(res.message);
s.html(`Converted geojson failed <a class="link" target="_blank" href="http://geojsonlint.com/">geojsonlint</a>'s validation`);
s.css('color', 'red');
s.attr('class', 'show');
setTimeout(() => s.attr('class', s.attr('class').replace('show', '')), 3000);
}
},
error: () => {
s.html(`Error happened when calling <a class="link" target="_blank" href="http://geojsonlint.com/">geojsonlint</a>'s web service`);
s.css('color', 'red');
s.attr('class', 'show');
setTimeout(() => s.attr('class', s.attr('class').replace('show', '')), 3000);
}
});
g.val(JSON.stringify(geojson, null, 2));
});
});
</script>
<style type="text/css">
body {
font-size: 18px;
background: white;
font-family: "Helvetica Neue", Helvetica, sans-serif;
width: 960px;
margin: 50px auto;
color: #000022;
line-height: 1.7em
}
li {
line-height: 1.7em;
text-align: left;
list-style: none;
}
#left {
width: 49%;
float: left;
text-align: center;
}
#osmdata, #geojson {
width: 100%;
background: white;
border: 1px solid #cccccc;
height: 320px;
overflow: auto;
margin-bottom: 20px;
resize: none;
}
#right {
width: 49%;
float: right;
text-align: center;
}
.button {
display: inline-block;
text-shadow: 0px 0px 1px black;
border-radius: 3px;
color: white;
background: #0c74a9;
padding: 10px 15px;
font-weight: bold;
text-decoration: none;
}
.button:hover {
background: #0c5489;
}
.button:active {
box-shadow: inset 0 0 10px rgba(0,0,0,0.75);
}
textarea {
font-size: 14px;
font-family: "Lucida Console", "Courier New", Monospace;
line-height: 1.5em;
padding: 7px 10px;
outline: none;
}
textarea:focus {
box-shadow: 0 0 2px 1px #0c74a97f;
}
#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;
}
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #ccc;
color: black;
text-shadow: 0px 0px 1px white;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 43%;
bottom: 50%;
opacity: 0.75;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 50%; opacity: 0.75;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 50%; opacity: 0.75;}
}
@-webkit-keyframes fadeout {
from {bottom: 50%; opacity: 0.75;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 50%; opacity: 0.75;}
to {bottom: 0; opacity: 0;}
}
.link:link {
color: #0c74a9;
font-weight: bold;
font-style: italic;
text-decoration: none;
}
.link:visited {
text-decoration: none;
}
.link:hover {
color: #0c5489;
text-decoration: underline;
}
.link:active {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="snackbar"> [Used to display the result of the geojsonlint's validation] </div>
<a href="https://github.com/tibetty/osm2geojson-lite"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s.cdpn.io/31787/forkme_right_blue.png" alt="Fork me on GitHub"></a>
<div id="top">
<span id="name">osm2geojson-lite</span> converts OSM data to GeoJSON.
</div>
<div id="example">
<div id="left">
<h3>OSM Data</h3>
<textarea class="ta" id="osmdata" contenteditable="true"></textarea>
</div>
<div id="right">
<h3>GeoJSON</h3>
<textarea class="ta" id="geojson" contenteditable="true"></textarea>
</div>
<a class="button" href="" id="toGeo">Convert to GeoJSON →</a>
</div>
<div id="about">
<p>osm2geojson-lite is a lightweight (not as lightweight as xml2geojson-lite though) yet faster convertor for OSM data in XML or JSON formats to GeoJSON - much faster (the more complex the data source is, the more performance advantages it posesses) than osmtogeojson in most situations - implemented in pure JavaScript without any 3rd party dependency, please find more details from its <a class="link" target="_blank" href="https://www.npmjs.com/package/osm2geojson-lite">npm homepage</a></p>
<span style="font-weight: bold;">Usage: </span>
<ul>
<li>In the browser:
<ul>
<li><code>
<script src='your/path/to/osm2geojson-lite.js'/>
</code></li>
<li><code>
osm2geojson(osm, opts);
</code></li>
</ul>
</li>
<li>As a nodejs library:
<ul>
<li><code>
$ npm install osm2geojson-lite
</code></li>
<li><code>
const osm2geojson = require('osm2geojson-lite');<br>
osm2geojson(osm, opts);
</code></li>
</ul>
</li>
</ul>
Read more about the API in the official <a class="link" target="_blank" href="https://github.com/tibetty/osm2geojson-lite#api">documentation</a>.
<div id="download">
<p><a class="button" href="https://raw.githubusercontent.com/tibetty/osm2geojson-lite/master/dist/osm2geojson-lite.js">Download osm2geojson-lite.js</a><br/><br/>
github: <a class="link" target="_blank" href="https://github.com/tibetty/osm2geojson-lite">tibetty/osm2geojson-lite</a><br/>
npm: <a class="link" target="_blank" href="https://npmjs.org/package/osm2geojson-lite">osm2geojson-lite</a><br/>
</p>
</div>
</div>
</table>
</body>
</html>