Skip to content

Instantly share code, notes, and snippets.

@Spaxe
Created August 23, 2017 10:39
Show Gist options
  • Save Spaxe/197ace389e4dc3ac286258e32ca0c0cc to your computer and use it in GitHub Desktop.
Save Spaxe/197ace389e4dc3ac286258e32ca0c0cc to your computer and use it in GitHub Desktop.
Test case for geobuf to read empty
module.exports = {
"type": "FeatureCollection",
"features": [
{
"geometry": {
"coordinates": [
[
[
138.674968,
-34.811527
],
[
138.674792,
-34.811596
]
]
],
"type": "MultiLineString"
},
"properties": {
"id": 1,
},
"type": "Feature"
}
]
};
<!DOCTYPE html>
<html>
<body>
<script src="https://unpkg.com/geobuf@3.0.0/dist/geobuf.js"></script>
<script src="https://unpkg.com/pbf@3.0.5/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>
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);
@Spaxe
Copy link
Author

Spaxe commented Aug 23, 2017

console.log output:

{
  data: "↵�id"#↵�↵������������!����z�j���r���z�z�"
  headers: {content-type: "application/octet-stream"}
  request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
  status: 200
  statusText: "OK"
  __proto__: Object
41
r {buf: Uint8Array(0), pos: 0, type: 0, length: 0}
{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment