Skip to content

Commit

Permalink
fix: use depthTest when render height
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Jan 12, 2024
1 parent 7b1f0b5 commit 6215682
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cesium-extends 提供了以下功能:
- 热力图 `@cesium-extends/heat`
- ...

详细信息及 demo,请参阅 [API 文档](https://cesium-extends.pages.dev/)
详细信息及 demo,请参阅 [API 文档](https://extends.opendde.com/)

## 示例

Expand Down
3 changes: 2 additions & 1 deletion doc/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default defineConfig({
name: 'cesium-extends',
socialLinks: {
github: 'https://github.com/hongfaqiu/cesium-extends',
}
},
logo: "/logo.svg"
},
alias: {
'@': path.resolve(__dirname, 'src'),
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cesium-extends 提供了以下功能:
- 热力图 `@cesium-extends/heat`
- ...

详细信息及 demo,请参阅 [API 文档](https://cesium-extends.vercel.app/)
详细信息及 demo,请参阅 [API 文档](https://extends.opendde.com/)

## 示例

Expand Down
1 change: 1 addition & 0 deletions doc/docs/doc/primitive-geojson.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ layer.load('path/to/data.json').then(() => {
- `fill`: 填充区域的颜色。
- `clampToGround`: 是否贴地。
- `credit`可选: 图层的信用信息。
- `depthTest`可选: 是否开启深度测试。

该方法返回一个 `Promise` 对象,在 GeoJSON 加载完成时解析为当前实例。

Expand Down
32 changes: 32 additions & 0 deletions doc/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion packages/geojson-render/src/primitiveRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const primitiveGeoJsonRender = async (
const featureItems = [...primitiveLayer.featureItems];
primitiveLayer.removeAllPrimitive();
const { label, paint, type, custom } = style;
let depthTest: undefined | boolean = undefined;
featureItems.map((feature) => {
const customStyle: any = {};

Expand All @@ -31,6 +32,7 @@ export const primitiveGeoJsonRender = async (

const height = customStyle?.extrudedHeight;
const extrudedHeight = height ? height * 1000 : undefined;
if (depthTest === undefined && height) depthTest = true;

switch (type) {
case 'point':
Expand Down Expand Up @@ -156,7 +158,7 @@ export const primitiveGeoJsonRender = async (
});
}
});
primitiveLayer.reloadPrimitive();
primitiveLayer.reloadPrimitive(depthTest);
};

export const renderPrimitiveGeoJson = async (
Expand Down
13 changes: 11 additions & 2 deletions packages/primitive-geojson/src/GeoJsonPrimitiveLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,17 @@ export class GeoJsonPrimitiveLayer extends BasicGraphicLayer {
this._polylineInstances = [];
}

reloadPrimitive() {
const appearance = new PerInstanceColorAppearance({
reloadPrimitive(depthTest: boolean = this._options.depthTest ?? false) {
const appearance = depthTest ? new PerInstanceColorAppearance({
translucent: false,
renderState: {
depthTest: {
enabled: true,
},
depthMask: true,
blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND
},
}) : new PerInstanceColorAppearance({
flat: true,
translucent: false,
closed: true,
Expand Down
1 change: 1 addition & 0 deletions packages/primitive-geojson/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type GeoJsonPrimitiveLayerOptions = {
fill: Color;
clampToGround: boolean;
credit?: Credit | string;
depthTest?: boolean;
};

export type PrimitiveItem =
Expand Down

0 comments on commit 6215682

Please sign in to comment.