Skip to content

Commit

Permalink
Upgrade to Cesium 1.108.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Aug 6, 2023
1 parent 041dc5f commit 58fa01d
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 258 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"babel-plugin-lodash": "^3.3.4",
"bottleneck": "^2.19.5",
"catalog-converter": "^0.0.9",
"cesium": "1.106.0",
"cesium": "1.108.0",
"class-list": "^0.1.1",
"classnames": "^2.3.1",
"clipboard": "^2.0.8",
Expand Down
54 changes: 24 additions & 30 deletions src/Map/Leaflet/ImageryProviderLeafletGridLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,16 @@ export default class ImageryProviderLeafletGridLayer extends L.GridLayer {
canvas.width = size.x;
canvas.height = size.y;

this.imageryProvider.readyPromise
.then(() => {
const n = this.imageryProvider.tilingScheme.getNumberOfXTilesAtLevel(
tilePoint.z
);
return this.imageryProvider.requestImageForCanvas(
CesiumMath.mod(tilePoint.x, n),
tilePoint.y,
tilePoint.z,
canvas
);
})
const n = this.imageryProvider.tilingScheme.getNumberOfXTilesAtLevel(
tilePoint.z
);
this.imageryProvider
.requestImageForCanvas(
CesiumMath.mod(tilePoint.x, n),
tilePoint.y,
tilePoint.z,
canvas
)
.then(function (canvas) {
done(undefined, canvas);
});
Expand All @@ -152,15 +150,13 @@ export default class ImageryProviderLeafletGridLayer extends L.GridLayer {
);
const level = Math.round(map.getZoom());

return this.imageryProvider.readyPromise.then(() => {
const tilingScheme = this.imageryProvider.tilingScheme;
const coords = tilingScheme.positionToTileXY(ll, level);
return {
x: coords.x,
y: coords.y,
level: level
};
});
const tilingScheme = this.imageryProvider.tilingScheme;
const coords = tilingScheme.positionToTileXY(ll, level);
return {
x: coords.x,
y: coords.y,
level: level
};
}

pickFeatures(
Expand All @@ -170,14 +166,12 @@ export default class ImageryProviderLeafletGridLayer extends L.GridLayer {
longitudeRadians: number,
latitudeRadians: number
) {
return this.imageryProvider.readyPromise.then(() => {
return this.imageryProvider.pickFeatures(
x,
y,
level,
longitudeRadians,
latitudeRadians
);
});
return this.imageryProvider.pickFeatures(
x,
y,
level,
longitudeRadians,
latitudeRadians
);
}
}
31 changes: 8 additions & 23 deletions src/Map/Leaflet/ImageryProviderLeafletTileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,6 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
}

