-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from MapColonies/update_tileset
feat: update tileset
- Loading branch information
Showing
8 changed files
with
242 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
packages/react-components/src/lib/cesium-map/layers/3d.tileset.update.ts
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
packages/react-components/src/lib/cesium-map/layers/3d.tileset.with.update.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */ | ||
/* | ||
https://sandcastle.cesium.com/index.html?#c=fVZtTxs5EP4re3xho0YOkOv1jgC6ElIuiAQKKaWQqnJ2nayL187Z3qCk4r/f+GXf8nKWot3YzzOeGT8z6wWWQRdLTRTFvB2cBl14y1JUznXGfMxbreBSYq798tV9gKOIKBVoESxFJgMqeICVIlqNuTfRFxzFZIozpj9a8Ei8EA5b7JPlVTK5jOgNvep/WfUPh7Sv+vzufdTt/9F/mT8+dK/+QgD6N758MSA6GJ3/HB712gN60H66fHq5Ht0l39K+vvnaWw27h/RmFP+8ue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mDL3a8jNeMhUyCA0OGorHR4nntIJ3r2jOxJtTim390y/V3yz7t1jHkdYafh6QE5HYjZj5DzTGjK5n18SehxPoOzhCmMuC82gyHWUELjCxDUBrM+ZsaMFbr/a7NTELiu72uj6KdRzkksq16E9tb3m3onSS0bOHOVvms6F1OYyEyLU0gQ6IthQrUkGQcIhKmVoJ62cdBLTRUDj0/He2v1vvBdEDG7lsDLNGLunKzLeOztpAb5GY6Bu+ArfLIhkeGkgyeHZtZtECJ204O8mSwvBJlhWLP4H | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
Cesium3DTileset, | ||
Cesium3DTile, | ||
Cartographic, | ||
Cartesian3, | ||
defined, | ||
sampleTerrainMostDetailed, | ||
Cesium3DTileContent, | ||
} from 'cesium'; | ||
import { CesiumViewer, useCesiumMap } from '../map'; | ||
|
||
export interface Cesium3DTilesetWithUpdateProps { | ||
url: string; | ||
withUpdate?: boolean; | ||
} | ||
|
||
export const Cesium3DTilesetWithUpdate: React.FC<Cesium3DTilesetWithUpdateProps> = ({ | ||
url, | ||
withUpdate, | ||
}) => { | ||
const mapViewer: CesiumViewer = useCesiumMap(); | ||
const scene = mapViewer.scene; | ||
const [cesium3DTileset] = useState<Cesium3DTileset>( | ||
new Cesium3DTileset({ | ||
url: url, | ||
}) | ||
); | ||
const [tileset] = useState<Cesium3DTileset>( | ||
scene.primitives.add(cesium3DTileset) | ||
); | ||
|
||
useEffect(() => { | ||
scene.globe.depthTestAgainstTerrain = true; | ||
void mapViewer.zoomTo(tileset); | ||
if (withUpdate === true) { | ||
updateTileset(tileset); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const updateContent = ( | ||
model: Cesium3DTileContent, | ||
boundingVolume: any | ||
): void => { | ||
const height = boundingVolume.minimumHeight | ||
? boundingVolume.minimumHeight | ||
: boundingVolume.center.z - boundingVolume.radius; | ||
// @ts-ignore | ||
const center = model._rtcCenter ?? boundingVolume.center; | ||
const normal = scene.globe.ellipsoid.geodeticSurfaceNormal( | ||
center, | ||
new Cartesian3() | ||
); | ||
const offset = Cartesian3.multiplyByScalar( | ||
normal, | ||
height, | ||
new Cartesian3() | ||
); | ||
const carto = Cartographic.fromCartesian(center); | ||
void new Promise((resolve, reject) => { | ||
// @ts-ignore | ||
if (scene.terrainProvider._ready !== true) { | ||
const result = { ...carto }; | ||
result.height = 0; | ||
resolve(result); | ||
} else { | ||
void sampleTerrainMostDetailed(scene.terrainProvider, [carto]).then( | ||
(results) => { | ||
const result = results[0]; | ||
if (!defined(result)) { | ||
resolve(carto); | ||
} | ||
resolve(result); | ||
} | ||
); | ||
} | ||
}).then((result) => { | ||
const resultCartesian = Cartographic.toCartesian(result as Cartographic); | ||
const position = Cartesian3.subtract( | ||
resultCartesian, | ||
offset, | ||
new Cartesian3() | ||
); | ||
// @ts-ignore | ||
model._rtcCenter = Cartesian3.clone(position, model._rtcCenter); | ||
}); | ||
}; | ||
|
||
const updateTile = (tile: Cesium3DTile): void => { | ||
if (tile.content !== undefined) { | ||
// @ts-ignore | ||
updateContent(tile.content, tile.boundingVolume.boundingVolume); | ||
} else { | ||
const listener = tileset.tileLoad.addEventListener((t) => { | ||
if (t === tile) { | ||
updateContent(t.content, t.boundingVolume.boundingVolume); | ||
listener(); | ||
} | ||
}); | ||
} | ||
tile.children.forEach((child) => updateTile(child)); | ||
}; | ||
|
||
const updateTileset = (tileset: Cesium3DTileset): void => { | ||
void tileset.readyPromise.then(() => { | ||
updateTile(tileset.root); | ||
}); | ||
}; | ||
|
||
return <></>; | ||
}; |
Oops, something went wrong.