diff --git a/examples/cog-blob.html b/examples/cog-blob.html new file mode 100644 index 0000000000..f876e635ce --- /dev/null +++ b/examples/cog-blob.html @@ -0,0 +1,10 @@ +--- +layout: example.html +title: Cloud Optimized GeoTIFF (COG) from a Blob +shortdesc: Rendering a COG as a tiled layer from a Blob. +docs: > + Tiled data from a Cloud Optimized GeoTIFF (COG) can be rendered as a layer. In this + example, a single 3-band GeoTIFF is used to render RGB data from a Blob. +tags: "cog" +--- +
diff --git a/examples/cog-blob.js b/examples/cog-blob.js new file mode 100644 index 0000000000..0d16dd0273 --- /dev/null +++ b/examples/cog-blob.js @@ -0,0 +1,28 @@ +import GeoTIFF from '../src/ol/source/GeoTIFF.js'; +import Map from '../src/ol/Map.js'; +import TileLayer from '../src/ol/layer/WebGLTile.js'; + +fetch('data/example.tif') + .then((response) => response.blob()) + .then((blob) => { + const source = new GeoTIFF({ + sources: [ + { + blob: blob, + }, + ], + }); + + const map = new Map({ + target: 'map', + layers: [ + new TileLayer({ + source: source, + }), + ], + view: source.getView().then((viewConfig) => { + viewConfig.showFullExtent = true; + return viewConfig; + }), + }); + }); diff --git a/examples/data/example.tif b/examples/data/example.tif new file mode 100644 index 0000000000..6ee9b0e226 Binary files /dev/null and b/examples/data/example.tif differ diff --git a/examples/resources/common.js b/examples/resources/common.js index d7b4db7682..c210631f7c 100644 --- a/examples/resources/common.js +++ b/examples/resources/common.js @@ -9,7 +9,7 @@ function fetchResource(resource) { return new Promise(function (resolve, reject) { - const isImage = /\.(png|jpe?g|gif|tiff|svg|kmz)$/.test(resource); + const isImage = /\.(png|jpe?g|gif|tiff?|svg|kmz)$/.test(resource); if (isImage) { resolve ({ isBinary: true, diff --git a/src/ol/source/GeoTIFF.js b/src/ol/source/GeoTIFF.js index 2188a297b1..c252877be9 100644 --- a/src/ol/source/GeoTIFF.js +++ b/src/ol/source/GeoTIFF.js @@ -4,7 +4,12 @@ import DataTile from './DataTile.js'; import State from './State.js'; import TileGrid from '../tilegrid/TileGrid.js'; -import {Pool, fromUrl as tiffFromUrl, fromUrls as tiffFromUrls} from 'geotiff'; +import { + Pool, + fromBlob as tiffFromBlob, + fromUrl as tiffFromUrl, + fromUrls as tiffFromUrls, +} from 'geotiff'; import { Projection, get as getCachedProjection, @@ -17,8 +22,9 @@ import {fromCode as unitsFromCode} from '../proj/Units.js'; /** * @typedef {Object} SourceInfo - * @property {string} url URL for the source GeoTIFF. - * @property {Array