Skip to content

Commit 2dbde22

Browse files
committed
Move band loading and change loading spinner
1 parent 65f6d4c commit 2dbde22

File tree

2 files changed

+38
-64
lines changed

2 files changed

+38
-64
lines changed

packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { faSpinner } from '@fortawesome/free-solid-svg-icons';
2-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
31
import { IDict } from '@jupytergis/schema';
42
import { Button } from '@jupyterlab/ui-components';
53
import { ReadonlyJSONObject } from '@lumino/coreutils';
@@ -12,6 +10,8 @@ import { IStopRow, ISymbologyDialogProps } from '../../symbologyDialog';
1210
import BandRow from './BandRow';
1311
import ColorRamp from './ColorRamp';
1412
import StopRow from './StopRow';
13+
import { getGdal } from '../../../gdal';
14+
import { Spinner } from '../../../mainview/spinner';
1515

1616
export interface IBandRow {
1717
band: number;
@@ -137,7 +137,7 @@ const SingleBandPseudoColor = ({
137137
: setSelectedFunction('exact');
138138
};
139139

140-
const getBandInfo = () => {
140+
const getBandInfo = async () => {
141141
const bandsArr: IBandRow[] = [];
142142
const source = context.model.getSource(layer?.parameters?.source);
143143
const sourceInfo = source?.parameters?.urls[0];
@@ -146,25 +146,41 @@ const SingleBandPseudoColor = ({
146146
return;
147147
}
148148

149-
if (stateDb && layerState && layerState.tifData) {
150-
const tifData = JSON.parse(layerState.tifData as string);
151-
152-
tifData['bands'].forEach((bandData: TifBandData) => {
153-
bandsArr.push({
154-
band: bandData.band,
155-
colorInterpretation: bandData.colorInterpretation,
156-
stats: {
157-
minimum: sourceInfo.min ?? bandData.minimum,
158-
maximum: sourceInfo.max ?? bandData.maximum,
159-
mean: bandData.mean,
160-
stdDev: bandData.stdDev
161-
},
162-
metadata: bandData.metadata,
163-
histogram: bandData.histogram
164-
});
149+
let tifData;
150+
151+
if (layerState && layerState.tifData) {
152+
tifData = JSON.parse(layerState.tifData as string);
153+
} else {
154+
const Gdal = await getGdal();
155+
156+
const fileData = await fetch(sourceInfo.url);
157+
const file = new File([await fileData.blob()], 'loaded.tif');
158+
159+
const result = await Gdal.open(file);
160+
const tifDataset = result.datasets[0];
161+
tifData = await Gdal.gdalinfo(tifDataset, ['-stats']);
162+
Gdal.close(tifDataset);
163+
164+
stateDb?.save(`jupytergis:${layerId}`, {
165+
tifData: JSON.stringify(tifData)
165166
});
166-
setBandRows(bandsArr);
167167
}
168+
169+
tifData['bands'].forEach((bandData: TifBandData) => {
170+
bandsArr.push({
171+
band: bandData.band,
172+
colorInterpretation: bandData.colorInterpretation,
173+
stats: {
174+
minimum: sourceInfo.min ?? bandData.minimum,
175+
maximum: sourceInfo.max ?? bandData.maximum,
176+
mean: bandData.mean,
177+
stdDev: bandData.stdDev
178+
},
179+
metadata: bandData.metadata,
180+
histogram: bandData.histogram
181+
});
182+
});
183+
setBandRows(bandsArr);
168184
};
169185

170186
const buildColorInfo = () => {
@@ -438,13 +454,7 @@ const SingleBandPseudoColor = ({
438454
<div className="jp-gis-layer-symbology-container">
439455
<div className="jp-gis-band-container">
440456
{bandRows.length === 0 ? (
441-
<div className="jp-gis-band-info-loading-container">
442-
<span>Fetching band info...</span>
443-
<FontAwesomeIcon
444-
icon={faSpinner}
445-
className="jp-gis-loading-spinner"
446-
/>
447-
</div>
457+
<Spinner loading={bandRows.length === 0} />
448458
) : (
449459
<BandRow
450460
// Band numbers are 1 indexed

packages/base/src/mainview/mainView.tsx

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from '@jupytergis/schema';
2626
import { IObservableMap, ObservableMap } from '@jupyterlab/observables';
2727
import { User } from '@jupyterlab/services';
28-
import { JSONValue, ReadonlyJSONObject, UUID } from '@lumino/coreutils';
28+
import { JSONValue, UUID } from '@lumino/coreutils';
2929
import { Collection, Map as OlMap, View } from 'ol';
3030
import { ScaleLine } from 'ol/control';
3131
import { GeoJSON, MVT } from 'ol/format';
@@ -54,8 +54,6 @@ import { PMTilesRasterSource, PMTilesVectorSource } from 'ol-pmtiles';
5454
import { Rule } from 'ol/style/flat';
5555
import * as React from 'react';
5656
import shp from 'shpjs';
57-
import { getGdal } from '../gdal';
58-
import { GlobalStateDbManager } from '../store';
5957
import { isLightTheme } from '../tools';
6058
import { MainViewModel } from './mainviewmodel';
6159
import { Spinner } from './spinner';
@@ -397,40 +395,6 @@ export class MainView extends React.Component<IProps, IStates> {
397395
case 'GeoTiffSource': {
398396
const sourceParameters = source.parameters as IGeoTiffSource;
399397

400-
const stateDb = GlobalStateDbManager.getInstance().getStateDb();
401-
402-
if (stateDb) {
403-
const layerState = (await stateDb.fetch(
404-
`jupytergis:${layerId}`
405-
)) as ReadonlyJSONObject;
406-
407-
if (
408-
sourceParameters.urls[0].url &&
409-
(!layerState || !layerState.tifData)
410-
) {
411-
// get GDAL info
412-
const Gdal = await getGdal();
413-
414-
const fileData = await fetch(sourceParameters.urls[0].url);
415-
const file = new File([await fileData.blob()], 'loaded.tif');
416-
417-
const result = await Gdal.open(file);
418-
const tifDataset = result.datasets[0];
419-
420-
const tifData = await Gdal.gdalinfo(tifDataset, [
421-
'-stats',
422-
'-hist'
423-
]);
424-
425-
Gdal.close(tifDataset);
426-
427-
stateDb.save(`jupytergis:${layerId}`, {
428-
...layerState,
429-
tifData: JSON.stringify(tifData)
430-
});
431-
}
432-
}
433-
434398
newSource = new GeoTIFFSource({
435399
sources: sourceParameters.urls,
436400
normalize: sourceParameters.normalize,

0 commit comments

Comments
 (0)