Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By stongo on
I can't get GEvent.addListener() to work for a gmap in a view (using gmap module) in Drupal 7. Has anyone been able to create a click event for a gmap generated by a view? Any help would be appreciated, I'm stumped
Here's test code from my JS file
(function ($) {
Drupal.behaviors.example = {
attach: function (context, settings) {
var gmap = Drupal.gmap.getMap('auto1map');
GEvent.addListener(gmap, 'click', function() {
alert('help');
});
}
};
}(jQuery));
The alert doesn't get fired. Also tried adding a marker which also didn't work.
Comments
Update
ready() was the key, but in Drupal 7, it must be written:
This at least makes Drupal.gmap.getMap('mapname') return as an object in console.log, and I placed it in the footer to make sure it would be executed last, but I am still unable to make a click event work.
Not sure where to go from here...
Same problem
but I try to bind the new behavior
My code is:
Solved
Hello,
I was miss a lot of how to use JQuery in Drupal 7 and my problem solved now, I will share my solution to all.
The behaviour has changed
The behaviour has changed again!
This works for me:
Gmap add custom js events working code
Add extra events on gmap views for additional features.
Below code add onclick event on marker click and also focus the matched record on right side bar.
Example-: