OpenLayers OpenLayers

Ticket #1489: permalink.patch

File permalink.patch, 3.0 kB (added by tcoulter, 9 months ago)
  • lib/OpenLayers/Control/Permalink.js

    old new  
    1414 *  - <OpenLayers.Control> 
    1515 */ 
    1616OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, { 
     17    ARG_PARSER_CLASS_NAME: "OpenLayers.Control.ArgParser", 
    1718 
    1819    /**  
    1920     * Property: element  
     
    8081        //make sure we have an arg parser attached 
    8182        for(var i=0; i< this.map.controls.length; i++) { 
    8283            var control = this.map.controls[i]; 
    83             if (control.CLASS_NAME == "OpenLayers.Control.ArgParser") { 
     84            if (control.CLASS_NAME == this.ARG_PARSER_CLASS_NAME) { 
    8485                 
    8586                // If a permalink is added to the map, and an ArgParser already 
    8687                // exists, we override the displayProjection to be the one 
    87                 // on the permalink.  
     88                // on the ArgParser.  
    8889                if (control.displayProjection != this.displayProjection) { 
    8990                    this.displayProjection = control.displayProjection; 
    9091                }     
     
    9394            } 
    9495        } 
    9596        if (i == this.map.controls.length) { 
    96             this.map.addControl(new OpenLayers.Control.ArgParser
     97            this.map.addControl(new eval(this.ARG_PARSER_CLASS_NAME)
    9798                { 'displayProjection': this.displayProjection }));        
    9899        } 
    99100 
     
    109110        OpenLayers.Control.prototype.draw.apply(this, arguments); 
    110111           
    111112        if (!this.element) { 
     113            this.div.className = this.displayClass; 
    112114            this.element = document.createElement("a"); 
    113115            this.element.innerHTML = OpenLayers.i18n("permalink"); 
    114116            this.element.href=""; 
     
    120122            'changebaselayer': this.updateLink, 
    121123            scope: this 
    122124        }); 
     125         
     126        // Make it so there is at least a link even though the map may not have 
     127        // moved yet. 
     128        this.updateLink(); 
     129         
    123130        return this.div; 
    124131    }, 
    125132    
     
    127134     * Method: updateLink  
    128135     */ 
    129136    updateLink: function() { 
    130         var center = this.map.getCenter(); 
    131          
    132         // Map not initialized yet. Break out of this function. 
     137        this.element.href = this.createUrl(); 
     138    },  
     139     
     140    createUrl: function(center) { 
     141             
     142        if (center == null) { 
     143            center = this.map.getCenter(); 
     144        }   
     145           
     146        // If there's still no center, map is not initialized yet.  
     147        // Break out of this function, and simply return the base link. 
    133148        if (!center) {  
    134             return;  
     149            return this.base;  
    135150        } 
    136151 
    137152        var params = OpenLayers.Util.getParameters(this.base); 
     
    168183        } 
    169184 
    170185        href += '?' + OpenLayers.Util.getParameterString(params); 
    171         this.element.href = href; 
     186        return href; 
    172187    },  
    173188 
    174189    CLASS_NAME: "OpenLayers.Control.Permalink"