Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a very basic, complete example as documentation? #122

Open
EricDuminil opened this issue Apr 22, 2024 · 2 comments
Open

Include a very basic, complete example as documentation? #122

EricDuminil opened this issue Apr 22, 2024 · 2 comments

Comments

@EricDuminil
Copy link

EricDuminil commented Apr 22, 2024

First: thanks for your excellent work!

I'm a HTML+JS noobie, and it would have helped me a lot to see a complete, minimal example, with just HTML+JS:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Shapefile Export</title>
  <!-- Import FileSaver.js -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
  <!-- Import shp-write.js -->
  <script src="https://unpkg.com/@mapbox/shp-write@latest/shpwrite.js"></script>
</head>

<body>
  <button onclick="exportShapefile()">Export Shapefile</button>

  <script>
    function exportShapefile() {
      // Sample data
      var data = {
        type: 'FeatureCollection',
        features: [{
          type: 'Feature',
          properties: {
            name: 'Some polygon'
          },
          geometry: {
            type: 'Polygon',
            coordinates: [[
              [-64.8, 32.3], [-65.5, 18.3], [-80.3, 25.2], [-64.8, 32.3]]]
          }
        }]
      };

      // Save the zip file
      shpwrite.zip(data, { outputType: "blob" }).then(function (zipBlob) {
        saveAs(zipBlob, "my_shapefile.zip");
      });
    }
  </script>
</body>
</html>

It can be run here: https://jsfiddle.net/pd14t8ew/2/

It's really not very different from the existing doc, but it took me a while to find the correct inputs.
If you're interested, I could write a corresponding PR for documentation.

@charlieforward9
Copy link
Contributor

@EricDuminil Hey there! I encourage you create a PR for this repo by editing the readme. I contributed about a year ago to add typescript support and it was a cool experience to make an open source contribution for the first time.

If you want to add a few more options, that would be awesome for making the demo feel more complete.

@ghazzaale
Copy link

Hi there! do you know why it is working well for Polygons and points but not for lineStrings? I have this issue and then came by your code and noticed that the same would happen here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants