angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

InfoWindow Events Attribute Missing

Open neerajkumarnj opened this issue 8 years ago • 6 comments

I have been trying to access the google map events e.g. "domready", for when user clicks a marker to open the infoWindow. But nothing seems to work. domready event is never caught or fired. I want to customize some of the things in google maps (using angular-google-maps).

How can i listen to Google Map API events? Its not specified anywhere in the documentation. I have used something like below, but that doesn't work:

infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(infoWindow, 'domready', function() {
      // whatever you want to do once the DOM is ready
});

neerajkumarnj avatar Oct 27 '15 08:10 neerajkumarnj

So is your question how to deal with events in the same way as above? Cause what you have should work for your purposes of doing it 100% programatically.

nmccready avatar Oct 27 '15 13:10 nmccready

Anyway if the desire is to be similar to markers then the events attribute should be added to the window and windows directive. http://angular-ui.github.io/angular-google-maps/#!/api/marker

That would be the most succinct and angular approach.

But to get something working right now. You can use control and bind an empty object in your controller to the windows control. Then you can iterate and bind events through all window objects just like you have above.

http://angular-ui.github.io/angular-google-maps/#!/api/windows

nmccready avatar Oct 27 '15 13:10 nmccready

Apologies for the late reply, i am in middle of trying out things for maps. But surely, it will be a great to have a "event" attribute in the window/windows directive. Thanks for the help.

neerajkumarnj avatar Nov 05 '15 06:11 neerajkumarnj

Hi, when will this be implemented? I don't seem to find it in 2.3.2 release.

I need to listen of some of the InfoWindow events listed here:

https://developers.google.com/maps/documentation/javascript/reference#InfoWindow

As a side note, with this feature implement, the current code to trigger close event can be eliminated as well:

https://github.com/angular-ui/angular-google-maps/blob/cbd17a3a225dfe543faa124eb295e66db566f27c/dist/angular-google-maps.js#L8479-L8502

edmondchui avatar Apr 26 '16 20:04 edmondchui

When is it going to be implemented ?

andrehsmendes avatar Jun 30 '16 18:06 andrehsmendes

An update to anyone trying to listen for the infowindow 'domready' event here is the solution using the current code: http://plnkr.co/edit/WIfDF8CQ0sGJFF1DJ6PH?p=preview

As @nmccready points out you can create an empty infowindow control object within the main controller. eg: $scope.infowindowControl = {};

Then you scope bind your new object in the ui-gmap-window directive definition like:

<ui-gmap-window
	options="windowOptions"
	closeClick="closeClick()"
	control="infowindowControl"
>

On infowindow open (actually unsure at what point) - it will pass five functions (some of which are noted in the documentation but in a rather haphazard and non-defined way - needs an update):

  • getChildWindows()
  • getGWindows()
  • getPlurals()
  • hideWindow()
  • showWindow()

The one that you need is getGWindows() - you can call this inside marker click event - which will get you an array of the open infowindows, to which you can now attach an event listener in the standard google maps fashion, like:

var windows = $scope.infowindowControl.getGWindows();
	console.log('inside click after getGWindows ', windows);
google.maps.event.addListener(windows[0], 'domready', function() {
	console.log('infowindow domready just fired !!');
});

While it's not an ideal, well documented or easy solution (and took me a number of hours to figure out) - and passing functions to an empty object is frankly counter-intuitive - it does seem to work.

I've also posted this on SO here - hope this helps.

gigmaps avatar Dec 14 '16 18:12 gigmaps