mapbox / geobuf

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

geobuf.decode() returns empty object in a browser #45

Closed mofoyoda closed 9 years ago

mofoyoda commented 9 years ago

I've made a simple gist that gets test pbf with XHR and then decodes it with geobuf.decode(). Unfortunately, it returns an empty Object. http://bl.ocks.org/mofoyoda/da963a75a3bb8c9437a6 I've tested decoding with node, and it works ok.

jfirebaugh commented 9 years ago

You probably need to add xmlhttp.responseType = 'arraybuffer'; and use xmlhttp.response rather than xmlhttp.responseText.

mourner commented 9 years ago

Yep, sounds like what John said.

mofoyoda commented 9 years ago

Oh, true, thanks a lot! I guess d3.xhr() doesn't work either, because it wraps responseText rather than response. FYI decoding runs quite fast: 1.5mln point features (87.5MB pbf) decoded in Chrome: decoding: 3612.231ms Firefox: decoding: 6859.14ms Safari: decoding: 49256.836ms (this one is strange)

mourner commented 9 years ago

Strange indeed. Can you profile and see what causes such a big difference?

mofoyoda commented 9 years ago

Profiled on Chrome and FF: everything went smooth. Added code and profiling info to the gist (https://gist.github.com/mofoyoda/da963a75a3bb8c9437a6). When I tried to profile on Safari, decoding script freezed like forever with 100% CPU load and swap file kept increasing over the edge. Tried several times with hard reset machine, unloaded all heavy services (postgres, tilemill, etc), but couldn't get it to finish. So I made a smaller test pbf (100k points instead of 1.5mln), and finished the profiling. It seems like pow in readDataField() function of decode.js file is nasty on Safari. readFeatureCollection() is the second most time-consuming function, but I guess that's normal. I've added my test data to the gist (caution - big data may take a while to clone). I'll investigate further on this and let you know if there'll be any more details.

mourner commented 9 years ago

That sound super-weird since pow should only be called once for a file... Thanks for looking into this!

aboutaaron commented 9 years ago

So, how do you effectively AJAX a .pbf file into the browser? Anyone have a guide on this? Thanks!

jfirebaugh commented 9 years ago

@aboutaaron xhr.responseType = 'arraybuffer'; -- see the mapbox-gl-js implementation for example.

aboutaaron commented 9 years ago

That did it! Thank you!

Sent from Outlook

On Tue, Oct 20, 2015 at 3:47 PM -0700, "John Firebaugh" notifications@github.com wrote:

@aboutaaron xhr.responseType = 'arraybuffer'; -- see the mapbox-gl-js implementation for example.

— Reply to this email directly or view it on GitHub.

stonetip commented 7 years ago

Under IIS, it was necessary to add the MIME type to Web.config:

`

</system.webServer>`