This guide explains how to use non-point geometries (Polygon, MultiPolygon, LineString, MultiLineString) with the ScreenGrid layer via the built-in placement preprocessor and the new rendering mode for per-feature glyphs.
The current point-based, screen-space grid aggregation remains supported and is the default.
source: Provide GeoJSON Features instead of an array of points. Mutually exclusive withdata/getPosition.placement: Configure how geometry features are converted to “anchors” (points) for rendering or aggregation.renderMode:screen-grid(default): anchors are aggregated into screen-space cells (current pipeline).feature-anchors: anchors are drawn directly (one glyph per anchor).
import { ScreenGridLayerGL } from 'screengrid';
// Example: Admin areas with centroid anchors, drawn once per feature
const layer = new ScreenGridLayerGL({
source: adminGeoJSON,
placement: { strategy: 'centroid', partition: 'union' },
renderMode: 'feature-anchors',
anchorSizePixels: 18,
glyph: 'circle',
glyphConfig: { color: '#3498db', alpha: 0.9 },
enableGlyphs: true
});point(Point/MultiPoint pass-through)centroid(one anchor per feature; line/polygon centroid)line-sample(sample points at regular intervals along lines)grid-geo(sample polygon interior at geodesic spacing in meters; respects holes)grid-screen(screen-grid center selection for anchors inside polygons; pixels)polylabel(optional; better polygon label placement, falls back to centroid)
See also: docs/PLACEMENT_CONFIG.md for the full schema and validation rules.
-
screen-grid(default):source + placementproduce anchors → anchors aggregated to cells → glyphs per cell.- Works well for density visualizations and large datasets.
-
feature-anchors:source + placementproduce anchors → anchors drawn directly with glyphs.- Best for one-glyph-per-feature or controlled sampling like
grid-screen.
Note: When using grid-screen, the library auto-switches renderMode to feature-anchors to avoid double aggregation and emits a single deduplicated console warning to inform the user.
- One glyph per polygon centroid:
new ScreenGridLayerGL({
source: adminGeoJSON,
placement: { strategy: 'centroid' },
renderMode: 'feature-anchors',
anchorSizePixels: 18,
glyph: 'circle',
enableGlyphs: true
});- Lines sampled every 200 meters and then aggregated into the grid:
new ScreenGridLayerGL({
source: roadsGeoJSON,
placement: { strategy: 'line-sample', spacing: { meters: 200 }, zoomAdaptive: true },
renderMode: 'screen-grid',
cellSizePixels: 60
});- Polygons filled with screen-grid anchors, drawn directly:
new ScreenGridLayerGL({
source: adminGeoJSON,
placement: { strategy: 'grid-screen', spacing: { pixels: 60 }, maxPerFeature: 200 },
renderMode: 'feature-anchors',
anchorSizePixels: 10,
glyph: 'circle',
enableGlyphs: true
});- Avoid double aggregation:
grid-screenshould be used withfeature-anchors. - Use
maxPerFeatureto limit dense grids. - For heavy strategies (
grid-geo,polylabel), consider larger spacing or fewer features. - View-dependent recomputation:
grid-screenand pixel-based spacing will recompute on pan/zoom; caching reduces churn.
To enable polylabel placement with pole-of-inaccessibility, install the package:
npm install polylabelIf it’s not installed, the library falls back to centroid with a console warning.
feature-anchors: hover/click events return the nearest anchor and its feature props in a backward-compatible “cell-like” payload.screen-grid: events remain cell-based as before.- Legends can be configured similarly; auto-detection by
renderModecan be added in the legend module.