instantsearch icon indicating copy to clipboard operation
instantsearch copied to clipboard

Geo add the ability to get a reference to the map instance

Open samouss opened this issue 6 years ago • 5 comments

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

samouss avatar Aug 09 '18 11:08 samouss

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

Haroenv avatar Aug 10 '18 07:08 Haroenv

Have you considered having the the instance of the map as a property of the widget and documenting it?

bobylito avatar Aug 10 '18 09:08 bobylito

@bobylito then it would be undefined before mounted right?

Haroenv avatar Aug 10 '18 11:08 Haroenv

@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?

bobylito avatar Aug 10 '18 12:08 bobylito

For anyone still wondering, a reference to the map is passed in the events from builtInMarker and customHTMLMarker.

samo012 avatar Jul 14 '22 15:07 samo012