@jupytergis/base 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands.js +120 -7
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +4 -0
- package/lib/dialogs/ProcessingFormDialog.d.ts +30 -0
- package/lib/dialogs/ProcessingFormDialog.js +109 -0
- package/lib/dialogs/layerBrowserDialog.js +1 -1
- package/lib/dialogs/{formdialog.d.ts → layerCreationFormDialog.d.ts} +1 -1
- package/lib/dialogs/{formdialog.js → layerCreationFormDialog.js} +1 -1
- package/lib/dialogs/symbology/hooks/useGetBandInfo.js +22 -3
- package/lib/formbuilder/formselectors.d.ts +3 -3
- package/lib/formbuilder/formselectors.js +3 -11
- package/lib/formbuilder/index.d.ts +2 -4
- package/lib/formbuilder/index.js +2 -4
- package/lib/formbuilder/objectform/baseform.d.ts +1 -10
- package/lib/formbuilder/objectform/baseform.js +1 -1
- package/lib/formbuilder/objectform/fileselectorwidget.js +3 -3
- package/lib/formbuilder/objectform/{heatmapLayerForm.js → layer/heatmapLayerForm.js} +1 -1
- package/lib/formbuilder/objectform/layer/index.d.ts +5 -0
- package/lib/formbuilder/objectform/layer/index.js +5 -0
- package/lib/formbuilder/objectform/{layerform.d.ts → layer/layerform.d.ts} +6 -1
- package/lib/formbuilder/objectform/{layerform.js → layer/layerform.js} +1 -1
- package/lib/formbuilder/objectform/process/dissolveProcessForm.d.ts +20 -0
- package/lib/formbuilder/objectform/process/dissolveProcessForm.js +62 -0
- package/lib/formbuilder/objectform/process/index.d.ts +1 -0
- package/lib/formbuilder/objectform/process/index.js +1 -0
- package/lib/formbuilder/objectform/{geojsonsource.d.ts → source/geojsonsource.d.ts} +2 -2
- package/lib/formbuilder/objectform/{geojsonsource.js → source/geojsonsource.js} +1 -1
- package/lib/formbuilder/objectform/{geotiffsource.d.ts → source/geotiffsource.d.ts} +3 -3
- package/lib/formbuilder/objectform/{geotiffsource.js → source/geotiffsource.js} +16 -3
- package/lib/formbuilder/objectform/source/index.d.ts +5 -0
- package/lib/formbuilder/objectform/source/index.js +5 -0
- package/lib/formbuilder/objectform/{pathbasedsource.d.ts → source/pathbasedsource.d.ts} +3 -3
- package/lib/formbuilder/objectform/{pathbasedsource.js → source/pathbasedsource.js} +4 -4
- package/lib/formbuilder/objectform/source/sourceform.d.ts +24 -0
- package/lib/formbuilder/objectform/source/sourceform.js +13 -0
- package/lib/formbuilder/objectform/{tilesourceform.d.ts → source/tilesourceform.d.ts} +2 -2
- package/lib/formbuilder/objectform/{tilesourceform.js → source/tilesourceform.js} +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/keybindings.json +5 -0
- package/lib/mainview/mainView.js +52 -15
- package/lib/panelview/components/layers.js +3 -3
- package/lib/panelview/leftpanel.d.ts +1 -0
- package/lib/panelview/leftpanel.js +8 -1
- package/lib/panelview/rightpanel.js +2 -0
- package/lib/processing.d.ts +25 -0
- package/lib/processing.js +177 -0
- package/lib/tools.d.ts +16 -0
- package/lib/tools.js +93 -0
- package/package.json +2 -2
- /package/lib/formbuilder/objectform/{heatmapLayerForm.d.ts → layer/heatmapLayerForm.d.ts} +0 -0
- /package/lib/formbuilder/objectform/{hillshadeLayerForm.d.ts → layer/hillshadeLayerForm.d.ts} +0 -0
- /package/lib/formbuilder/objectform/{hillshadeLayerForm.js → layer/hillshadeLayerForm.js} +0 -0
- /package/lib/formbuilder/objectform/{vectorlayerform.d.ts → layer/vectorlayerform.d.ts} +0 -0
- /package/lib/formbuilder/objectform/{vectorlayerform.js → layer/vectorlayerform.js} +0 -0
- /package/lib/formbuilder/objectform/{webGlLayerForm.d.ts → layer/webGlLayerForm.d.ts} +0 -0
- /package/lib/formbuilder/objectform/{webGlLayerForm.js → layer/webGlLayerForm.js} +0 -0
package/lib/tools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VectorTile } from '@mapbox/vector-tile';
|
|
2
|
+
import { Contents } from '@jupyterlab/services';
|
|
2
3
|
import { IDict, IJGISLayerBrowserRegistry, IJGISOptions, IJGISSource, IJupyterGISModel } from '@jupytergis/schema';
|
|
3
4
|
export declare const debounce: (func: CallableFunction, timeout?: number) => CallableFunction;
|
|
4
5
|
export declare function throttle<T extends (...args: any[]) => void>(callback: T, delay?: number): T;
|
|
@@ -56,6 +57,19 @@ export declare const getFromIndexedDB: (key: string) => Promise<{
|
|
|
56
57
|
file: any;
|
|
57
58
|
metadata?: any | undefined;
|
|
58
59
|
} | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Load a GeoTIFF file from IndexedDB database cache or fetch it .
|
|
62
|
+
*
|
|
63
|
+
* @param sourceInfo object containing the URL of the GeoTIFF file.
|
|
64
|
+
* @returns A promise that resolves to the file as a Blob, or undefined .
|
|
65
|
+
*/
|
|
66
|
+
export declare const loadGeoTiff: (sourceInfo: {
|
|
67
|
+
url?: string | undefined;
|
|
68
|
+
}, file?: Contents.IModel | null) => Promise<{
|
|
69
|
+
file: any;
|
|
70
|
+
metadata: any;
|
|
71
|
+
sourceUrl: string;
|
|
72
|
+
} | null>;
|
|
59
73
|
/**
|
|
60
74
|
* Generalized file reader for different source types.
|
|
61
75
|
*
|
|
@@ -96,3 +110,5 @@ export declare const getMimeType: (filename: string) => string;
|
|
|
96
110
|
*/
|
|
97
111
|
export declare const stringToArrayBuffer: (content: string) => Promise<ArrayBuffer>;
|
|
98
112
|
export declare const getNumericFeatureAttributes: (featureProperties: Record<string, Set<any>>) => Record<string, Set<number>>;
|
|
113
|
+
export declare function downloadFile(content: BlobPart, fileName: string, mimeType: string): void;
|
|
114
|
+
export declare function getGeoJSONDataFromLayerSource(source: IJGISSource, model: IJupyterGISModel): Promise<string | null>;
|
package/lib/tools.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ServerConnection } from '@jupyterlab/services';
|
|
|
5
5
|
import { showErrorMessage } from '@jupyterlab/apputils';
|
|
6
6
|
import * as d3Color from 'd3-color';
|
|
7
7
|
import shp from 'shpjs';
|
|
8
|
+
import { getGdal } from './gdal';
|
|
8
9
|
import RASTER_LAYER_GALLERY from '../rasterlayer_gallery/raster_layer_gallery.json';
|
|
9
10
|
export const debounce = (func, timeout = 100) => {
|
|
10
11
|
let timeoutId;
|
|
@@ -321,6 +322,53 @@ const fetchWithProxies = async (url, parseResponse) => {
|
|
|
321
322
|
}
|
|
322
323
|
return null;
|
|
323
324
|
};
|
|
325
|
+
/**
|
|
326
|
+
* Load a GeoTIFF file from IndexedDB database cache or fetch it .
|
|
327
|
+
*
|
|
328
|
+
* @param sourceInfo object containing the URL of the GeoTIFF file.
|
|
329
|
+
* @returns A promise that resolves to the file as a Blob, or undefined .
|
|
330
|
+
*/
|
|
331
|
+
export const loadGeoTiff = async (sourceInfo, file) => {
|
|
332
|
+
if (!(sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url)) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const url = sourceInfo.url;
|
|
336
|
+
const mimeType = getMimeType(url);
|
|
337
|
+
if (!mimeType || !mimeType.startsWith('image/tiff')) {
|
|
338
|
+
throw new Error('Invalid file type. Expected GeoTIFF (image/tiff).');
|
|
339
|
+
}
|
|
340
|
+
const cachedData = await getFromIndexedDB(url);
|
|
341
|
+
if (cachedData) {
|
|
342
|
+
return {
|
|
343
|
+
file: cachedData.file,
|
|
344
|
+
metadata: cachedData.metadata,
|
|
345
|
+
sourceUrl: url
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
let fileBlob = null;
|
|
349
|
+
if (!file) {
|
|
350
|
+
fileBlob = await fetchWithProxies(url, async (response) => response.blob());
|
|
351
|
+
if (!fileBlob) {
|
|
352
|
+
showErrorMessage('Network error', `Failed to fetch ${url}`);
|
|
353
|
+
throw new Error(`Failed to fetch ${url}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
fileBlob = await base64ToBlob(file.content, mimeType);
|
|
358
|
+
}
|
|
359
|
+
const geotiff = new File([fileBlob], 'loaded.tif');
|
|
360
|
+
const Gdal = await getGdal();
|
|
361
|
+
const result = await Gdal.open(geotiff);
|
|
362
|
+
const tifDataset = result.datasets[0];
|
|
363
|
+
const metadata = await Gdal.gdalinfo(tifDataset, ['-stats']);
|
|
364
|
+
Gdal.close(tifDataset);
|
|
365
|
+
await saveToIndexedDB(url, fileBlob, metadata);
|
|
366
|
+
return {
|
|
367
|
+
file: fileBlob,
|
|
368
|
+
metadata,
|
|
369
|
+
sourceUrl: url
|
|
370
|
+
};
|
|
371
|
+
};
|
|
324
372
|
/**
|
|
325
373
|
* Generalized file reader for different source types.
|
|
326
374
|
*
|
|
@@ -426,6 +474,15 @@ export const loadFile = async (fileInfo) => {
|
|
|
426
474
|
throw new Error('Invalid file format for image content.');
|
|
427
475
|
}
|
|
428
476
|
}
|
|
477
|
+
case 'GeoTiffSource': {
|
|
478
|
+
if (typeof file.content === 'string') {
|
|
479
|
+
const tiff = loadGeoTiff({ url: filepath }, file);
|
|
480
|
+
return tiff;
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
throw new Error('Invalid file format for tiff content.');
|
|
484
|
+
}
|
|
485
|
+
}
|
|
429
486
|
default: {
|
|
430
487
|
throw new Error(`Unsupported source type: ${type}`);
|
|
431
488
|
}
|
|
@@ -643,3 +700,39 @@ export const getNumericFeatureAttributes = (featureProperties) => {
|
|
|
643
700
|
}
|
|
644
701
|
return filteredRecord;
|
|
645
702
|
};
|
|
703
|
+
export function downloadFile(content, fileName, mimeType) {
|
|
704
|
+
const blob = new Blob([content], { type: mimeType });
|
|
705
|
+
const url = URL.createObjectURL(blob);
|
|
706
|
+
const downloadLink = document.createElement('a');
|
|
707
|
+
downloadLink.href = url;
|
|
708
|
+
downloadLink.download = fileName;
|
|
709
|
+
document.body.appendChild(downloadLink);
|
|
710
|
+
downloadLink.click();
|
|
711
|
+
document.body.removeChild(downloadLink);
|
|
712
|
+
}
|
|
713
|
+
export async function getGeoJSONDataFromLayerSource(source, model) {
|
|
714
|
+
const vectorSourceTypes = ['GeoJSONSource', 'ShapefileSource'];
|
|
715
|
+
if (!vectorSourceTypes.includes(source.type)) {
|
|
716
|
+
console.error(`Invalid source type '${source.type}'. Expected one of: ${vectorSourceTypes.join(', ')}`);
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
719
|
+
if (!source.parameters) {
|
|
720
|
+
console.error('Source parameters are missing.');
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
if (source.parameters.path) {
|
|
724
|
+
const fileContent = await loadFile({
|
|
725
|
+
filepath: source.parameters.path,
|
|
726
|
+
type: source.type,
|
|
727
|
+
model
|
|
728
|
+
});
|
|
729
|
+
return typeof fileContent === 'object'
|
|
730
|
+
? JSON.stringify(fileContent)
|
|
731
|
+
: fileContent;
|
|
732
|
+
}
|
|
733
|
+
else if (source.parameters.data) {
|
|
734
|
+
return JSON.stringify(source.parameters.data);
|
|
735
|
+
}
|
|
736
|
+
console.error("Source is missing both 'path' and 'data' parameters.");
|
|
737
|
+
return null;
|
|
738
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupytergis/base",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "A JupyterLab extension for 3D modelling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@fortawesome/react-fontawesome": "latest",
|
|
44
44
|
"@jupyter/react-components": "^0.16.6",
|
|
45
45
|
"@jupyter/ydoc": "^2.0.0 || ^3.0.0",
|
|
46
|
-
"@jupytergis/schema": "^0.4.
|
|
46
|
+
"@jupytergis/schema": "^0.4.3",
|
|
47
47
|
"@jupyterlab/application": "^4.3.0",
|
|
48
48
|
"@jupyterlab/apputils": "^4.3.0",
|
|
49
49
|
"@jupyterlab/completer": "^4.3.0",
|
|
File without changes
|
/package/lib/formbuilder/objectform/{hillshadeLayerForm.d.ts → layer/hillshadeLayerForm.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|