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

Zip.js function does not work on a angular implementation of the project #77

Open
yusefrich opened this issue Jan 3, 2020 · 2 comments

Comments

@yusefrich
Copy link

Hi guys, the zip function inside zip.js does not work in a angular implementation of this package, it returns the following error:

MeusMapasDetailComponent.html:497 ERROR ReferenceError: process is not defined
    at push../node_modules/shp-write/src/zip.js.module.exports (zip.js:33)
    at Object.push../node_modules/shp-write/src/download.js.module.exports [as download] (download.js:4)
    at MeusMapasDetailComponent.push../src/app/cliente-basico/modules/meus-mapas/detail/detail.component.ts.MeusMapasDetailComponent.exportshp (detail.component.ts:908)
    at Object.eval [as handleEvent] (MeusMapasDetailComponent.html:497)
    at handleEvent (core.js:23107)
    at callWithDebugContext (core.js:24177)
    at Object.debugHandleEvent [as handleEvent] (core.js:23904)
    at dispatchEvent (core.js:20556)
    at core.js:21003
    at HTMLButtonElement.<anonymous> (platform-browser.js:993)

My current implementation

import * as shp from 'shp-write';
  getSingleGeoJson(){
    var selectedPoligon = this.allDrawnItems.getLayer(this.ultimoPoligonoSelecionado.target._leaflet_id);

    var newPoli = L.polygon(selectedPoligon["_latlngs"][0],
      {
        color: '#1DB954',
        fillColor: '#1DB954',
        fillOpacity: 0.2
      }
    ).addTo(this.singlePolygonGroupLayer);

    return this.singlePolygonGroupLayer.toGeoJSON();

  }
  exportshp() {
     var options = {
       folder: 'myshapes',
       types: {
           point: 'mypoints',
           polygon: 'mypolygons',
           line: 'mylines'
       }
  }
      shp.download(this.getSingleGeoJson(), options); 
  }

What i found out

After messing arround i found that the error is in line 33 of the zip.js file inside src, where is has:

 if (!process.browser) {
      generateOptions.type = 'nodebuffer';
    }

since theres no process being set, because the method is being called by a angular project, the download does not happens.

@younghoh
Copy link

workaround
add pollyfills.ts

(window as any).process = {
    browser: true
};

or

download
https://unpkg.com/shp-write@latest/shpwrite.js

apply #48 (comment)

add angular.json

            "scripts": [
              "your_shpwrite_path",
            ]

in your component or service

declare var shpwrite: any;
...
...
shpwrite.download()

@wondie
Copy link

wondie commented Sep 22, 2020

Is there any fix for the browser version?

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