ol2 icon indicating copy to clipboard operation
ol2 copied to clipboard

OpenLayers.Popup closeBoxCallback not fired

Open florianheeg opened this issue 13 years ago • 4 comments

Hi,

i have an OpenLayers Map with some markers. Every marker has it's own popup to display when clicked on it and every Popup has a closeBoxCallback which should be fired if the popup will be hidden. It works if i click the close button of the popup but the event / callback isn't fired if i add the popup as exclusive (map.addPopup(popup, true)) and click another marker or if i hide the popup manually with popup.hide().

I want to excuse for my bad english, it's not my native language.

florianheeg avatar Feb 15 '12 10:02 florianheeg

Does someone have the same problem or can reproduce it? Do you need more information?

florianheeg avatar Feb 23 '12 14:02 florianheeg

I think I might be hitting the same issue than you ...

lissyx avatar Jul 23 '12 10:07 lissyx

I cannot reproduce after upgrading from 2.11 to 2.12.

lissyx avatar Jul 23 '12 11:07 lissyx

Hi. Until a better solution exists, I think we can use the following one:

Override the addCloseBox method from OpenLayers.Popup. Check out the changes I made.

/**
 * Method: addCloseBox
 * 
 * Parameters:
 * callback - {Function} The callback to be called when the close button
 *     is clicked.
 */
OpenLayers.Popup.prototype.addCloseBox = function(callback) {

    this.closeDiv = OpenLayers.Util.createDiv(
        this.id + "_close", null, {w: 17, h: 17}
    );
    this.closeDiv.className = "olPopupCloseBox"; 

    // use the content div's css padding to determine if we should
    //  padd the close div
    var contentDivPadding = this.getContentDivPadding();

    this.closeDiv.style.right = contentDivPadding.right + "px";
    this.closeDiv.style.top = contentDivPadding.top + "px";
    this.groupDiv.appendChild(this.closeDiv);

    // COMMENT OUT THIS DEFINITION OF 'closePopup'
    //var closePopup = callback || function(e) {
    //    this.hide();
    //    OpenLayers.Event.stop(e);
    //};

    // NEW DEFINITION OF 'closePopup'
    var closePopup = function(e) {
        this.hide();
        /* Checks whether the callback is a function */
        if (typeof callback == 'function') { 
            /* Triggers the callback */
            callback(); 
        }
        OpenLayers.Event.stop(e);
    };

    OpenLayers.Event.observe(this.closeDiv, "touchend", 
            OpenLayers.Function.bindAsEventListener(closePopup, this));
    OpenLayers.Event.observe(this.closeDiv, "click", 
            OpenLayers.Function.bindAsEventListener(closePopup, this));
};

:)

joaorodr84 avatar Mar 30 '16 11:03 joaorodr84