Markers

Mappedin SDK version 6 is currently in an alpha state while Mappedin perfects a new design. Breaking changes may occur, which will be posted in the v6 release notes.

The Mappedin SDK allows adding and removing Markers on a map. Markers are elements containing HTML that the SDK anchors to a Door, Space or Coordinate. They are automatically rotated and repositioned when the camera moves.

Note that the MapView class implements the IMarkers interface and exposes it as MapView.Markers. Use MapView.Markers to utilize IMarkers' methods.

Web SDK v6 Markers

Creating Markers

Markers are added to the map by referencing a target that can be a Door, Space or Coordinate. The following code sample adds a marker to a coordinate.

mapView.Markers.add(coordinate, '<div>This is a Marker!</div>');

Marker anchoring can be customised using the options argument of IMarkers.add(). Options accepts a TAddMarkerOptions value, which has a member named anchor. Anchor positions are defined in TMarkerAnchor which contains 5 values. The anchor point are as follows, with the default being center.

TMarkerAnchor

  • center
  • top
  • left
  • bottom
  • right

Removing Markers

Markers can be removed individually by using the IMarkers.remove(marker) method, passing in the marker to be removed as shown below.

mapView.Markers.remove(marker);

To remove all markers from a map, call IMarkers.removeAll().

mapView.Markers.removeAll();

The CodeSandbox below demonstrates adding and removing markers. Click on a room to add a marker or click on a marker to remove it.

Marker Rank

Ranking can be added to markers to control which marker will be shown when more than one marker occupies the same space. The marker with the highest rank will be shown. If markers do not overlap, ranking will have no effect. Rank values medium, high and always-visible as defined in TCollisionRankingTier.

The code below adds markers where a user clicks on the map. The marker rank is cycled with each click. If the user clicks and adds multiple markers in the same location, the marker with the highest rank is shown and lower ranking markers are hidden.

const RANKS = ['medium', 'high', 'always-visible'] as const;
let rank = 0 as number;
// Act on the click event and add a marker with a cycling rank. Observe how higher ranking markers are shown when they collide with lower ranking markers.
mapView.on('click', async event => {
// TCollisionRankingTier contains 3 values. If rank exceeds 2, reset it to 0.
const markerTemplate = `
<div>
<style>
.marker {
display: flex;
align-items: center;
background-color: #fff;
max-height: 64px;
border: 2px solid grey;
padding: 4px 12px;
font-weight: bold;
font-family: sans-serif;
}
.marker img {
max-width: 64px;
max-height: 32px;
object-fit: contain;
margin-right: 12px;
}
</style>
<div class="marker">
<p>Marker Rank: ${RANKS[rank]}</p>
</div>
</div>`;
// Add a marker with the current rank at the clicked coordinate.
mapView.Markers.add(event.coordinate, markerTemplate, {
rank: RANKS[rank],
});
rank++;
if (rank === RANKS.length) {
rank = 0;
}
});

© 2024 Mappedin Inc.

All Rights Reserved.

Sign up for developer updates

Get early access to release notes, major version changes, version migration guides, and our developer focused blog posts.

Loading...

For more information

Read the Developer Blog

Explore the Playground

Talk to Sales

Maps for Good 🤍