-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimizeJavascript.html
More file actions
41 lines (30 loc) · 1.14 KB
/
MinimizeJavascript.html
File metadata and controls
41 lines (30 loc) · 1.14 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
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Minimize js files</title>
<script src="http://code.jquery.com/jquery-git.js"></script>
<style>
textarea {
height: 250px;
width: 48%;
}
</style>
</head>
<body><textarea id="input" placeholder="Paste GeoJSON here">
</textarea>
<textarea id="output"></textarea>
<button id="run">Optimize</button>
<p style="margin-top:5px">Click "Optimize" to strip whitespace from your GeoJSON, and reduce the number of decimals in coordinates.</p>
<script>
// Set to number of decimals to keep
var keepDecimals = 4;
$('#run').click(function () {
console.log('starting');
$('#output').text($('#input').val().replace(/\s/g, '').replace(/(\[-?\d+)\.(\d+)(,-?\d+)\.(\d+)(\])/g, function (s1, s2, s3, s4, s5, s6) {
return keepDecimals ? s2 + '.' + s3.slice(0, keepDecimals) + s4 + '.' + s5.slice(0, keepDecimals) + s6 : s2 + s4 + s6;
}));
console.log('finished');
});
</script>