Changeset 568 for trunk


Ignore:
Timestamp:
Jul 24, 2007, 9:51:16 PM (12 years ago)
Author:
Nick Burch
Message:

Support for negative northings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gpx.npemap.org.uk/js/mapTiles.js

    r451 r568  
    77var sizeGridX = 6;   // Size of visible grid (table) in each dimension
    88var sizeGridY = 4;   // Size of visible grid (table) in each dimension
     9
     10var minY = -86; // Minimum Y at scale 1
    911
    1012var tileWidth = 125;
     
    196198
    197199
    198 // Need to use substring for IE, and it doesn't take negative numbers.
     200// Need to use substring for IE
     201// Pads to 3 digits with zeros, or - and 2 digits
    199202function trimNumber(string) {
    200         // If we have a 4 digit number, no need to do any padding
    201         if(parseInt(string) >= 1000) { return string; }
     203        // If we have a 3+ digit number, no need to do any padding
     204        if(parseInt(string) >= 100) { return string; }
     205        // Or a 2+ digit negative number, no need to do any padding
     206        if(parseInt(string) <= -10) { return string; }
     207
     208        // Special case for 1 digit negative numbers
     209        if(parseInt(string) <= 0) {
     210                var num = parseInt(string);
     211                return '-0' + (0-num);
     212        }
    202213
    203214        // Pad it so that it'll always have leading 0s, and be at least 3 long
     
    208219
    209220function trimSixDigits(string) {
    210         // If we have a 7 digit number, no need to do any padding
    211         if(parseInt(string) >= 1000000) { return string; }
     221        // If we have a 6+ digit number, no need to do any padding
     222        if(parseInt(string) >= 100000) { return string; }
     223        // Or a 5+ digit negative number, no need to do any padding
     224        if(parseInt(string) <= -10000) { return string; }
     225
     226        // Is it negative?
     227        var num = parseInt(string)
     228        var isNegative = (num < 0);
     229        if(isNegative) {
     230                num = 0 - num;
     231        }
    212232
    213233        // Pad it so that it'll always have leading 0s, and be at least 6 long
    214         str = '000000' + string
     234        str = '000000' + num;
    215235        // Grab the right most 6 digits, which will have any required padding
    216         return str.substring(str.length -6)
    217 }
     236        str = str.substring(str.length -6)
     237        // Add back in - at start if needed
     238        if(isNegative) {
     239                str = '-' + str.substring(1);
     240        }
     241        return str;
     242}
     243
    218244
    219245function refreshGrid() {
     
    281307    }
    282308    else if ( theDirection == 'down' ) {
    283         if ( offsetGridY > 0 )
     309        if ( offsetGridY > Math.round(minY / zooms[zoomLevel]) )
    284310            offsetGridY --;
    285311    }
Note: See TracChangeset for help on using the changeset viewer.