mapbox / geobuf

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

geobuf.decode error #129

Open tangzijun opened 1 year ago

tangzijun commented 1 year ago

When I execute geobuf.decode, an error is reported:

image

image

rmcf commented 9 months ago

To decode geobuf with a "manual" fetch I use this:

import geobuf from "geobuf";
import Pbf from "pbf";

function getCompressedData(geobufFileUrl) {
  fetch(geobufFileUrl)
    .then((response) => response.arrayBuffer())
    .then((buffer) => {
      const geoJsonData = geobuf.decode(new Pbf(buffer));
      createMap(geoJsonData);
    });
}
NathanPB commented 8 months ago

I am facing the same issue when the code is minified with webpack. I suppose that this is the reason:

image

Workaround:

My workaround at the moment is to use the Terser webpack plugin to ignore geobuf when minifying the code:

npm i -D terser-webpack-plugin

// webpack.config.js
module.exports = {
  optimization: {
    minimize: true,
      minimizer: [
        new TerserPlugin({ exclude: /node_modules\/geobuf/ })
      ],
  }
}