Skip to content

Commit 8e0d49e

Browse files
authored
Pass vertexValid to SolidPolygonLayer when using binary GeoJSON (#9805)
1 parent 07601cb commit 8e0d49e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/api-reference/layers/solid-polygon-layer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Only applies if `extruded: true`.
297297

298298
This section is about the special requirements when [supplying attributes directly](../../developer-guide/performance.md#supply-attributes-directly) to a `SolidPolygonLayer`.
299299

300-
Because each polygon has a different number of vertices, when `data.attributes.getPolygon` is supplied, the layer also requires an array `data.startIndices` that describes the vertex index at the start of each polygon. For example, if there are 3 polygons of 3, 4, and 5 vertices each (including the end vertex that overlaps with the first vertex to close the loop), `startIndices` should be `[0, 3, 7, 12]`. *Polygons with holes are not supported when using precalculated attributes.*
300+
Because each polygon has a different number of vertices, when `data.attributes.getPolygon` is supplied, the layer also requires an array `data.startIndices` that describes the vertex index at the start of each polygon. For example, if there are 3 polygons of 5, 6, and 7 vertices each (including the end vertex that overlaps with the first vertex to close the loop), `startIndices` should be `[0, 5, 13, 20]`. When the polygon data contains holes, an additional array must be passed as `data.attributes.vertexValid`. This array must be a mask where all vertices are `1` except for the index of the last vertex of each polygon ring, which should be `0`. For instance, if the second polygon contains an outer ring with 3 vertices followed by an inner ring of 3 vertices then `vertexValid` should be passed as `[1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0]`. For reference see https://github.com/visgl/deck.gl/blob/master/modules/layers/src/geojson-layer/geojson-layer-props.ts#L107-L111.
301301

302302
Additionally, all other attributes (`getFillColor`, `getElevation`, etc.), if supplied, must contain the same layout (number of vertices) as the `getPolygon` buffer.
303303

modules/layers/src/geojson-layer/geojson-layer-props.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,22 @@ export function createLayerPropsFromBinary(
104104
} as LayerData<any>;
105105
layerProps.lines._pathType = 'open';
106106

107+
const vertexCount = polygons.positions.value.length / polygons.positions.size;
108+
const vertexValid = Array(vertexCount).fill(1);
109+
for (const index of polygons.primitivePolygonIndices.value) {
110+
vertexValid[index - 1] = 0;
111+
}
112+
107113
layerProps.polygons.data = {
108114
length: polygons.polygonIndices.value.length - 1,
109115
startIndices: polygons.polygonIndices.value,
110116
attributes: {
111117
...polygons.attributes,
112118
getPolygon: polygons.positions,
119+
instanceVertexValid: {
120+
size: 1,
121+
value: new Uint16Array(vertexValid)
122+
},
113123
pickingColors: {
114124
size: 4,
115125
value: customPickingColors.polygons!

0 commit comments

Comments
 (0)