Changeset 536 for trunk


Ignore:
Timestamp:
Apr 30, 2007, 10:31:28 AM (13 years ago)
Author:
Nick Burch
Message:

Pad the grid numbers properly

Location:
trunk/london.npemap.org.uk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/london.npemap.org.uk/index.html

    r535 r536  
    5151        var tile_y_offset = y - (tile_y*24);
    5252
    53         // Always seem to be 1 tile too far to the right
     53        // Always seem to be 1 tile too far to the right, and 1 too high
    5454        tile_x -= 1;
     55        tile_y -= 1;
    5556
    5657        location.href="/tiles.html#"+tile_x+","+tile_y+",1";
  • trunk/london.npemap.org.uk/js/mapTiles.js

    r533 r536  
    7373        var grid_e = Math.floor(gmc_easting/1000);
    7474        var grid_n = Math.floor(gmc_northing/1000);
    75         var offset_e = Math.round(gmc_easting - (grid_e*1000));
    76         var offset_n = Math.round(gmc_northing - (grid_n*1000));
     75        var offset_e = trimThreeDigits(Math.round(gmc_easting - (grid_e*1000)));
     76        var offset_n = trimThreeDigits(Math.round(gmc_northing - (grid_n*1000)));
    7777        // Need to go from top left, not bottom left
    7878        grid_n = 16 - grid_n;
     
    349349}
    350350
     351function trimThreeDigits(string) {
     352        // If we have a 4+ digit number, no need to do any padding
     353        if(parseInt(string) >= 1000) { return string; }
     354
     355        // Pad it so that it'll always have leading 0s, and be at least 3 long
     356        str = '000' + string
     357        // Grab the right most 3 digits, which will have any required padding
     358        return str.substring(str.length -3)
     359}
    351360function trimSixDigits(string) {
    352361        // If we have a 7 digit number, no need to do any padding
Note: See TracChangeset for help on using the changeset viewer.