A marker consists of a pin, a tooltip and an optional popup:
- The pin is an element that should convey the marker's location and basic information like an icon or a color.
- The tooltip is an element that should provide additional information that needs to be readable — it could be a small or large amount of
information depending on the application.
- The popup is an element that is displayed when the user clicks on the marker. It should contain additional information that is not
necessary or too large for a tooltip.
Markers toggle between the pin and the tooltip elements as the user zooms in. The pin is displayed when there is no room for the tooltip. When
the user zooms in and more space is available, more tooltips are displayed. Which tooltips are displayed first is determined primarily by the
ranking of the markers — the higher the rank, the sooner the tooltip is displayed.
To add markers to the map, you first need to define an array of MapMarkerData objects. Provide the base marker data and the configuration
for the tooltip, pin and popup. The configurations have body callbacks which should return a HTMLElement.
Use the updateMarkers method on the map manager to update the map with new markers. If some of the provided markers already exist
on the map with the same id, it will be assumed that the data is the same (width, height, body...). This approach is designed for continuous updates
of map markers.
When updating the markers, you can let the library try to automatically measure the sizes of the provided elements, or use the dimensions property to manually set the sizes. Using it will also slightly improve loading performance when working with a large
number of complex elements.
The tooltip and popup body dimensions must abide by the following rules:
- The width, height and radius of the body must be greater than zero.
- The padding must be less than a fourth of the minimum of the width or height of the body.
The following are body callback functions for the current demo. Use them to return the HTMLElement object for the tooltip, pin
and popup. You can create them manually or by using a specific frontend library such as React, Vue, Svelte, or any other library that supports creating
and manipulating DOM elements.
To remove all markers from the map, use the removeMarkers method:
To manually toggle the popup of a marker, use the showPopup and hidePopup methods: