From 5749e280f023aae181aa0fd7c40c2fd236533106 Mon Sep 17 00:00:00 2001 From: Jim Phillips Date: Fri, 4 Feb 2022 20:19:52 -0600 Subject: [PATCH] load from File/Blob on front-end 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. --- src/index.js | 4 ++++ src/parseData.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c947960..ef94d2a 100644 --- a/src/index.js +++ b/src/index.js @@ -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'); diff --git a/src/parseData.js b/src/parseData.js index b139c12..2ef27ab 100644 --- a/src/parseData.js +++ b/src/parseData.js @@ -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'; @@ -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');