Tooltips | Android SDK v5 | Mappedin Developer Portal
Loading...

Tooltips

A Tooltip is similar to a marker, except, it has a mechanism to avoid collisions with other items on the map by positioning itself relative to the point where it's added. This is done automatically and makes it useful for long text with icons. Tooltips can also be clickable, which makes them ideal for showing connection points such as elevators and switching to the following map after an interaction from the user.

Tooltips could be used as helpful hints for a user to navigate, with prompts such as "Take elevator to Floor 2" at a certain node on the map.

A complete class that uses the code snippets in this guide can be found in the Mappedin Android Github repo: Tooltips.kt

Drawing Tooltips

When creating a Tooltip, the app specifies some HTML to display and the node to attach it too. The tooltip will be anchored to a specified node or coordinate in one of eight anchor orientations, which are defined in MPIOptions.TooltipAnchor. The possible anchor types are top, bottom, left, right, topLeft, topRight, bottomLeft, and bottomRight. This describes the position of the tooltip relative to the node or coordinate to which it is attached. Tooltip options such as interactivity and collision rank are specified using MPIOptions.Tooltip.

The code below uses createTooltip to create a tooltip and store its Id:

mapView.createTooltip(
node = nodeToAttachTooltip,
contentHtml = """
<div tabindex="0" style="padding: 10px; background-color: gray;">
This is a tooltip!
</div>""",
) {
id ->
if (id != null) {
tooltipId = id
}
}

Custom Tooltips

While regular Tooltips come with some base styling, custom tooltips allow an app to have complete control over the element's appearance. Creation is similar to a regular tooltip, with the addition of a CSS selector string that allows the SDK to target the tooltip.

The code below uses createCustomTooltip to create a tooltip and store its Id:

mapView.createCustomTooltip(
node = nodeToAttachTooltip,
contentHtml = """
<div class="my-tooltip-wrapper" style="position: absolute;">
<div class="tips" style="filter: drop-shadow(0 0 2px #00000050);">
<div style="background: red; color: white;padding: 10px;border-radius: 10px;">
Tool Tip
</div>
</div>
</div>""",
selector = ".my-tooltip-wrapper",
MPIOptions.Tooltip(
collisionRank = MPIOptions.COLLISION_RANK.MEDIUM,
)){
id ->
if (id != null) {
tooltipId = id
}
}

A complete class that uses the code snippets in this guide can be found in the Mappedin Android Github repo: Tooltips.kt

Was this page helpful?

Next Topic

Locations