Styling and labels · Angular, React and OpenLayers

Several styles for one feature

Compose three concentric OpenLayers circle styles on one feature—halo, rimmed ring and core dot—ordered deterministically with zIndex in Angular.

Kraków's Main Square with a blue point in a white ring and a light blue halo.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

Directly on Kraków’s Main Square, a single point feature renders as a crisp multi-layered cartographic target: a wide translucent outer halo, a white-rimmed middle ring and a solid dark centre dot—built entirely from vector circle primitives without external PNG or SVG assets.

When you need it

Single-stroke or single-circle symbols easily disappear against busy aerial orthophotos or dense street networks.

Stacking a contrasting casing or translucent halo underneath a foreground symbol keeps markers, GPS locks and selected vertices legible over dark forests and bright rooftops alike.

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.

styles-composition.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  FeatureComponent,
  GeometryPointComponent,
  LayerTileComponent,
  LayerVectorComponent,
  MapComponent,
  SourceOsmComponent,
  SourceVectorComponent,
  StyleCircleComponent,
  StyleComponent,
  StyleFillComponent,
  StylesComponent,
  StyleStrokeComponent,
  ViewComponent,
} from 'cc-openlayers';

/** A point drawn with three stacked circle styles: a halo, a ring and a centre dot. */
@Component({
  selector: 'app-styles-composition',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    FeatureComponent,
    GeometryPointComponent,
    LayerTileComponent,
    LayerVectorComponent,
    MapComponent,
    SourceOsmComponent,
    SourceVectorComponent,
    StyleCircleComponent,
    StyleComponent,
    StyleFillComponent,
    StylesComponent,
    StyleStrokeComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="15"><aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" /></aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-layer-vector>
        <aol-source-vector>
          <aol-feature>
            <aol-geometry-point><aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" /></aol-geometry-point>
            <aol-styles>
              <aol-style [zIndex]="1">
                <aol-style-circle [radius]="24">
                  <aol-style-stroke color="rgba(22, 125, 222, 0.18)" [width]="18" />
                  <aol-style-fill color="rgba(22, 125, 222, 0.08)" />
                </aol-style-circle>
              </aol-style>
              <aol-style [zIndex]="2">
                <aol-style-circle [radius]="12">
                  <aol-style-stroke color="#ffffff" [width]="4" />
                  <aol-style-fill color="#167dde" />
                </aol-style-circle>
              </aol-style>
              <aol-style [zIndex]="3">
                <aol-style-circle [radius]="4"><aol-style-fill color="#0b2f57" /></aol-style-circle>
              </aol-style>
            </aol-styles>
          </aol-feature>
        </aol-source-vector>
      </aol-layer-vector>
    </aol-map>
  `,
})
export class StylesComposition {}

Architecture and OpenLayers mechanics

Wrapping multiple aol-style elements inside aol-styles attaches an array of OpenLayers Style instances to the single point feature. Assigning explicit [zIndex] integers orders the passes deterministically from bottom to top—painting the wide translucent halo first, the white-rimmed ring second and the inner dot last.

How it works

  • aol-styles binds an array of styles to one feature, with each child aol-style contributing one rendering pass.
  • [zIndex] fixes the draw order from lowest to highest: outer translucent halo, white-rimmed ring, then dark centre dot.
  • Constructing all three passes from vector circles of different radii requires zero external image downloads and scales sharply on any screen.

Pitfalls

  • Leaving zIndex unset relies purely on array order, which dynamic template updates can inadvertently reshuffle—specify explicit [zIndex] values on multi-pass symbols.
  • Each extra style in aol-styles adds another draw pass per feature; for layers holding tens of thousands of identical markers, pre-render the composite symbol once onto an off-screen canvas icon instead.

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.