Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8d12e15

Browse files
committedMar 13, 2025·
Added support for a new model layout property: allow-density-reduction
1 parent df4901f commit 8d12e15

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed
 

‎3d-style/data/bucket/model_bucket.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class ModelBucket implements Bucket {
342342
): string {
343343
const layer = this.layers[0];
344344
const modelIdProperty = layer.layout.get('model-id');
345+
const modelAllowDensityReductionProperty = layer.layout.get('model-allow-density-reduction');
345346
assert(modelIdProperty);
346347

347348
const modelId = modelIdProperty.evaluate(evaluationFeature, {}, this.canonical);
@@ -371,14 +372,16 @@ class ModelBucket implements Bucket {
371372
if (point.x < 0 || point.x >= EXTENT || point.y < 0 || point.y >= EXTENT) {
372373
continue; // Clip on tile borders to prevent duplicates
373374
}
374-
// reduce density
375-
const tileToLookup = (this.lookupDim - 1.0) / EXTENT;
376-
const lookupIndex = this.lookupDim * ((point.y * tileToLookup) | 0) + (point.x * tileToLookup) | 0;
377-
if (this.lookup) {
378-
if (this.lookup[lookupIndex] !== 0) {
379-
continue;
375+
if (modelAllowDensityReductionProperty) {
376+
// reduce density
377+
const tileToLookup = (this.lookupDim - 1.0) / EXTENT;
378+
const lookupIndex = this.lookupDim * ((point.y * tileToLookup) | 0) + (point.x * tileToLookup) | 0;
379+
if (this.lookup) {
380+
if (this.lookup[lookupIndex] !== 0) {
381+
continue;
382+
}
383+
this.lookup[lookupIndex] = 1;
380384
}
381-
this.lookup[lookupIndex] = 1;
382385
}
383386
this.instanceCount++;
384387
const i = instancedDataArray.length;

‎3d-style/style/style_layer/model_style_layer_properties.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import type {StylePropertySpecification} from '../../../src/style-spec/style-spe
1919
export type LayoutProps = {
2020
"visibility": DataConstantProperty<"visible" | "none">;
2121
"model-id": DataDrivenProperty<string>;
22+
"model-allow-density-reduction": DataConstantProperty<boolean>;
2223
};
2324
let layout: Properties<LayoutProps>;
2425
export const getLayoutProperties = (): Properties<LayoutProps> => layout || (layout = new Properties({
2526
"visibility": new DataConstantProperty(styleSpec["layout_model"]["visibility"]),
2627
"model-id": new DataDrivenProperty(styleSpec["layout_model"]["model-id"]),
28+
"model-allow-density-reduction": new DataConstantProperty(styleSpec["layout_model"]["model-allow-density-reduction"]),
2729
}));
2830

2931
export type PaintProps = {

‎src/style-spec/reference/v8.json

+16
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,22 @@
15781578
"vector"
15791579
]
15801580
}]
1581+
},
1582+
"model-allow-density-reduction": {
1583+
"type": "boolean",
1584+
"default": true,
1585+
"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.",
1586+
"sdk-support": {
1587+
"basic functionality": {
1588+
"js": "0.10.0",
1589+
"android": "2.0.1",
1590+
"ios": "2.0.0"
1591+
}
1592+
},
1593+
"expression": {
1594+
"interpolated": false
1595+
},
1596+
"property-type": "data-constant"
15811597
}
15821598
},
15831599
"layout_clip": {

‎src/style-spec/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ export type ModelLayerSpecification = {
10661066
"layout"?: {
10671067
"visibility"?: "visible" | "none" | ExpressionSpecification,
10681068
"model-id"?: DataDrivenPropertyValueSpecification<string>
1069+
"model-allow-density-reduction"?: PropertyValueSpecification<boolean>,
10691070
},
10701071
"paint"?: {
10711072
"model-opacity"?: DataDrivenPropertyValueSpecification<number>,

0 commit comments

Comments
 (0)
Please sign in to comment.