Skip to main content

Highlighting objects

You can highlight various objects on the map, such as buildings, roads, and others. To do that, call the setSelectedObjects() method and pass an array of IDs of the objects that you want to highlight.

map.setSelectedObjects([id1, id2]);

You can get the object ID, for example, by adding a click listener to the map and catching the MapPointerEvent:

map.on('click', (e) => {
if (!e.target) {
return;
}
const { id } = e.target;
alert('Object ID is ' + id);
});

To disable highlighting, call the setSelectedObjects() without arguments:

map.setSelectedObjects();

You can find a demonstration example below. Click on a map object to highlight it. Click on it again to remove the highlight.