11import { TIdentityGeoJSONFeature , Tools } from "../../../packages/maplugin-maplibre" ;
2- import shp from "shpjs" ;
2+ import shpReader from "shpjs" ;
3+ import shpWriter from '@mapbox/shp-write' ;
34
45function appendId ( fc : GeoJSON . FeatureCollection ) {
56 fc . features . forEach ( f => {
@@ -16,7 +17,7 @@ const FileProcesses: Array<{
1617 description : string ,
1718 contentType : string
1819 decode ?( file : File ) : Promise < Array < TIdentityGeoJSONFeature > > ,
19- encode ?( geojson : GeoJSON . FeatureCollection ) : string | Blob
20+ encode ?( geojson : GeoJSON . FeatureCollection ) : Promise < string | Blob >
2021} > = [ {
2122 extension : ".geojson" ,
2223 description : "geojson" ,
@@ -27,7 +28,7 @@ const FileProcesses: Array<{
2728 return appendId ( geojson ) . features as any ;
2829 } ,
2930
30- encode ( geojson ) {
31+ async encode ( geojson ) {
3132 return JSON . stringify ( geojson , null , 4 ) ;
3233 }
3334} , {
@@ -36,8 +37,14 @@ const FileProcesses: Array<{
3637 contentType : "application/x-zip-compressed" ,
3738 async decode ( file ) {
3839 const buffer = await file . arrayBuffer ( ) ;
39- const geojson = await shp ( buffer ) as GeoJSON . FeatureCollection ;
40+ const geojson = await shpReader ( buffer ) as GeoJSON . FeatureCollection ;
4041 return appendId ( geojson ) . features as any ;
42+ } ,
43+ async encode ( geojson ) {
44+ return ( await shpWriter . zip ( geojson , {
45+ 'outputType' : 'blob' ,
46+ 'compression' : 'DEFLATE'
47+ } ) ) as Blob ;
4148 }
4249} ]
4350
0 commit comments