Created
August 9, 2013 03:37
-
-
Save tmcw/6190994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' /> | |
<style> | |
body { margin:0; padding:0; } | |
#map { width:100%; height:300px; } | |
</style> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /> | |
<![endif]--> | |
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script> | |
</head> | |
<body> | |
<div id='map'></div> | |
<h1>input</h1> | |
<pre id='input'></pre> | |
<h1>output</h1> | |
<pre id='output'></pre> | |
<script type='text/javascript'> | |
var map = L.map('map'); | |
var geojson = { | |
"type": "FeatureCollection", | |
"features": [ | |
{ | |
"type": "Feature", | |
"geometry": { | |
"type": "GeometryCollection", | |
"geometries": [ | |
{ | |
"type": "LineString", | |
"coordinates": [ | |
[ | |
-122.4425587930444, | |
37.80666418607323, | |
0 | |
], | |
[ | |
-122.4428379594768, | |
37.80663578323093, | |
0 | |
] | |
] | |
}, | |
{ | |
"type": "LineString", | |
"coordinates": [ | |
[ | |
-122.4425509770566, | |
37.80662588061205, | |
0 | |
], | |
[ | |
-122.4428340530617, | |
37.8065999493009, | |
0 | |
] | |
] | |
} | |
] | |
}, | |
"properties": { | |
"name": "SF Marina Harbor Master" | |
} | |
} | |
] | |
}; | |
var geojsonLayer = L.geoJson(geojson).addTo(map); | |
map.fitBounds(geojsonLayer.getBounds()); | |
var fc = { type: 'FeatureCollection', features: [] }; | |
geojsonLayer.eachLayer(function(l) { | |
l.eachLayer(function(j) { | |
fc.features.push(j.toGeoJSON()); | |
}); | |
}); | |
document.getElementById('input').innerHTML = JSON.stringify(geojson, null, 2); | |
document.getElementById('output').innerHTML = JSON.stringify(fc, null, 2); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment