mapbox / geobuf

A compact binary encoding for geographic data.
ISC License
967 stars 84 forks source link

Geobuf/Pbf reading FeatureCollection as empty #82

Closed Spaxe closed 7 years ago

Spaxe commented 7 years ago

Minimal test case: https://gist.github.com/Spaxe/197ace389e4dc3ac286258e32ca0c0cc

The strange thing is that geobuf2json and json2geobuf converts it perfectly, so I don't really know what I'm missing.

To run the test, run node index.js. npm dependencies are geobuf, pbf.

Then index.html needs to be served by something like http-server -p 8001.

mourner commented 7 years ago

Can you reproduce this with a more minimal test case that doesn't involve a server?

Spaxe commented 7 years ago

I only get this problem while loading it from the client... so I'm not sure. Any suggestions on how I might be able to make the test smaller?

mourner commented 7 years ago

Don't load the JSON from the server, just hardcode it on the HTML page.

Spaxe commented 7 years ago

One HTML page test https://gist.github.com/Spaxe/f44a70e726b6eae13656f7ac7579de67

This version doesn't reproduce the bug I'm experiencing, unfortunately. Everything works.

I'm not sure where things got lost.

mourner commented 7 years ago

Looks like response.data is not a buffer by the time you get it from the server. Maybe something to do with MIME types (you need to request the geobuf as binary). Anyway, not a geobuf issue.

Spaxe commented 7 years ago

Thanks @mourner for the hint!

Adding { responseType: 'arraybuffer' } did indeed solve my problem. :)

Can we make the documentation a little clearer? I'll send in a PR shortly.