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.
I would like to be able to run custom JavaScript code whenever an Openlayers Popup is displayed.
Adding the following lines to the end of the popup.js file accomplishes this goal.
// Allow other code to be triggered when a popup is displayed.
jQuery(document).trigger('openlayers.Component:Popup', { 'overlay': overlay, 'evt': evt });
Comment | File | Size | Author |
---|---|---|---|
#2 | openlayers_popup_trigger-2687781-1.patch | 577 bytes | m.stenta |
|
Comments
Comment #2
m.stentaPatch attached.
The following code illustrates an example usage. Simply put this into a javascript file and include in the same page as your map with drupal_add_js().
Comment #4
jantoine CreditAttribution: jantoine as a volunteer commentedThis is a much better approach than what I was trying to do which was to copy how the GeoJSON source component is extended. Instead of using drupal_add_js() to include your javascript on a specific page, hook_openlayers_object_postprocess_alter() might be more robust as it is path independent and will load your javascript no matter where your maps/popups are loaded.
Example code:
Comment #5
m.stentaThanks for the JS loading tip @jantoine! And for trying the patch! :-)
If it's working for you, feel free to mark this issue "Reviewed & tested by the community".
Comment #6
jantoine CreditAttribution: jantoine as a volunteer commentedThis is working great for us!