Created
August 23, 2017 10:39
-
-
Save Spaxe/197ace389e4dc3ac286258e32ca0c0cc to your computer and use it in GitHub Desktop.
Test case for geobuf to read empty
This file contains hidden or 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
module.exports = { | |
"type": "FeatureCollection", | |
"features": [ | |
{ | |
"geometry": { | |
"coordinates": [ | |
[ | |
[ | |
138.674968, | |
-34.811527 | |
], | |
[ | |
138.674792, | |
-34.811596 | |
] | |
] | |
], | |
"type": "MultiLineString" | |
}, | |
"properties": { | |
"id": 1, | |
}, | |
"type": "Feature" | |
} | |
] | |
}; |
This file contains hidden or 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> | |
<body> | |
<script src="https://unpkg.com/[email protected]/dist/geobuf.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/pbf.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<script> | |
axios.get('http://localhost:8000').then( response => { | |
console.log(response); | |
console.log(response.data.length); // <- not 0 | |
const buf = new Pbf(response.data); | |
console.log(buf); // <- empty? | |
const geojson = geobuf.decode(buf); | |
console.log(geojson); // <- empty? | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
const http = require('http'); | |
const geobuf = require('geobuf'); | |
const Pbf = require('pbf'); | |
const geojson = require('./data'); | |
http.createServer(function (req, res) { | |
const buf = geobuf.encode(geojson, new Pbf()); | |
res.writeHead(200, { | |
'Content-Type': 'application/octet-stream', | |
'Access-Control-Allow-Origin': '*', | |
}); | |
res.end(Buffer.from(buf)); | |
}).listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
console.log
output: