From 4acce45929e8643411b78f14b2062694c0020ff3 Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Mon, 12 Jun 2017 16:24:54 +0300 Subject: [PATCH 1/8] add node_modules to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3db12b15..2f6661c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ shpwrite.js +node_modules From f0d5e56866efbba0f990abff589c02e4163dd188 Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Mon, 12 Jun 2017 16:47:43 +0300 Subject: [PATCH 2/8] index page script file name fix --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index f856a0a1..46db3182 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ - + From d04188662bb64a2f0a19a4cde0ddbea222c14370 Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Mon, 12 Jun 2017 16:49:25 +0300 Subject: [PATCH 3/8] test download function --- indexTest.js | 30 ++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 indexTest.js diff --git a/indexTest.js b/indexTest.js new file mode 100644 index 00000000..f61bda2f --- /dev/null +++ b/indexTest.js @@ -0,0 +1,30 @@ +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 + ] + ] + ] + } + }] +}); diff --git a/package.json b/package.json index 8bf6a416..86b3cdc0 100644 --- a/package.json +++ b/package.json @@ -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", From 30f288143de3cff8cf61ac887abde879c1447558 Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Mon, 12 Jun 2017 17:05:55 +0300 Subject: [PATCH 4/8] update jszip, use filesaver --- indexTest.js | 8 ++++++++ package.json | 3 ++- src/download.js | 4 ++-- src/zip.js | 11 ++++------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/indexTest.js b/indexTest.js index f61bda2f..d8cf5f1e 100644 --- a/indexTest.js +++ b/indexTest.js @@ -27,4 +27,12 @@ require('./src/download')({ ] } }] +}, { + fileName: 'shapefiles', + folder: 'shapefiles', + types: { + point: 'points', + polygon: 'polygons', + line: 'lines' + } }); diff --git a/package.json b/package.json index 86b3cdc0..a9e94a17 100644 --- a/package.json +++ b/package.json @@ -36,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", diff --git a/src/download.js b/src/download.js index d198addf..ac45ede2 100644 --- a/src/download.js +++ b/src/download.js @@ -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.fileName + '.zip'); }); }; diff --git a/src/zip.js b/src/zip.js index b8e89d85..7c2c2de1 100644 --- a/src/zip.js +++ b/src/zip.js @@ -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' + }); }; From f7d39cce2abb1ad65554f6b1137d32c8b21d6bdd Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Tue, 13 Jun 2017 15:33:53 +0300 Subject: [PATCH 5/8] test data: line, point, readme fix --- README.md | 2 +- indexTest.js | 83 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b04c03e0..d23d805e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ var options = { types: { point: 'mypoints', polygon: 'mypolygons', - line: 'mylines' + polyline: 'mylines' } } // a GeoJSON bridge for features diff --git a/indexTest.js b/indexTest.js index d8cf5f1e..def9dd2e 100644 --- a/indexTest.js +++ b/indexTest.js @@ -1,38 +1,85 @@ require('./src/download')({ "type": "FeatureCollection", "features": [{ - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ [ - 24.936046600341797, - 60.175245406790246 + [ + 24.936046600341797, + 60.175245406790246 + ], + [ + 24.920597076416016, + 60.15577400466598 + ], + [ + 24.953556060791016, + 60.1570553725571 + ], + [ + 24.936046600341797, + 60.175245406790246 + ] ], [ - 24.920597076416016, - 60.15577400466598 - ], + [ + 24.93523120880127, + 60.169247224327165 + ], + [ + 24.945573806762695, + 60.15874243076889 + ], + [ + 24.928064346313477, + 60.15825127085746 + ], + [ + 24.93523120880127, + 60.169247224327165 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ [ - 24.953556060791016, - 60.1570553725571 + 24.920940399169922, + 60.17977000114811 ], [ - 24.936046600341797, - 60.175245406790246 + 24.953556060791016, + 60.17486121440947 ] ] - ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 24.925403594970703, + 60.171830205844614 + ] + } } - }] + ] }, { fileName: 'shapefiles', folder: 'shapefiles', types: { point: 'points', polygon: 'polygons', - line: 'lines' + polyline: 'lines' } }); From 35d0ce56439ed87ef50483b04b9375696abae27f Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Tue, 13 Jun 2017 16:21:10 +0300 Subject: [PATCH 6/8] readme update --- README.md | 4 ++-- src/download.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d23d805e..9a913340 100644 --- a/README.md +++ b/README.md @@ -22,15 +22,15 @@ Or in a browser 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', diff --git a/src/download.js b/src/download.js index ac45ede2..e30bd027 100644 --- a/src/download.js +++ b/src/download.js @@ -2,5 +2,5 @@ var zip = require('./zip'); var saveAs = require("file-saver").saveAs; module.exports = function(gj, options) { - zip(gj, options).then(function(blob) { saveAs(blob, options.fileName + '.zip'); }); + zip(gj, options).then(function(blob) { saveAs(blob, options.file + '.zip'); }); }; From 5f4a0f9a4c8b6ac9ef873f3137e40968b2697216 Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Tue, 13 Jun 2017 17:01:18 +0300 Subject: [PATCH 7/8] added test instructions --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9a913340..fb3dd36d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ 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) From 1171bbaa9f8ae7238f396e1217b5286f02e9ef9d Mon Sep 17 00:00:00 2001 From: Miro Kokkonen Date: Wed, 14 Jun 2017 10:15:53 +0300 Subject: [PATCH 8/8] test options param name fix --- indexTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indexTest.js b/indexTest.js index def9dd2e..aa3a9dcd 100644 --- a/indexTest.js +++ b/indexTest.js @@ -75,7 +75,7 @@ require('./src/download')({ } ] }, { - fileName: 'shapefiles', + file: 'shapefiles', folder: 'shapefiles', types: { point: 'points',