Skip to content

Commit

Permalink
feat: add fromUrl, support [email protected]+ #11
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Jun 20, 2023
1 parent 3ac7f97 commit 8ce6a81
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 188 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,30 @@ import TIFFImageryProvider from 'tiff-imagery-provider';

const cesiumViewer = new Viewer("cesiumContainer");

const provider = new TIFFImageryProvider({
const provider = await TIFFImageryProvider.fromUrl({
url: 'https://oin-hotosm.s3.amazonaws.com/56f9b5a963ebf4bc00074e70/0/56f9c2d42b67227a79b4faec.tif',
});

cesiumViewer.imageryLayers.addImageryProvider(provider);
```

You can also use the New keyword to create a new TIFFimageryProvider, which was deprecated after [email protected]+

```ts
const provider = new TIFFImageryProvider({
url: YOUR_TIFF_URL,
});
provider.readyPromise.then(() => {
cesiumViewer.imageryLayers.addImageryProvider(provider);
})

```

If TIFF's projection is not EPSG:4326, you can pass the ``projFunc`` to handle the projection

```ts
import proj4 from 'proj4';

new TIFFImageryProvider({
url: YOUR_TIFF_URL,
TIFFImageryProvider.fromUrl(YOUR_TIFF_URL, {
projFunc: (code) => {
if (code === 32760) {
proj4.defs("EPSG:32760", "+proj=utm +zone=60 +south +datum=WGS84 +units=m +no_defs +type=crs");
Expand All @@ -64,8 +72,7 @@ Band calculation

```ts
// NDVI
new TIFFImageryProvider({
url: YOUR_TIFF_URL,
TIFFImageryProvider.fromUrl(YOUR_TIFF_URL, {
renderOptions: {
single: {
colorScale: 'rainbow',
Expand Down Expand Up @@ -93,7 +100,8 @@ class TIFFImageryProvider {
}

interface TIFFImageryProviderOptions {
url: string | File | Blob;
/** Deprecated */
url?: string | File | Blob;
requestOptions?: {
/** defaults to false */
forceXHR?: boolean;
Expand Down
25 changes: 17 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ import TIFFImageryProvider from 'tiff-imagery-provider';

const cesiumViewer = new Viewer("cesiumContainer");

const provider = new TIFFImageryProvider({
const provider = await TIFFImageryProvider.fromUrl({
url: 'https://oin-hotosm.s3.amazonaws.com/56f9b5a963ebf4bc00074e70/0/56f9c2d42b67227a79b4faec.tif',
});

cesiumViewer.imageryLayers.addImageryProvider(provider);

```

也可以使用New关键字新建一个TIFFimageryProvider,但是在[email protected]+之后被弃用

```ts
const provider = new TIFFImageryProvider({
url: YOUR_TIFF_URL,
});
provider.readyPromise.then(() => {
cesiumViewer.imageryLayers.addImageryProvider(provider);
})

```

如果TIFF的投影不是EPSG:4326,您可以传递``projFunc``来处理投影
如果 TIFF 的投影不是 EPSG:4326,你可以通过 ``projFunc`` 来处理投影

```ts
import proj4 from 'proj4';

new TIFFImageryProvider({
url: YOUR_TIFF_URL,
TIFFImageryProvider.fromUrl(YOUR_TIFF_URL, {
projFunc: (code) => {
if (code === 32760) {
proj4.defs("EPSG:32760", "+proj=utm +zone=60 +south +datum=WGS84 +units=m +no_defs +type=crs");
Expand All @@ -64,8 +73,7 @@ new TIFFImageryProvider({

```ts
// NDVI
new TIFFImageryProvider({
url: YOUR_TIFF_URL,
TIFFImageryProvider.fromUrl(YOUR_TIFF_URL, {
renderOptions: {
single: {
colorScale: 'rainbow',
Expand Down Expand Up @@ -93,7 +101,8 @@ class TIFFImageryProvider {
}

interface TIFFImageryProviderOptions {
url: string | File | Blob;
/** 已弃用 */
url?: string | File | Blob;
requestOptions?: {
/** 默认 false */
forceXHR?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/react-color": "^3.0.6",
"@types/react-dom": "18.0.9",
"ahooks": "^3.7.2",
"cesium": "^1.99.0",
"cesium": "^1.100.0",
"classnames": "^2.3.2",
"d3-scale-chromatic": "^3.0.0",
"eslint": "8.30.0",
Expand Down
4 changes: 1 addition & 3 deletions example/src/utils/CesiumMap/CesiumMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ export default class CesiumMap extends BaseMap {
});
break;
case 'cog':
imageryProvider = new TIFFImageryProvider({
url,
imageryProvider = await TIFFImageryProvider.fromUrl(url, {
minimumLevel,
maximumLevel,
renderOptions,
Expand All @@ -134,7 +133,6 @@ export default class CesiumMap extends BaseMap {
default:
break;
}
await imageryProvider.readyPromise
return imageryProvider;
}

Expand Down
Loading

1 comment on commit 8ce6a81

@vercel
Copy link

@vercel vercel bot commented on 8ce6a81 Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.