OpenLayers

Use the Siemens basemap as a vector tile layer in OpenLayers. The tiles are read straight from our archive, and the Siemens style is applied to them, so the map matches the embed.

Live

Plain OpenLayers controls: drag, wheel or the plus and minus buttons; with the map focused, arrow keys pan and plus and minus zoom.

Install

Terminal
npm install ol@10.11.0 ol-pmtiles@2.0.2 ol-mapbox-style@13.10.0 \
  https://maps.siemens-cdn.com/sdk/1.2.0/siemens-maps-1.2.0.tgz

Code

index.html
<div id="map" style="height: 420px"></div>
<script type="module" src="./main.js"></script>
main.js
import Map from 'ol/Map';
import View from 'ol/View';
import VectorTileLayer from 'ol/layer/VectorTile';
import { fromLonLat } from 'ol/proj';
import 'ol/ol.css';
import { PMTilesVectorSource } from 'ol-pmtiles';
import { applyStyle } from 'ol-mapbox-style';
import { siemensStyle, OSM_ATTRIBUTION } from '@siemens/maps/style';

const style = await siemensStyle({ scheme: 'light' });
const layer = new VectorTileLayer({
  declutter: true,
  source: new PMTilesVectorSource({
    url: style.sources.protomaps.url.replace('pmtiles://', ''),
    attributions: [OSM_ATTRIBUTION],
  }),
});
// The Siemens style on that source. webfonts: false: no font requests to a public CDN.
await applyStyle(layer, style, { source: 'protomaps', updateSource: false, webfonts: false });

new Map({
  target: 'map',
  layers: [layer],
  view: new View({ center: fromLonLat([11.575, 48.1443]), zoom: 14 }),
});

Content Security Policy

Content-Security-Policy
connect-src 'self' https://maps.siemens-cdn.com

OpenLayers draws on a canvas in the page itself: no worker and no frame.

Good to know

  • Attribution: keep the attribution control with “© OpenStreetMap contributors” visible.
  • Labels: OpenLayers draws text with the page’s fonts, not the map’s glyphs. Load Noto Sans from your own host if labels must match the embed exactly.
  • Where it works: the tiles answer Siemens apps on https://*.siemens.zone and localhost.
  • Library versions on this page: ol 10.11.0, ol-pmtiles 2.0.2, ol-mapbox-style 13.10.0.