screengrid

Geometry Input & Placement Guide

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.


New Concepts


Quick Start

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
});

Placement Strategies

See also: docs/PLACEMENT_CONFIG.md for the full schema and validation rules.


Rendering Modes

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.


Examples

1) One glyph per polygon centroid:

new ScreenGridLayerGL({
  source: adminGeoJSON,
  placement: { strategy: 'centroid' },
  renderMode: 'feature-anchors',
  anchorSizePixels: 18,
  glyph: 'circle',
  enableGlyphs: true
});

2) 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
});

3) 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
});

Performance & Pitfalls


Optional Dependency: polylabel

To enable polylabel placement with pole-of-inaccessibility, install the package:

npm install polylabel

If it’s not installed, the library falls back to centroid with a console warning.


Events & Legend