Controls · Angular, React and OpenLayers

An overview map

Mount an expanded OpenLayers OverviewMap inset control with its own dedicated OpenStreetMap tile layer to frame the main viewport in context.

A street map around Wawel in Kraków with the overview map in its lower left corner.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

Zoomed closely into the streets around Wawel Castle in Kraków, an expanded inset map in the bottom-left corner shows the wider city context with a draggable extent box indicating the exact area currently visible in the main viewport.

Panning or zooming the main map updates the inset box in real time, dragging the inset box repositions the main map, and clicking the corner toggle button folds the overview away when extra canvas room is needed.

When you need it

When analysts inspect utility trenches, cadastral parcels or high-zoom aerial imagery at 1:1 000 scale, surrounding district landmarks disappear off screen and spatial orientation is easily lost.

A classic cartographic overview inset preserves macro regional context alongside micro street detail without splitting the screen into two equal maps.

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.

overview.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';
import { ControlOverviewMapComponent } from 'cc-openlayers/overview';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';

/** OpenLayers' overview map control: a small map that shows and moves the main map's extent. */
@Component({
  selector: 'app-overview',
  imports: [
    ControlOverviewMapComponent,
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    MapComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-control-overviewmap [collapsed]="false" [layers]="overviewLayers" />
      <aol-view [zoom]="15">
        <aol-coordinate [x]="19.9356" [y]="50.054" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
    </aol-map>
  `,
})
export class Overview {
  /** OpenLayers' overview map shows only the layers it is given. */
  protected readonly overviewLayers = [new TileLayer({ source: new OSM() })];
}

Architecture and OpenLayers mechanics

aol-control-overviewmap (imported from cc-openlayers/overview) mounts an independent miniature OpenLayers Map instance inside the control overlay. Because OpenLayers renders nothing inside an overview by default—and strictly forbids sharing a single Layer instance across two Map instances—the component supplies a dedicated TileLayer + OSM source array through [layers].

Setting [collapsed]="false" opens the inset on startup, while OpenLayers automatically scales the overview zoom so the indicator box stays between roughly 10% and 75% of the inset frame.

How it works

  • aol-control-overviewmap from cc-openlayers/overview attaches OpenLayers’ interactive overview inset control.
  • [layers] provides a dedicated OpenStreetMap tile layer exclusively for the overview map instance.
  • [collapsed]="false" starts the inset open on initial render while retaining its corner collapse/expand button.

Pitfalls

  • Never pass the main map’s own Layer instances into [layers]: each OpenLayers Layer object can belong to only one Map at a time, so always instantiate separate layer objects (which can still share stateless tile URLs) for the overview.
  • Avoid locking a fixed zoom on a custom overview View unless intended—OpenLayers’ default dynamic overview scaling keeps the viewport indicator box legible across all zoom levels instead of shrinking it to an invisible dot.

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.