Element Maps¶
Element Maps is Element's high-level Angular map component based on OpenLayers. It provides points, grouping, clusters, labels, tooltips, and popovers out of the box.
Usage¶
Use Element Maps when an application needs a ready-to-use map component with Element-specific behavior instead of assembling map features individually.
When to use¶
- To display and group location points with a predefined Element presentation.
- When built-in clustering, labels, tooltips, or popovers are required.
- When a high-level component is preferable to direct interaction with a map library.
Code¶
The si-map component uses the OpenLayers library. OpenLayers is a high-performance, feature-rich library for creating interactive geographical maps. It can display map tiles, vector data, and markers loaded from a wide range of sources.
The API documentation can be found in the official OpenLayers API docs, with further useful examples on the OpenLayers examples page. The source code is available in the OpenLayers GitHub repository.
For cluster functionality and other additional features, ol-ext is used. More information and documentation can be found in the ol-ext GitHub repository.
The OpenLayers ol-mapbox-style library is used to create OpenLayers maps from Mapbox Style Specification objects.
Usage¶
Required Packages
npm install --save @siemens/maps-ng
# Also install the needed peer dependencies
npm install --save ol ol-ext ol-mapbox-style
Add library assets and CommonJS dependencies in angular.json under the build options:
{
"architect": {
"build": {
"options": {
"assets": [
{
"glob": "**/*",
"input": "./node_modules/@siemens/maps-ng/assets",
"output": "/assets/"
}
],
"allowedCommonJsDependencies": [
"xml-utils/find-tags-by-name.js",
"xml-utils/get-attribute.js",
"web-worker",
"pbf",
"earcut",
"rbush"
]
}
}
}
}
Import the OpenLayers styles into the main global stylesheet:
@use 'ol/ol.css';
Import SiMapComponent into the component that displays the map:
import { Component } from '@angular/core';
import { SiMapComponent } from '@siemens/maps-ng';
@Component({
selector: 'app-map',
imports: [SiMapComponent],
template: '<si-map maptilerKey="REPLACE_WITH_YOUR_MAPTILER_KEY" />'
})
export class MapComponent {}
Provide a MapTiler key when using the default map style:
<si-map maptilerKey="REPLACE_WITH_YOUR_MAPTILER_KEY"></si-map>
Features¶
Grouping¶
Points on the map can be grouped so they share the color provided in groupColors. While clustered, points are grouped in a donut chart.
To group points, specify the group property on a point object. The value of group is used to match the color from the default palette or groupColors, if provided. While groupColors is optional, the default color palette is status.
A custom color palette can be defined with the following code:
<si-map [points]="points" [groupColors]="{ 1: 'red', 2: 'green', 3: 'blue', 4: 'black'}"></si-map>
Accessibility of custom colors
The usage of Element color definitions is strongly recommended to fulfill accessibility standards. Involve your UX specialist when using custom colors to ensure accessibility, especially important are appropriate contrasts for different themes.
To override a group color, specify a marker color on the point object itself:
const point: MapPoint = {
name: 'Point 1',
lon: 11,
lat: 10,
group: 1,
marker: {
color: 'orange'
}
};
Examples¶
Grouping with default status palette:
<si-map [points]="points"></si-map>
const points: MapPoint[] = [
{
name: 'Point 1',
lon: 11,
lat: 10,
group: 1 // $element-status-information
},
{
name: 'Point 2',
lon: 11,
lat: 10,
group: 2 // $element-status-success
},
{
name: 'Point 3',
lon: 11,
lat: 10,
group: 3 // $element-status-warning
},
{
name: 'Point 4',
lon: 11,
lat: 10,
group: 4 // $element-status-danger
}
];

Grouping with Element palette colors:
<si-map [points]="points" groupColors="element"></si-map>
const points: MapPoint[] = [
{
name: 'Point 1',
lon: 11,
lat: 10,
group: 1 // $element-red-500 / 300 (depending on theme)
},
{
name: 'Point 2',
lon: 11,
lat: 10,
group: 2 // $element-orange-500
},
{
name: 'Point 3',
lon: 11,
lat: 10,
group: 3 // $element-blue-500
},
{
name: 'Point 4',
lon: 11,
lat: 10,
group: 4 // $element-yellow-500
}
];