_update() {
if (!this.imageryProvider.ready) {
if (!this._delayedUpdate) {
this._delayedUpdate = <any>setTimeout(() => {
this._delayedUpdate = undefined;
this._update();
}, this._leafletUpdateInterval);
}
return;
}

if (!this.initialized) {
this.initialized = true;

Expand Down Expand Up @@ -396,7 +386,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
this._previousCredits = nextCredits;
}

getFeaturePickingCoords(
async getFeaturePickingCoords(
map: L.Map,
longitudeRadians: number,
latitudeRadians: number
Expand All @@ -408,17 +398,13 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
);
const level = Math.round(map.getZoom());

return pollToPromise(() => {
return this.imageryProvider.ready;
}).then(() => {
const tilingScheme = this.imageryProvider.tilingScheme;
const coords = tilingScheme.positionToTileXY(ll, level);
return {
x: coords.x,
y: coords.y,
level: level
};
});
const tilingScheme = this.imageryProvider.tilingScheme;
const coords = tilingScheme.positionToTileXY(ll, level);
return {
x: coords.x,
y: coords.y,
level: level
};
}

async pickFeatures(
Expand All @@ -428,7 +414,6 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
longitudeRadians: number,
latitudeRadians: number
): Promise<ImageryLayerFeatureInfo[] | undefined> {
await pollToPromise(() => this.imageryProvider.ready);
try {
return await this.imageryProvider.pickFeatures(
x,
Expand Down
80 changes: 50 additions & 30 deletions src/ModelMixins/Cesium3dTilesMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ function Cesium3dTilesMixin<T extends AbstractConstructor<BaseType>>(Base: T) {

override async _protected_forceLoadMapItems() {
try {
this._private_loadTileset();
await this._private_loadTileset();
if (this._protected_tileset) {
const _protected_tileset = await this._protected_tileset.readyPromise;
const tileset = this._protected_tileset;
if (
_protected_tileset.extras !== undefined &&
_protected_tileset.extras.style !== undefined
tileset.extras !== undefined &&
tileset.extras.style !== undefined
) {
runInAction(() => {
this.strata.set(
CommonStrata.defaults,
createStratumInstance(Cesium3DTilesCatalogItemTraits, {
style: _protected_tileset.extras.style
style: tileset.extras.style
})
);
});
Expand Down Expand Up @@ -180,35 +180,55 @@ function Cesium3dTilesMixin<T extends AbstractConstructor<BaseType>>(Base: T) {
return;
}

const _protected_tileset = new ObservableCesium3DTileset({
...this.optionsObj,
url: resource
});

_protected_tileset._catalogItem = this;
runLater(
action(() => {
this.isTilesetReady = _protected_tileset.ready;
})
);
if (!_protected_tileset.destroyed) {
this._protected_tileset = _protected_tileset;
}

// Save the original root tile transform and set its value to an identity
// matrix This lets us control the whole model transformation using just
// tileset.modelMatrix We later derive a tilset.modelMatrix by combining
// the root transform and transformation traits in mapItems.
_protected_tileset.readyPromise.then(
action(() => {
this.isTilesetReady = _protected_tileset.ready;
if (_protected_tileset.root !== undefined) {
this._private_originalRootTransform =
_protected_tileset.root.transform.clone();
_protected_tileset.root.transform = Matrix4.IDENTITY.clone();
}
})
);
return Promise.resolve(resource).then((resource) => {
if (resource === undefined) return;

const tilesetPromise = Cesium3DTileset.fromUrl(resource, {
...this.optionsObj
});
return tilesetPromise.then((tileset) => {
// Hackily turn the Cesium3DTileset into an ObservableCesium3DTileset
const anyTileset: any = tileset;
anyTileset._catalogItem = this;
anyTileset.destroyed = tileset.isDestroyed();
const superDestroy = anyTileset.destroy;
anyTileset.destroy = function () {
superDestroy.call(this);
// TODO: we are running later to prevent this
// modification from happening in some computed up the call chain.
// Figure out why that is happening and fix it.
runLater(() => {
runInAction(() => {
this.destroyed = true;
});
});
};

makeObservable(anyTileset, {
destroyed: observable
});

const observableTileset: ObservableCesium3DTileset = anyTileset;

action(() => {
observableTileset._catalogItem = this;
if (!observableTileset.destroyed) {
runInAction(() => {
this._protected_tileset = observableTileset;
});
if (observableTileset.root !== undefined) {
this._private_originalRootTransform =
observableTileset.root.transform.clone();
observableTileset.root.transform = Matrix4.IDENTITY.clone();
}
}
});
});
});
}

/**
Expand Down
46 changes: 40 additions & 6 deletions src/ModelMixins/MappableMixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18next from "i18next";
import { computed, makeObservable, runInAction } from "mobx";
import { computed, makeObservable, observable, runInAction } from "mobx";
import { Rectangle } from "cesium";
import { TerrainProvider } from "cesium";
import { DataSource } from "cesium";
Expand All @@ -26,11 +26,45 @@ export type MapItem =
| AbstractPrimitive
| TerrainProvider;

export interface ImageryParts {
alpha: number;
clippingRectangle: Rectangle | undefined;
imageryProvider: ImageryProvider;
show: boolean;
export class ImageryParts {
@observable imageryProvider: ImageryProvider | undefined = undefined;
alpha: number = 0.8;
clippingRectangle: Rectangle | undefined = undefined;
show: boolean = true;

static fromAsync(options: {
imageryProviderPromise: Promise<ImageryProvider | undefined>,
alpha?: number,
clippingRectangle?: Rectangle,
show?: boolean
}): ImageryParts {
const result = new ImageryParts({
imageryProvider: undefined,
alpha: options.alpha,
clippingRectangle: options.clippingRectangle,
show: options.show
});
options.imageryProviderPromise.then((imageryProvider) => {
if (imageryProvider) {
runInAction(() => {
result.imageryProvider = imageryProvider;
});
}
});
return result;
}

constructor(options: {
imageryProvider: ImageryProvider | undefined,
alpha?: number,
clippingRectangle?: Rectangle,
show?: boolean
}) {
this.imageryProvider = options.imageryProvider;
this.alpha = options.alpha ?? 0.8;
this.clippingRectangle = options.clippingRectangle;
this.show = options.show ?? true;
}
}

// This discriminator only discriminates between ImageryParts and DataSource
Expand Down
Loading

0 comments on commit 58fa01d

Please sign in to comment.