Changeset 562 for trunk


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

Handle negative northings, for the Channel Islands

File:
1 edited

Legend:

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

    r550 r562  
    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;
     
    321323
    322324
    323 // Need to use substring for IE, and it doesn't take negative numbers.
     325// Need to use substring for IE
     326// Pads to 3 digits with zeros, or - and 2 digits
    324327function trimNumber(string) {
    325         // If we have a 4 digit number, no need to do any padding
    326         if(parseInt(string) >= 1000) { return string; }
     328        // If we have a 3+ digit number, no need to do any padding
     329        if(parseInt(string) >= 100) { return string; }
     330        // Or a 2+ digit negative number, no need to do any padding
     331        if(parseInt(string) <= -10) { return string; }
     332
     333        // Special case for 1 digit negative numbers
     334        if(parseInt(string) <= 0) {
     335                var num = parseInt(string);
     336                return '-0' + (0-num);
     337        }
    327338
    328339        // Pad it so that it'll always have leading 0s, and be at least 3 long
     
    333344
    334345function trimSixDigits(string) {
    335         // If we have a 7 digit number, no need to do any padding
    336         if(parseInt(string) >= 1000000) { return string; }
     346        // If we have a 6+ digit number, no need to do any padding
     347        if(parseInt(string) >= 100000) { return string; }
     348        // Or a 5+ digit negative number, no need to do any padding
     349        if(parseInt(string) <= -10000) { return string; }
     350
     351        // Is it negative?
     352        var num = parseInt(string)
     353        var isNegative = (num < 0);
     354        if(isNegative) {
     355                num = 0 - num;
     356        }
    337357
    338358        // Pad it so that it'll always have leading 0s, and be at least 6 long
    339         str = '000000' + string
     359        str = '000000' + num;
    340360        // Grab the right most 6 digits, which will have any required padding
    341         return str.substring(str.length -6)
     361        str = str.substring(str.length -6)
     362        // Add back in - at start if needed
     363        if(isNegative) {
     364                str = '-' + str.substring(1);
     365        }
     366        return str;
    342367}
    343368
     
    563588    }
    564589    else if ( theDirection == 'down' ) {
    565         if ( offsetGridY > 0 )
     590        if ( offsetGridY > Math.round(minY / zooms[zoomLevel]) )
    566591            offsetGridY --;
    567592    }
Note: See TracChangeset for help on using the changeset viewer.