Skip to content

Added support for a new model layout property: allow-density-reduction #13433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions 3d-style/data/bucket/model_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions 3d-style/style/style_layer/model_style_layer_properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import type {StylePropertySpecification} from '../../../src/style-spec/style-spe
export type LayoutProps = {
"visibility": DataConstantProperty<"visible" | "none">;
"model-id": DataDrivenProperty<string>;
"model-allow-density-reduction": DataConstantProperty<boolean>;
};
let layout: Properties<LayoutProps>;
export const getLayoutProperties = (): Properties<LayoutProps> => 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 = {
Expand Down
14 changes: 14 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,20 @@
"vector"
]
}]
},
"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": {
"js": "0.10.0",
"android": "2.0.1",
"ios": "2.0.0"
}
},
"property-type": "data-constant"
}
},
"layout_clip": {
Expand Down
3 changes: 2 additions & 1 deletion src/style-spec/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,8 @@ export type ModelLayerSpecification = {
"filter"?: FilterSpecification,
"layout"?: {
"visibility"?: "visible" | "none" | ExpressionSpecification,
"model-id"?: DataDrivenPropertyValueSpecification<string>
"model-id"?: DataDrivenPropertyValueSpecification<string>,
"model-allow-density-reduction"?: boolean
},
"paint"?: {
"model-opacity"?: DataDrivenPropertyValueSpecification<number>,
Expand Down