Map with marker centering
Displays the location of the entities on Map. Allows to choose among existing tile providers or configure own server. Supports markers, marker tooltips, widget actions, polygons, and circles for enhanced spatial representation. Any other widget on the dashboard can bring an entity into view: broadcast ‘markerCentered’ with its id and the map pans to that marker, opening its tooltip or leaving it closed.
Map with marker centering
Shows where your entities are on a map, and lets any other widget on the dashboard point that map at one of them. It is the standard entity map — tile providers, markers, tooltips, polygons and circles — with one addition: a marker can be brought into view by broadcasting its entity id, so a table, a list or an alarm widget can drive the map instead of leaving the operator to hunt for the right pin.
What it displays
Each entity in the datasource becomes a marker at the coordinates it reports. Markers carry a tooltip, can trigger widget actions, and can be joined by polygons and circles drawn from the same entities. The base layer comes from a tile provider you choose, or from a tile server of your own.
Data keys
Each data layer reads its own keys. The names below are the defaults; every one of them is a setting, so point them at whatever your devices actually report.
| Layer | Key | Default name | Type |
|---|---|---|---|
| Markers | X | latitude | number |
| Markers | Y | longitude | number |
| Polygons | Polygon | perimeter | attribute holding the point list |
| Circles | Circle | perimeter | attribute holding centre and radius |
A marker appears only once both of its coordinate keys have a value. An entity that has never reported its position is not drawn, and is not an error.
Centring the map on a marker
This is what the widget adds to the standard map. Broadcast markerCentered with an entity id, and
the map pans to that entity’s marker:
const broadcastService = widgetContext.$scope.$injector .get(widgetContext.servicesMap.get('broadcastService'));
broadcastService.broadcast('markerCentered', entityId.id, false);The three arguments are:
| Argument | What it is |
|---|---|
'markerCentered' | the event the map listens for |
entityId.id | the id of the entity to centre on — the id itself, not the whole entityId object |
false | whether to open that marker’s tooltip once the map has moved |
Pass true for the last argument when the operator needs to see the entity’s details straight away —
coming from an alarm table, for instance. Pass false when the map is one panel among several and a
tooltip would cover the neighbouring markers.
The call can be made from anywhere that has a widget context: a widget action, a custom action’s script, or another widget’s controller.
Where this is worth using
- An alarm widget: clicking an alarm centres the map on the device that raised it, with the tooltip open.
- An entity table or list: selecting a row moves the map to that entity, keeping the list as the place where the operator navigates.
- A search or filter widget: narrowing to one entity brings it into view without touching the map.
Configuration
The widget carries the standard map settings. The ones worth knowing about:
| Setting | What it does |
|---|---|
| Map provider | Which tile source draws the base layer, or a URL for a server of your own |
| Data layers | Markers, polygons and circles, each with its own datasource and keys |
| Marker icon and colour | The pin itself, including rules that colour it by a reported value |
| Tooltip | The content shown on a marker, written as a template over the entity’s keys |
| Widget actions | What a click on a marker does |
| Default map position and zoom | Where the map opens before anything is centred |
| Fit map bounds | Whether the map zooms to include every marker when it loads |
Note that centring on a marker moves the view: if fit map bounds is on, it applies when the map loads, and a later broadcast overrides it.
What happens with an id the map does not know
Broadcasting an id that has no marker — an entity outside the datasource, or one that has not reported a position — leaves the view where it is. Nothing is centred and nothing fails, so a table listing more entities than the map shows will not break the dashboard.
Share Your Widget with the Community
Built a custom widget? Export it as a JSON from ThingsBoard and publish it to the IoT Hub through a simple 4-step wizard (Upload, Listing, Readme, Review & Submit). Share it with thousands of ThingsBoard developers worldwide and get featured in the catalog.