MapKit JS Select Annotation Programmatically

It's a pretty simple question. In MapKit JS, how can you set an annotation as the selected annotation?


I already have the annotation on the map view and access to the annotation I want to select. I feel like there should be a method that MapKit (not js, just normal)


MKMapView in vanilla MapKit has a selectAnnotation method.


selectAnnotation(_:animated:)

Accepted Reply

Set the `selected` property on the annotation to true.


var a = map.annotations[0];
a.selected = true;
  • Does anyone know how to disable/remove the a.selected = true behavior? (i.e. when you "click" ("select") an annotation, or programmatically select it with the a.selected = true, how do you prevent the annotation marker animation? I want to remove that behavior, but this forum post is the closest I've come to better understanding selected-annotation behavior.

  • Does anyone know how to disable/remove the a.selected = true behavior? (i.e. when you "click" ("select") an annotation, or programmatically select it with the a.selected = true, how do you prevent the annotation marker animation? I want to remove that behavior, but this forum post is the closest I've come to better understanding selected-annotation behavior.

Add a Comment

Replies

Set the `selected` property on the annotation to true.


var a = map.annotations[0];
a.selected = true;
  • Does anyone know how to disable/remove the a.selected = true behavior? (i.e. when you "click" ("select") an annotation, or programmatically select it with the a.selected = true, how do you prevent the annotation marker animation? I want to remove that behavior, but this forum post is the closest I've come to better understanding selected-annotation behavior.

  • Does anyone know how to disable/remove the a.selected = true behavior? (i.e. when you "click" ("select") an annotation, or programmatically select it with the a.selected = true, how do you prevent the annotation marker animation? I want to remove that behavior, but this forum post is the closest I've come to better understanding selected-annotation behavior.

Add a Comment

"How do you select something on the map" "Set the .selected to true."


Well..... chalk that up to a history of seeing properties be read only and having methods to set, combined with a section of my code that wasn't executed. I didn't debug well due to confirmation bias - expecting the property to be read-only and requiring a setter... thanks for the simply obvious answer.

No problem! A documentation search didn't turn this up immediately for me, so here's a good place to find the available properties for an annotation (note that mapkit.Annotation is for custom annotations, but markerAnnotation inherits from this):


https://developer.apple.com/documentation/mapkitjs/mapkit/annotation


Hope this helps!

I read that. The description `A Boolean value indicating whether the annotation is selected` also lead me to think it was read only. I have really enjoyed Apple Maps though after switching from Google Maps.