Custom Mapbox style¶
The map appearance can be changed by passing a custom Mapbox style to the component as the styleJson input. In this case, maptilerKey is not needed as the custom style overrides it.
<si-map [styleJson]="styleJson"></si-map>
See the official Mapbox documentation for more information.
Customize tooltip length¶
Customize the tooltip width with maxLabelLength:
<si-map
class="flex-fill"
[points]="points"
[displayTooltipOnHover]="true"
[maptilerKey]="maptilerKey"
>
<si-map-tooltip [maxLabelLength]="50" />
</si-map>
Map example¶
SiMapComponent API Documentation¶
si-mapInput Properties¶
| Name | Type | Default | Description |
|---|---|---|---|
| alwaysShowLabels ¶ | boolean | false | Show the label permanently next to the point. Normally the label is shown on hover or click. By enabling this it will always be visible next to the marker. |
| autoZoomClusterClick ¶ | boolean | true | When disabled, clusters will no longer automatically be zoomed to on click. |
| autoZoomFeatureClick ¶ | boolean | false | When enabled, features will be automatically zoom to on click. |
| cluster ¶ | boolean | false | Enable or disable clustering of points on the map. |
| clusterClickZoom ¶ | number | DEFAULT_CLUSTER_CLICK_ZOOM | Max zoom level for clicking on a cluster on the map. Defaults to 15. |
| clusterDistance ¶ | number | DEFAULT_CLUSTER_DISTANCE | Defines range in which points are clustered. In pixels. |
| clusterPopoverComponent ¶ | Type<any> | Custom popover component for clustering | |
| displayPopoverOnClick ¶ | boolean | true | Option to switch on/off the display of popover when clicked. Default set to true (on). |
| displayPopoverOnHover ¶ | boolean | false | Option to switch on/off popover when hovered. Default is set to false (off) |
| displayTooltipOnClusterHover ¶ | boolean | false | Option to switch on/off the display of tooltip while hovering over cluster. |
| displayTooltipOnHover ¶ | boolean | false | Option to switch on/off the display of tooltip while hovering over single point. |
| featureClickZoom ¶ | number | DEFAULT_FEATURE_CLICK_ZOOM | Max zoom level which is used when clicking on feature on the map. Defaults to 15. |
| featureSelectZoom ¶ | number | DEFAULT_FEATURE_SELECT_ZOOM | Zoom level when calling the select() method on the component. Defaults to 10. |
| fitClusterPadding ¶ | [ number, number, number, number ] | [20, 20, 20, 20] | Padding (in pixels) applied to the map view when zooming to a cluster, preventing points from being clipped at the edges. Specified as [top, right, bottom, left]. |
| fitGeoJsonPadding ¶ | number[] | [20, 20, 20, 20] | For GeoJson, padding (in pixels) to be cleared to fit the GeoJson inside the view after a click on it. Values in the array are: [top, right, bottom, left]. |
| fitPointPadding ¶ | number[] | [20, 20, 20, 20] | For Point geometry, padding (in pixels) to be cleared to fit the point inside the view after a click on it. Values in the array are: [top, right, bottom, left]. |
| geoJson ¶ | any | Payload of a geo-JSON object. | |
| geoJsonProjection ¶ | string | 'EPSG:3857' | Projection format used to render the geo-JSON payload. |
| globalZoom ¶ | number | DEFAULT_GLOBAL_ZOOM | Max zoom level on load or when clicking the reset button. Defaults to 5. |
| groupColors ¶ | (Record<number, string> | ColorPalette) | 'status' | Defines which colors should be used when points are grouped. Grouping means that points are painted with their group color and they are displayed as series in donut chart inside cluster. |
| maptilerKey ¶ | string | Provide your key for MapTiler, this will use the default siemens element styles which can be used in both light and dark mode. Shouldn't be used together with styleJson. | |
| markerAnimation ¶ | boolean | false | Enable or disable animation of markers. |
| maxLabelLineLength ¶ | number | 20 | Maximum number of characters per line for always displayed labels of a point. If the label exceeds this limit, it will be wrapped or trimmed. If set to 0, label trimming will be disabled. This setting is effective only when alwaysShowLabels is enabled. Important: Changing this is not recommended in most cases and may cause issues with positioning of the labels. |
| maxLabelLines ¶ | number | 3 | Maximum number of lines for always displayed labels of a point. If the label exceeds this limit, it will be trimmed. This setting is effective only when alwaysShowLabels is enabled and maxLabelLineLength is not 0. Important: Changing this is not recommended in most cases and may cause issues with positioning of the labels. |
| multiWorld ¶ | boolean | true | Show multiple worlds, including points that cross the 180th meridian. |
| nativeProperties ¶ | OverlayNativeProperties | - overlay: Layer for popup element, an element to be displayed over the map and attached to a single map location. - controls: List of controls to activate for map, additional controls like full screen, etc. can be added here. | |
| points ¶ | MapPoint[] | Points to be rendered on the map as features. | |
| popoverCloseOnClick ¶ | boolean | true | Close the popover on click |
| popoverComponent ¶ | Type<any> | Custom popover component | |
| popoverComponentProps ¶ | any | Custom popover component | |
| styleFunction ¶ | StyleLike | Callback function to add custom styling to the drawn geo-JSON features. | |
| styleJson ¶ | any | Type of background map, for example 'https://api.maptiler.com/maps/voyager/style.json?key=xxx' (Token key is required). The styleJson defines the tiler source and the used styles for different layers, should only be used if the siemens default styles by using maptilerKey isn't good enough. |
Output Properties¶
| Name | Type | Description |
|---|---|---|
| pointsChange ¶ | MapPoint[] | Points to be rendered on the map as features. |
| pointsRefreshed ¶ | void | Emitted when the points are available as features. So consumers can call methods like zoomToPoints() on the actual point list. |
| pointsSelected ¶ | MapPoint[] | Emitted when points on the map are selected or de-selected |
Methods¶
| Name | Type | Description |
|---|---|---|
| clear | clear() => void | Remove all points from map. |
| refresh | refresh(points: MapPoint[]) => void | Updates the map with new set of points provided in argument. |
| select | select(point: MapPoint) => void | Zoom in the provided point and display popover with additional information. |
MapTiler API key¶
Element Maps currently supports MapTiler as an OSM tile source. An API key is required to use this service. The API key is unique per project and its use is limited to certain URLs through an HTTP Origin Header allow-list.
As with most map services, commercial use of the API is a paid service and requires an account with an active subscription. Element does not provide such an account for all of Siemens.
Testing¶
When running automated tests, do not load map tiles. This drastically reduces the number of MapTiler requests, which are limited by contract. Tests should cover the application's map functionality rather than the map data.
- Unit tests: Do not provide an API key.
- Playwright tests: Stub the
tiles.jsonrequest and related requests usingpage.route(...).
Types Documentation¶
Variable |
|---|
Variable |
|---|
Variable |
|---|
Variable |
|---|
Variable |
|---|
|
| ||||||||
|
import imported from ol |
|---|
| ||||||
|
| Represents a translatable string. This can either be a translation key, e.g. ACTIONS.EDIT that will be automatically translated when displayed on the UI or a pre-translated string, e.g. Edit . Equivalent to a normal string in usage and functionality. |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
|
Function |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
| Class for grouping functionality | ||||||
|---|---|---|---|---|---|---|
| ||||||
| ||||||
| ||||||
|
import imported from ol |
|---|
Constructor |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
import imported from ol |
|---|
|
| ||||||||||||||||
| ||||||||||||||||
| ||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||
| |||||||||||||||||
|
| Wrapper around an actual translation framework which is meant to be used internally by Element. Applications must not use this service. Use injectSiTranslateService to get an instance of the translation service. | |||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
|
| Pass through implementation of the SiTranslateService which is used as a default. | |||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
|
Except where otherwise noted, content on this site is licensed under MIT License.