OpenLayers OpenLayers

Changeset 4818

Show
Ignore:
Timestamp:
10/04/07 11:46:20 (1 year ago)
Author:
ianmayo
Message:

More detailed skeleton implementation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/ianmayo/openlayers/lib/OpenLayers/Control/ScaleLine.js

    r4815 r4818  
    5959    }, 
    6060 
    61     /**  
    62      * Method: getDataWidth 
    63      * Returns: 
    64      * {Float} the width of the currently viewed data 
    65      */ 
    66     getDataWidth: function(){ 
    67         return 12; 
    68     }, 
    6961 
    7062    /**  
    71      * Method: getScreenWidth 
     63     * Method: getBarLen 
     64     * Parameters: 
     65     * maxLen - {float}  the calculated bar must be less than or equal to this size 
     66     * units - {String}  the units that this bar must be "rounded" down to 
    7267     * Returns: 
    73      * {Float} the width of the viewport, in pixels 
     68     * {Float} the width of the scale bar in specified units (less than or equal to maxLen) 
    7469     */ 
    75     getScreenWidth: function(){ 
     70    getBarLen: function(maxLen, units){ 
     71        // produce set of thresholds (in metres) 
     72        var thresholds = [1,2,5,10,20,50,100,200,500,1000,2000,5000, 
     73                10000,20000,50000,100000,200000,500000]; 
     74 
    7675        return 120; 
    7776    }, 
     
    8685        if (!scale) return; 
    8786         
    88         // right, we're to plot scale in metres first. how many metres in scale? 
    89         //  
     87        // ok, what's the max size of bar to draw 
     88        var maxSizePx = 100; 
    9089         
    91         // ok.  how large is the map? 
     90        // ok, convert it to data units 
     91        var maxSizeDeg = maxSizePx * scale; 
    9292         
    93         // now,  
     93        // now trim this down to useful block 
     94        var barMetricKm = this.getBarLen(maxSizeDeg, "km"); 
     95        var barImperialMiles = this.getBarLen(maxSizeDeg, "mi"); 
    9496         
    95     //  scale = parseInt(scale); 
    96          
    97         var extent = this.map.getExtent(); 
    98         var width = extent.right - extent.left; 
    99          
    100         // we just want the line to be about 10% of the width of the plot, so shrink it down. 
    101         width /= 10; 
    102  
    103         // produce set of thresholds (in metres) 
    104         var thresholds = [1,2,5,10,20,50,100,200,500,1000,2000,5000, 
    105                 10000,20000,50000,100000,200000,500000]; 
    106                  
    107         // convert width to metres 
    108         var widthMetres = parseInt(width * 60 * 1852); 
    109         var thisWidth; 
    110          
    111         for(i=0;i<thresholds.length;i++) 
    112         { 
    113             var thisT = thresholds[i]; 
    114             if(thisT > widthMetres) 
    115             { 
    116                 break; 
    117             } 
    118         } 
    119          
    120         // move down two sizes 
    121         if(i > 2) 
    122         { 
    123           i -= 2; 
    124           } 
    125            
    126         thisWidth = thresholds[i]; 
    127          
    128         // convert this width to back to degrees 
    129         var thisWidthDegs =  thisWidth / (60 * 1852) 
     97        // and back to data units 
     98        var barMetricDegs = barMetricKm / OpenLayers.INCHES_PER_UNIT["km"] * OpenLayers.INCHES_PER_UNIT["degrees"]; 
     99        var barImperialDegs = barImperialMiles / OpenLayers.INCHES_PER_UNIT["mi"] * OpenLayers.INCHES_PER_UNIT["degrees"]; 
    130100         
    131101        // and to screen units 
    132         thisWidthDegs *= scale; 
     102        var barMetricPx = barMetricDegs / scale; 
     103        var barImperialPx = barImperialDegs / scale; 
    133104         
    134105         
    135  
    136 //        if (scale >= 9500 && scale <= 950000) { 
    137 //            scale = Math.round(scale / 1000) + "K"; 
    138 //        } else if (scale >= 950000) { 
    139 //            scale = Math.round(scale / 1000000) + "M"; 
    140 //        } else { 
    141 //            scale = Math.round(scale); 
    142 //        }     
    143          
    144         this.metric.style.width=thisWidthDegs / 5; 
    145         this.imperial.style.width=140;       
     106        this.metric.style.width= barMetricPx; 
     107        this.imperial.style.width= barImperialPx; 
    146108         
    147109        scale = parseInt(scale); 
    148110         
    149         this.metric.innerHTML = parseInt(thisWidth) + " m"; 
    150         this.imperial.innerHTML = scale + " m"; 
     111        this.metric.innerHTML = "12" + " m"; 
     112        this.imperial.innerHTML = "6" + " miles"; 
    151113    },  
    152114