Vector data · Angular, React and OpenLayers
A polygon from WKB
Decode hexadecimal Well-Known Binary (WKB) geometries from spatial databases in OpenLayers using readGeometry and explicit projection options.

What this example shows
Over OpenStreetMap at zoom 9 between Kraków and Tarnów, the exact same Lesser Poland polygon renders directly from a compact hexadecimal Well-Known Binary (WKB_POLYGON) payload—matching the raw binary representation stored inside PostGIS tables.
When you need it
High-throughput spatial backends and GraphQL/JSON APIs frequently return raw hexadecimal WKB (or binary ArrayBuffer streams) straight from database cursors to avoid CPU-heavy text formatting on the database server.
Decoding WKB natively on the client cuts server serialisation overhead and avoids floating-point rounding drift.
The code
The example uses cc-openlayers, my Angular component library for OpenLayers: each aol-… element creates the OpenLayers object it names, updates it from its inputs and disposes of it with the component.
wkb.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
import WKB from 'ol/format/WKB';
const WKB_POLYGON =
'0103000000010000000500000033333333333333409A99999999F948409A999999999934409A999999991949406666666666E634400000000000E0484000000000008033403333333333D3484033333333333333409A99999999F94840';
/** A polygon read from hexadecimal WKB in geographic coordinates and shown in the map's Web Mercator. */
@Component({
selector: 'app-wkb',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="9"><aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" /></aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-vector>
<aol-source-vector>
<aol-feature [geometry]="geometry" />
</aol-source-vector>
</aol-layer-vector>
</aol-map>
`,
})
export class Wkb {
protected readonly geometry = new WKB().readGeometry(WKB_POLYGON, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857',
});
} The React version uses the library's React adapter, cc-openlayers/react: each component creates the OpenLayers object it names when it mounts, updates it from its props and disposes of it when it unmounts.
wkb.react.tsximport type Geometry from 'ol/geom/Geometry.js';
import WKB from 'ol/format/WKB.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Feature,
Map,
OSMSource,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const WKB_POLYGON =
'0103000000010000000500000033333333333333409A99999999F948409A999999999934409A999999991949406666666666E634400000000000E0484000000000008033403333333333D3484033333333333333409A99999999F94840';
const geometry = new WKB().readGeometry(WKB_POLYGON, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857',
}) as Geometry;
/** A polygon read from hexadecimal WKB in geographic coordinates and shown in the map's Web Mercator. */
export function Wkb() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={9}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer>
<VectorSource>
<Feature geometry={geometry} />
</VectorSource>
</VectorLayer>
</Map>
);
}How the React version works
A polygon read from hexadecimal WKB in degrees and shown in Web Mercator.
What both versions share
OpenLayers renders the map and handles the interactions; the cc-openlayers/core layer gives both adapters the same view binding (MapViewBinding) and the same conversion of coordinates from EPSG:4326 to the map's projection.
From Angular to React
| Angular | React |
|---|---|
<aol-feature [geometry]> | <Feature geometry> with a geometry read once in the module |
Who creates, updates and disposes
Map creates the ol/Map in useLayoutEffect and disposes of it on unmount; each layer, source and interaction component adds its object to the parent it gets from context and removes it in its effect's cleanup, as ngOnDestroy does in Angular.
Architecture and OpenLayers mechanics
WKB_POLYGON encodes byte-order (01 for little-endian), geometry type (3 for Polygon) and IEEE-754 double-precision vertex rings in hex. OpenLayers’ WKB readGeometry accepts hex strings, ArrayBuffers or Uint8Array views alike, reprojecting vertices from dataProjection into featureProjection in a single pass.
How it works
WKB_POLYGONrepresents a little-endian (01) Polygon (type3) with one closed five-vertex ring in hexadecimal.readGeometrydecodes hexadecimal strings as well as binary array buffers and typed arrays directly.dataProjectionandfeatureProjectiontransform decoded degree coordinates into the map’s Web Mercator projection.
Pitfalls
- Standard ISO WKB contains no SRID header, making explicit
dataProjectionmandatory; PostGIS Extended WKB (EWKB) embeds an SRID flag that OpenLayers can auto-detect only whendataProjectionis omitted and that EPSG code is registered. - Hex-encoded strings double the byte length of raw binary WKB—prefer binary ArrayBuffer transport or simplified geometries when transferring thousands of complex polygons.
Related examples
The same feature in the OpenLayers examples .
Background: state and lifecycle of maps in Angular with OpenLayers, which the components of cc-openlayers take care of.