OpenLayers OpenLayers

Ticket #330: closebox.patch

File closebox.patch, 4.1 kB (added by euzuro, 2 years ago)

add the option to put a close box on the popup

  • lib/OpenLayers/Popup/AnchoredBubble.js

    old new  
    2828    *                         - 'size' (OpenLayers.Size) and  
    2929    *                         - 'offset' (OpenLayers.Pixel)  
    3030    *                         (this is generally an OpenLayers.Icon) 
     31    * @param {Boolean} closeBox 
    3132    */ 
    32     initialize:function(id, lonlat, size, contentHTML, anchor) { 
     33    initialize:function(id, lonlat, size, contentHTML, anchor, closeBox) { 
    3334        OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments); 
    3435    }, 
    3536 
  • lib/OpenLayers/Popup/Anchored.js

    old new  
    3131    *                         - 'size' (OpenLayers.Size) and  
    3232    *                         - 'offset' (OpenLayers.Pixel)  
    3333    *                         (this is generally an OpenLayers.Icon) 
     34    * @param {Boolean} closeBox 
    3435    */ 
    35     initialize:function(id, lonlat, size, contentHTML, anchor) { 
    36         var newArguments = new Array(id, lonlat, size, contentHTML); 
     36    initialize:function(id, lonlat, size, contentHTML, anchor, closeBox) { 
     37        var newArguments = new Array(id, lonlat, size, contentHTML, closeBox); 
    3738        OpenLayers.Popup.prototype.initialize.apply(this, newArguments); 
    3839 
    3940        this.anchor = (anchor != null) ? anchor  
  • lib/OpenLayers/Popup.js

    old new  
    6060    * @param {OpenLayers.LonLat} lonlat 
    6161    * @param {OpenLayers.Size} size 
    6262    * @param {String} contentHTML 
     63    * @param {Boolean} closeBox 
    6364    */ 
    64     initialize:function(id, lonlat, size, contentHTML) { 
     65    initialize:function(id, lonlat, size, contentHTML, closeBox) { 
    6566        if (id == null) { 
    6667            id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 
    6768        } 
     
    9091        this.contentDiv.className = 'olPopupContent';                                             
    9192        this.div.appendChild(this.contentDiv); 
    9293 
     94        if (closeBox == true) { 
     95           // close icon 
     96            var closeSize = new OpenLayers.Size(17,17); 
     97            var img = OpenLayers.Util.getImagesLocation() + "close.gif"; 
     98            var closeImg = OpenLayers.Util.createAlphaImageDiv(this.id + "_close",  
     99                                                                null,  
     100                                                                closeSize,  
     101                                                                img); 
     102            closeImg.style.right = this.padding + "px"; 
     103            closeImg.style.top = this.padding + "px"; 
     104            this.div.appendChild(closeImg); 
     105 
     106            var closeEvents = new OpenLayers.Events(this, closeImg); 
     107            closeEvents.register("mousedown", this, this.hide); 
     108 
     109        } 
     110 
    93111        this.registerEvents(); 
    94112    }, 
    95113 
  • examples/popups.html

    old new  
    3737            popup = new OpenLayers.Popup("chicken",  
    3838                                         new OpenLayers.LonLat(5,40), 
    3939                                         new OpenLayers.Size(200,200), 
    40                                          "example popup"); 
     40                                         "example popup", 
     41                                         true); 
    4142         
    4243            map.addPopup(popup); 
    4344        }