Instance Method

topOverlayAtPoint

Returns the topmost overlay at a given point on the webpage.

Declaration

mapkit.Overlay topOverlayAtPoint(DOMPoint point);

Parameters

point

A point in the page's coordinate system, such as new DOMPoint(event.pageX, event.pageY) when handling a mouse event.

Return Value

Returns the topmost overlay or null.

Discussion

If there are multiple overlays at a point, the overlay closest to the foreground is returned. If an overlay is selected, the selected overlay is returned. Selected overlays are drawn on top of all other overlays.

The following code example identifies the topmost overlay during a mouse move event:

document.querySelector(".mk-map-view").addEventListener("mousemove", function(event) {
    var targetOverlay = map.topOverlayAtPoint(new DOMPoint(event.pageX, event.pageY));
    // Add special styling to the overlay to indicate its hover state or whatever you'd like.
    // ...
});

See Also

Adding and Removing Overlays

overlays

An array of all of the map's overlays.

selectedOverlay

The overlay on the map that is selected.

overlaysAtPoint

Returns an array of overlays at a given point on the webpage.

addOverlay

Adds an overlay to the map.

addOverlays

Adds multiple overlays to the map.

removeOverlay

Removes an overlay from the map.

removeOverlays

Removes multiple overlays from the map.