I looked through supported events for mapkit.Map, however I couldn't find anything that would allow me to setup an event listener that adds an annotation on the location of user mouse click.
I understand that MapKit JS is still in beta, but I really expected this to be in the very first alpha release of annotations. Will this be supported?
MapKit JS relies as much as possible on existing DOM events. Here is an example using native DOM events to add annotations to a map on user click:
map.element.addEventListener("click", function(event) {
if (event.target.parentNode !== map.element) {
// This condition prevents clicks on controls. Binding to a
// secondary click is another option to prevent conflict
return;
}
var domPoint = new DOMPoint(event.pageX, event.pageY);
var coordinate = map.convertPointOnPageToCoordinate(domPoint);
map.addAnnotation(new mapkit.MarkerAnnotation(coordinate));
});
If there are ways you would like to see this improved during or after the Beta, please file an enhancement request via Apple Bug Reporter.