Skip to content

Commit

Permalink
fix(COG): Fix COG example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin ETOURNEAU authored and Desplandis committed May 30, 2024
1 parent 1de7124 commit aaa9691
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/js/plugins/COGParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ const COGParser = (function _() {
*/
parse: async function _(data, options) {
const source = options.in;
const tileExtent = data.extent.as(source.crs);
const tileExtent = options.extent.as(source.crs);

const level = selectLevel(source, tileExtent, source.tileWidth, source.tileHeight);
const viewport = makeWindowFromExtent(source, tileExtent, level.resolution);
const rgbBuffer = await readRGB(source, level, viewport);
const texture = createTexture(source, rgbBuffer);
texture.flipY = true;
texture.extent = data.extent;
texture.extent = options.extent;
texture.needsUpdate = true;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearFilter;
Expand Down
16 changes: 13 additions & 3 deletions examples/source_file_cog.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
itowns.proj4.defs('EPSG:2154', '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');

var viewerDiv = document.getElementById('viewerDiv');
var view;

function readCOGURL() {
var url = document.getElementById('cog_url').value || new URLSearchParams(window.location.search).get('geotiff');
Expand All @@ -47,7 +48,7 @@
}

function loadRGBSample() {
document.getElementById('cog_url').value = 'https://cdn.jsdelivr.net/gh/bloc-in-bloc/iTowns2-sample-data@add-cog-sample/cog/orvault.tif';
document.getElementById('cog_url').value = 'https://cdn.jsdelivr.net/gh/iTowns/iTowns2-sample-data/cog/nantes/nantes.tif';
readCOGURL();
}

Expand All @@ -56,6 +57,12 @@
readCOGURL();
}

function removeAllChildNodes(parent) {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}

function loadCOG(url) {
// create a source from a Cloud Optimized GeoTiff
var cogSource = new COGSource({
Expand All @@ -66,14 +73,17 @@
});

cogSource.whenReady.then(() => {
var view = new itowns.PlanarView(viewerDiv, cogSource.extent, {
if (view !== undefined) {
view.dispose(true);
removeAllChildNodes(viewerDiv);
}
view = new itowns.PlanarView(viewerDiv, cogSource.extent, {
// Default maxSubdivisionLevel is 5, so with huge geotiff it's not enough to see details when zoomed
maxSubdivisionLevel: 10,
disableSkirt: true,
placement: { tilt: 90 }
});
setupLoadingScreen(viewerDiv, view);
new itowns.PlanarControls(view, {});
var cogLayer = new itowns.ColorLayer('cog', {
source: cogSource,
});
Expand Down

0 comments on commit aaa9691

Please sign in to comment.