diff --git a/web/client/components/import/dragZone/enhancers/__tests__/testData.js b/web/client/components/import/dragZone/enhancers/__tests__/testData.js index a88a370b7a..918b9090b3 100644 --- a/web/client/components/import/dragZone/enhancers/__tests__/testData.js +++ b/web/client/components/import/dragZone/enhancers/__tests__/testData.js @@ -16,7 +16,8 @@ export const getFile = (url, fileName = "file") => responseType: 'arraybuffer' })) .map( res => { - return new File([new Blob([res.data], {type: res.headers['response-type']})], fileName); + const contentType = res.headers['content-type'] === 'null' ? undefined : res.headers['content-type']; + return new File([res.data], fileName, {type: contentType}); }); // PDF_FILE: new File(b64toBlob('UEsDBAoAAAAAACGPaktDvrfoAQAAAAEAAAAKAAAAc2FtcGxlLnR4dGFQSwECPwAKAAAAAAAhj2pLQ7636AEAAAABAAAACgAkAAAAAAAAACAAAAAAAAAAc2FtcGxlLnR4dAoAIAAAAAAAAQAYAGILh+1EWtMBy3f86URa0wHLd/zpRFrTAVBLBQYAAAAAAQABAFwAAAApAAAAAAA=', 'application/pdf'), "file.pdf"), diff --git a/web/client/components/import/dragZone/enhancers/processFiles.jsx b/web/client/components/import/dragZone/enhancers/processFiles.jsx index 65a62202cf..9afc0b2fae 100644 --- a/web/client/components/import/dragZone/enhancers/processFiles.jsx +++ b/web/client/components/import/dragZone/enhancers/processFiles.jsx @@ -24,7 +24,8 @@ import { readWMC, readZip, recognizeExt, - shpToGeoJSON + shpToGeoJSON, + readGeoJson } from '../../../../utils/FileUtils'; import { geoJSONToLayer } from '../../../../utils/LayersUtils'; @@ -48,7 +49,8 @@ const checkFileType = (file) => { || type === 'application/vnd.google-earth.kmz' || type === 'application/gpx+xml' || type === 'application/json' - || type === 'application/vnd.wmc') { + || type === 'application/vnd.wmc' + || type === 'application/geo+json') { resolve(file); } else { // Drag and drop of compressed folders doesn't correctly send the zip mime type (windows, also conflicts with installations of WinRar) @@ -114,6 +116,18 @@ const readFile = (onWarnings) => (file) => { return [{...f, "fileName": file.name}]; }); } + if (type === 'application/geo+json') { + return readGeoJson(file).then(f => { + const projection = get(f, 'geoJSON.map.projection'); + if (projection) { + if (supportedProjections.includes(projection)) { + return [{...f.geoJSON, "fileName": file.name}]; + } + throw new Error("PROJECTION_NOT_SUPPORTED"); + } + return [{...f.geoJSON, "fileName": file.name}]; + }); + } if (type === 'application/vnd.wmc') { return readWMC(file).then((config) => { return [{...config, "fileName": file.name}];