instantsearch
instantsearch copied to clipboard
Geo add the ability to get a reference to the map instance
Is your feature request related to a problem? Please describe 🙏
It might happen in some cases that you directly want to interact with the map instance. Right now the only way to get this instance is through the event listeners on the markers. It would be nice to provide it as soon as the map is instantiated.
Describe the solution you'd like 🤔
We can trigger an event once the map is instantiated.
search.addWidget(
instantsearch.widgets.geoSearch({
container: "#geo-search-container",
googleReference: window.google,
events: {
onMapCreated: instance => {
// Do something with the instance
}
}
})
);
Additional context
See https://github.com/algolia/instantsearch.js/issues/2778#issuecomment-411552188
another option would be to add this event to the return of .geoSearch()
, but that would be less obvious to deal with, so adding events
here seems nice. Maybe it can be added to other ones too if it makes sense
Have you considered having the the instance of the map as a property of the widget and documenting it?
@bobylito then it would be undefined before mounted right?
@bobylito then it would be undefined before mounted right?
Probably indeed 😅 . Other idea: what about having a method on the widget instance that returns a promise of the map?
For anyone still wondering, a reference to the map is passed in the events from builtInMarker and customHTMLMarker.