diff --git a/packages/base/package.json b/packages/base/package.json index d8c12121..e96b2084 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -16,7 +16,7 @@ "name": "JupyterGIS contributors" }, "files": [ - "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}", + "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,data,wasm}", "style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}" ], "main": "lib/index.js", @@ -27,10 +27,11 @@ "url": "https://github.com/geojupyter/jupytergis.git" }, "scripts": { - "build": "jlpm run build:gallery && tsc -b", + "build": "jlpm run build:gallery && tsc -b && jlpm run cp:gdal", "build:gallery": "python rasterlayer_gallery_generator.py", + "cp:gdal": "cp ../../node_modules/gdal3.js/dist/package/gdal3WebAssembly.data lib && cp ../../node_modules/gdal3.js/dist/package/gdal3WebAssembly.wasm lib", "build:prod": "jlpm run clean && jlpm run build", - "build:dev": "tsc -b", + "build:dev": "tsc -b && jlpm run cp:gdal", "clean": "rimraf tsconfig.tsbuildinfo", "clean:lib": "rimraf lib tsconfig.tsbuildinfo", "clean:all": "jlpm run clean:lib", diff --git a/packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx b/packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx index 2d494607..43d4f8a4 100644 --- a/packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx +++ b/packages/base/src/dialogs/components/symbology/SingleBandPseudoColor.tsx @@ -1,14 +1,14 @@ import { faSpinner } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { IDict } from '@jupytergis/schema'; -import { PageConfig } from '@jupyterlab/coreutils'; import { Button } from '@jupyterlab/ui-components'; -import initGdalJs from 'gdal3.js'; +import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { ExpressionValue } from 'ol/expr/expression'; import React, { useEffect, useRef, useState } from 'react'; import { ISymbologyDialogProps } from '../../symbologyDialog'; import BandRow from './BandRow'; import StopRow from './StopRow'; +import { getGdal } from '../../../gdal'; export interface IStopRow { value: number; @@ -116,17 +116,13 @@ const SingleBandPseudoColor = ({ let tifData; - const baseUrl = PageConfig.getBaseUrl(); - - const tifDataState = (await state.fetch(layerId)) as string; - if (tifDataState) { - tifData = JSON.parse(tifDataState); + const layerState = await state.fetch(`jupytergis:${layerId}`); + if (layerState) { + tifData = JSON.parse( + (layerState as ReadonlyPartialJSONObject).tifData as string + ); } else { - //! This takes so long, maybe do when adding source instead - const Gdal = await initGdalJs({ - path: baseUrl + '/extensions/@jupytergis/jupytergis-core/static', - useWorker: false - }); + const Gdal = await getGdal(); const fileData = await fetch(sourceInfo.url); const file = new File([await fileData.blob()], 'loaded.tif'); diff --git a/packages/base/src/gdal.ts b/packages/base/src/gdal.ts new file mode 100644 index 00000000..90ae7b8f --- /dev/null +++ b/packages/base/src/gdal.ts @@ -0,0 +1,18 @@ +import initGdalJs from 'gdal3.js'; + +export async function getGdal() { + const dataurl = new URL('./gdal3WebAssembly.data', import.meta.url); + const wasmurl = new URL('./gdal3WebAssembly.wasm', import.meta.url); + + // TODO Pass gdal JS too and run gdal in a worker? + return await initGdalJs({ + paths: { + wasm: wasmurl.href, + data: dataurl.href + }, + useWorker: false + }); +} + +// Early load gdal +getGdal(); diff --git a/python/jupytergis_core/extension.webpack.config.js b/python/jupytergis_core/extension.webpack.config.js deleted file mode 100644 index 22b7af35..00000000 --- a/python/jupytergis_core/extension.webpack.config.js +++ /dev/null @@ -1,52 +0,0 @@ -const CopyPlugin = require('copy-webpack-plugin'); -const path = require('path'); - -const wasmPath = [ - __dirname, - '../', - '../', - 'node_modules', - 'gdal3.js', - 'dist', - 'package', - 'gdal3WebAssembly.wasm' -]; - -const dataPath = [ - __dirname, - '../', - '../', - 'node_modules', - 'gdal3.js', - 'dist', - 'package', - 'gdal3WebAssembly.data' - ]; - -const staticWasm = [ - __dirname, - 'jupytergis_core', - 'labextension', - 'static', - '[name].wasm' -]; - -const staticData = [ - __dirname, - 'jupytergis_core', - 'labextension', - 'static', - '[name].data' -]; - -module.exports = { - plugins: [ - new CopyPlugin({ - patterns: [ - { from: path.join(...wasmPath), to: path.join(...staticWasm) }, - { from: path.join(...dataPath), to: path.join(...staticData) }, - - ] - }) - ] -}; diff --git a/python/jupytergis_core/package.json b/python/jupytergis_core/package.json index f82d09fa..2f02bb6a 100644 --- a/python/jupytergis_core/package.json +++ b/python/jupytergis_core/package.json @@ -103,7 +103,6 @@ }, "extension": true, "outputDir": "jupytergis_core/labextension", - "webpackConfig": "./extension.webpack.config.js", "sharedPackages": { "@jupytergis/base": { "singleton": true,