mapbox / mapbox/shp-write

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

Open
#77 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
321
Forks
195
PR merge metrics
No merged PRs in 30d

Description

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. (platform-browser.js:993)
```
### My current implementation
```typescript
import * as shp from 'shp-write';
```
```typescript
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();

}
```

```typescript
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:
```javascript
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting src/zip.js at line 33 and follow how src/download.js invokes it when imported from an Angular application. Reproduce the reported ReferenceError with the shown shp.download call, then verify that the browser download completes without the process error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.