使用 shp-write 在 Javascript 中将 Geojson 转换为 Shapefile

Converting Geojson to Shapefile in Javascript using shp-write

我正在使用 Mapbox,我正在尝试使用 GitHub 页面上给出的 shp-write. But when I follow the example 将 Geojson 转换为压缩的 shapefile,我得到一个 "ReferenceError: require is not defined"此行的错误:

var shpwrite = require('shp-write');

这是一个 jsfiddle,您可以在其中进行测试。我对 JavaScript 比较陌生,之前没用过 'require()' 函数。

您提供的 jsfiddle 包含多个外部资源,其中一个 shpwrite delivered by unpkg 您可能缺少。

通常 require doesn't exist in your browser. You would need to execute it with Node.js or use a module bundler like Webpack,但 Unpkg 会为您处理。

所以添加:

<script src="https://unpkg.com/shp-write@latest/shpwrite.js"></script>

在您的页面上应该可以正常工作。