From 8d12e15138cd6e8bb5d68ed37d8639fa37786eb7 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 13 Mar 2025 14:26:39 +0000 Subject: [PATCH 1/3] Added support for a new model layout property: allow-density-reduction --- 3d-style/data/bucket/model_bucket.ts | 17 ++++++++++------- .../style_layer/model_style_layer_properties.ts | 2 ++ src/style-spec/reference/v8.json | 16 ++++++++++++++++ src/style-spec/types.ts | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/3d-style/data/bucket/model_bucket.ts b/3d-style/data/bucket/model_bucket.ts index fbe3dd8b481..9ea7f5d5a3e 100644 --- a/3d-style/data/bucket/model_bucket.ts +++ b/3d-style/data/bucket/model_bucket.ts @@ -342,6 +342,7 @@ class ModelBucket implements Bucket { ): string { const layer = this.layers[0]; const modelIdProperty = layer.layout.get('model-id'); + const modelAllowDensityReductionProperty = layer.layout.get('model-allow-density-reduction'); assert(modelIdProperty); const modelId = modelIdProperty.evaluate(evaluationFeature, {}, this.canonical); @@ -371,14 +372,16 @@ class ModelBucket implements Bucket { if (point.x < 0 || point.x >= EXTENT || point.y < 0 || point.y >= EXTENT) { continue; // Clip on tile borders to prevent duplicates } - // reduce density - const tileToLookup = (this.lookupDim - 1.0) / EXTENT; - const lookupIndex = this.lookupDim * ((point.y * tileToLookup) | 0) + (point.x * tileToLookup) | 0; - if (this.lookup) { - if (this.lookup[lookupIndex] !== 0) { - continue; + if (modelAllowDensityReductionProperty) { + // reduce density + const tileToLookup = (this.lookupDim - 1.0) / EXTENT; + const lookupIndex = this.lookupDim * ((point.y * tileToLookup) | 0) + (point.x * tileToLookup) | 0; + if (this.lookup) { + if (this.lookup[lookupIndex] !== 0) { + continue; + } + this.lookup[lookupIndex] = 1; } - this.lookup[lookupIndex] = 1; } this.instanceCount++; const i = instancedDataArray.length; diff --git a/3d-style/style/style_layer/model_style_layer_properties.ts b/3d-style/style/style_layer/model_style_layer_properties.ts index 23a450dbad3..22bb4518ca0 100644 --- a/3d-style/style/style_layer/model_style_layer_properties.ts +++ b/3d-style/style/style_layer/model_style_layer_properties.ts @@ -19,11 +19,13 @@ import type {StylePropertySpecification} from '../../../src/style-spec/style-spe export type LayoutProps = { "visibility": DataConstantProperty<"visible" | "none">; "model-id": DataDrivenProperty; + "model-allow-density-reduction": DataConstantProperty; }; let layout: Properties; export const getLayoutProperties = (): Properties => layout || (layout = new Properties({ "visibility": new DataConstantProperty(styleSpec["layout_model"]["visibility"]), "model-id": new DataDrivenProperty(styleSpec["layout_model"]["model-id"]), + "model-allow-density-reduction": new DataConstantProperty(styleSpec["layout_model"]["model-allow-density-reduction"]), })); export type PaintProps = { diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index d1fe597132c..13c7694dd86 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -1578,6 +1578,22 @@ "vector" ] }] + }, + "model-allow-density-reduction": { + "type": "boolean", + "default": true, + "doc": "If true, the models will be reduced in density based on the zoom level. This is useful for large datasets that may be slow to render.", + "sdk-support": { + "basic functionality": { + "js": "0.10.0", + "android": "2.0.1", + "ios": "2.0.0" + } + }, + "expression": { + "interpolated": false + }, + "property-type": "data-constant" } }, "layout_clip": { diff --git a/src/style-spec/types.ts b/src/style-spec/types.ts index 4b6b5a62809..afe1d2be025 100644 --- a/src/style-spec/types.ts +++ b/src/style-spec/types.ts @@ -1066,6 +1066,7 @@ export type ModelLayerSpecification = { "layout"?: { "visibility"?: "visible" | "none" | ExpressionSpecification, "model-id"?: DataDrivenPropertyValueSpecification + "model-allow-density-reduction"?: PropertyValueSpecification, }, "paint"?: { "model-opacity"?: DataDrivenPropertyValueSpecification, From a537010ececa1262515d8cf5a45ed94d3a79e20f Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 13 Mar 2025 15:20:10 +0000 Subject: [PATCH 2/3] fix lint --- 3d-style/data/bucket/model_bucket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3d-style/data/bucket/model_bucket.ts b/3d-style/data/bucket/model_bucket.ts index 9ea7f5d5a3e..638693a98c4 100644 --- a/3d-style/data/bucket/model_bucket.ts +++ b/3d-style/data/bucket/model_bucket.ts @@ -373,7 +373,7 @@ class ModelBucket implements Bucket { continue; // Clip on tile borders to prevent duplicates } if (modelAllowDensityReductionProperty) { - // reduce density + // reduce density const tileToLookup = (this.lookupDim - 1.0) / EXTENT; const lookupIndex = this.lookupDim * ((point.y * tileToLookup) | 0) + (point.x * tileToLookup) | 0; if (this.lookup) { From 4228794b8c1736fe9f00657255d86ae5c9d4a8b9 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 13 Mar 2025 15:44:49 +0000 Subject: [PATCH 3/3] fixed types --- src/style-spec/reference/v8.json | 4 +--- src/style-spec/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 13c7694dd86..e5d03c1cb7e 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -1582,6 +1582,7 @@ "model-allow-density-reduction": { "type": "boolean", "default": true, + "transition": false, "doc": "If true, the models will be reduced in density based on the zoom level. This is useful for large datasets that may be slow to render.", "sdk-support": { "basic functionality": { @@ -1590,9 +1591,6 @@ "ios": "2.0.0" } }, - "expression": { - "interpolated": false - }, "property-type": "data-constant" } }, diff --git a/src/style-spec/types.ts b/src/style-spec/types.ts index afe1d2be025..727238863e1 100644 --- a/src/style-spec/types.ts +++ b/src/style-spec/types.ts @@ -1065,8 +1065,8 @@ export type ModelLayerSpecification = { "filter"?: FilterSpecification, "layout"?: { "visibility"?: "visible" | "none" | ExpressionSpecification, - "model-id"?: DataDrivenPropertyValueSpecification - "model-allow-density-reduction"?: PropertyValueSpecification, + "model-id"?: DataDrivenPropertyValueSpecification, + "model-allow-density-reduction"?: boolean }, "paint"?: { "model-opacity"?: DataDrivenPropertyValueSpecification,