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

IE download fix #50

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
shpwrite.js
node_modules
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@ Or in a browser

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

## Testing

To test the download functionality run `npm run make-test` and open index.html in browser.
This should start an immediate download of test features defined in `indexTest.js`.

## Caveats

* Requires a capable fancy modern browser with [Typed Arrays](http://caniuse.com/#feat=typedarrays)
support
* Geometries: Point, LineString, Polygon, MultiLineString, MultiPolygon
* Tabular-style properties export with Shapefile's field name length limit
* Uses jsZip for ZIP files, but [compression is buggy](https://github.com/Stuk/jszip/issues/53) so it uses STORE instead of DEFLATE.

## Example

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

// (optional) set names for feature types and zipped folder
// (optional) set names for zip file, zipped folder and feature types
var options = {
file: 'myshapes'
folder: 'myshapes',
types: {
point: 'mypoints',
polygon: 'mypolygons',
line: 'mylines'
polyline: 'mylines'
}
}
// a GeoJSON bridge for features
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<script src='bundle.js'></script>
<script src='shpwrite.js'></script>
85 changes: 85 additions & 0 deletions indexTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require('./src/download')({
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.936046600341797,
60.175245406790246
],
[
24.920597076416016,
60.15577400466598
],
[
24.953556060791016,
60.1570553725571
],
[
24.936046600341797,
60.175245406790246
]
],
[
[
24.93523120880127,
60.169247224327165
],
[
24.945573806762695,
60.15874243076889
],
[
24.928064346313477,
60.15825127085746
],
[
24.93523120880127,
60.169247224327165
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
24.920940399169922,
60.17977000114811
],
[
24.953556060791016,
60.17486121440947
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
24.925403594970703,
60.171830205844614
]
}
}
]
}, {
file: 'shapefiles',
folder: 'shapefiles',
types: {
point: 'points',
polygon: 'polygons',
polyline: 'lines'
}
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"test": "mocha -R spec",
"prepublish": "npm run make",
"make": "browserify -s shpwrite ./ > shpwrite.js"
"make": "browserify -s shpwrite ./ > shpwrite.js",
"make-test": "browserify indexTest.js > shpwrite.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,7 +36,8 @@
},
"dependencies": {
"dbf": "0.1.4",
"jszip": "2.5.0"
"file-saver": "1.3.3",
"jszip": "3.1.3"
},
"devDependencies": {
"browserify": "^13.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/download.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var zip = require('./zip');
var saveAs = require("file-saver").saveAs;

module.exports = function(gj, options) {
var content = zip(gj, options);
location.href = 'data:application/zip;base64,' + content;
zip(gj, options).then(function(blob) { saveAs(blob, options.file + '.zip'); });
};
11 changes: 4 additions & 7 deletions src/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ module.exports = function(gj, options) {
}
});

var generateOptions = { compression:'STORE' };

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

return zip.generate(generateOptions);
return zip.generateAsync({
type: process.browser === undefined ? 'nodebuffer' : 'blob',
compression: 'DEFLATE'
});
};