Skip to content

Commit

Permalink
load from File/Blob on front-end
Browse files Browse the repository at this point in the history
Use geotiff package fromBlob() function to read File/Blob object
directly rather than copying data to ArrayBuffer object or using
createObjectURL() to create URL string for File/Blob object.
  • Loading branch information
jcphill committed Feb 5, 2022
1 parent f4a2351 commit 5749e28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class GeoRaster {
this._url = data;
this.rasterType = 'geotiff';
this.sourceType = 'url';
} else if (typeof Blob !== 'undefined' && data instanceof Blob) {
this._data = data;
this.rasterType = 'geotiff';
this.sourceType = 'Blob';
} else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
// this is node
if (debug) console.log('data is a buffer');
Expand Down
4 changes: 3 additions & 1 deletion src/parseData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {fromArrayBuffer, fromUrl} from 'geotiff';
import {fromArrayBuffer, fromUrl, fromBlob} from 'geotiff';
import {getPalette} from 'geotiff-palette';
import {unflatten} from './utils.js';

Expand Down Expand Up @@ -74,6 +74,8 @@ export default function parseData(data, debug) {
let initFunction = fromArrayBuffer;
if (data.sourceType === 'url') {
initFunction = fromUrl;
} else if (data.sourceType === 'Blob') {
initFunction = fromBlob;
}

if (debug) console.log('data.rasterType is geotiff');
Expand Down

0 comments on commit 5749e28

Please sign in to comment.