Converting Geojson to Shapefile in Javascript using shp-write

隐身守侯 提交于 2020-06-29 04:18:45

问题


I'm using Mapbox, and I'm trying to convert a Geojson to a zipped shapefile using shp-write. But when I follow the example given on the GitHub page, I'm getting a "ReferenceError: require is not defined" error on this line:

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

This is a jsfiddle in which you can test this. I'm relatively new to JavaScript, and haven't had to use the 'require()' function before.


回答1:


The jsfiddle you provided includes several external resources, among which a shpwrite delivered by unpkg that you may be missing.

Usually require doesn't exist in your browser. You would need to execute it with Node.js or use a module bundler like Webpack, but Unpkg takes care of it for you.

So adding:

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

on your page should make it work.



来源:https://stackoverflow.com/questions/48325664/converting-geojson-to-shapefile-in-javascript-using-shp-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!