marook / osm-read

an openstreetmap XML and PBF data parser for node.js and the browser
GNU Lesser General Public License v3.0
107 stars 25 forks source link

Example pbf.html is Broken #29

Closed aemkei closed 9 years ago

aemkei commented 10 years ago

It is not possible to run the example/pbf.html.

I followed the instructions and run npm run browserify to create the file osm-read-pbf.js. When opening the example HTML it will throw the following errors:

Uncaught Error: Cannot find module 'bytebuffer' osm-read-pbf.js:1
Uncaught ReferenceError: pbfParser is not defined pbf.html:18
GET http://localhost:8080/inflate.min.js.map 404 (Not Found)
aemkei commented 10 years ago

Looks like browserify can't include bytebuffer correctly. I see this in the final osm-read-pbf.js:

{"bytebuffer":"bytebuffer","fs":undefined,"path":undefined}]}
nrenner commented 10 years ago

Seems like my hack to include the minified files is no longer working with the latest browserify:

browserify ./lib/pbfParser.js --bare -x bytebuffer -x long -r ./node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js:bytebuffer -r ./node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/dist/Long.min.js:long -s=pbfParser -o osm-read-pbf.js

As a workaround you can use:

browserify ./lib/pbfParser.js --bare -s=pbfParser -o osm-read-pbf.js

Need to see what I can do about this.

aemkei commented 10 years ago

Thanks! The workaround works for now. BTW: This is an amazing project and I'm looking forward to see OSM data in Node and the browser…

nrenner commented 9 years ago

The reason for wanting to require the already minified files is that ByteBuffer.min.js and Long.min.js are built with Google Closure Compiler in advanced mode, which supposedly might also improve runtime performance e.g. by function inlining.

But now I have done some quick manual testing and could not observe a significant performance improvement. I also wanted to look into compiling across all modules instead of using the individual builds, but don't know if that would be worth the effort. So for now I'm simply using minifyify on the sources.

Here is the build workaround used for testing:

  browserify -r ./node_modules/protobufjs/node_modules/bytebuffer/dist/ByteBufferAB.min.js:bytebuffer -x long -o bytebuffer.js
  browserify -r ./node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/dist/Long.min.js:long -o long.js
  browserify ./lib/pbfParser.js --bare -x bytebuffer -x long -s=pbfParser -o osm-read-pbf.js

  <script src="long.js"></script>
  <script src="bytebuffer.js"></script>
  <script src="osm-read-pbf.js"></script>
wolfgangvonludwigsburg commented 9 years ago

I did follow your workaround so far, but I end up with:

Uncaught TypeError: Cannot read property 'decode' of undefined (in osm-read-pbf.js):

function readBlobHeaderContent(fd, position, size, callback) { => return reader.readPBFElement(fd, position, size, fileFormat.BlobHeader.decode, callback); }

Looks like:

var fileFormat = require('./proto/fileformat.js');

does'nt instantiate correctly ... (i.e. missing Member '.BlobHeader')

Would you please upload (e.g. to './dist') any working files from your functional workaround: long.js, bytebuffer.js, osm-read-pbf.js so I can check against my configuration ...

PLEASE ... ;-) Thank you.

nrenner commented 9 years ago

Sorry about this. Moving forward, I now have merged the pending PR #31. This fixes the build, so npm run browserify now works again.

I also have committed the osm-read-pbf.js to the repo. It contains all that is needed, so you should be ready to go.