source: subversion/sites/other/tilesAtHome/lib/tilenames.inc @ 2886

Last change on this file since 2886 was 2886, checked in by ojw, 13 years ago

Send uploads to new disk

File size: 1.2 KB
Line 
1<?php
2
3function TileName($X,$Y,$Z,$Layer="Tiles",$Old=0){
4  if(!$Layer)
5    return("");
6  if(!TileValid($X,$Y,$Z))
7    return("");
8
9  if($Old==1 && $Layer == "Tiles")
10    $BaseDir = "/home/ojw/tiles-ojw";
11  else
12    $BaseDir = "/home/ojw/tiles-ojw2";
13
14  return("$BaseDir/$Layer/".TilePartName($X,$Y,$Z));
15}
16function TileURL($X,$Y,$Z,$Layer="tile"){
17  if(!TileValid($X,$Y,$Z))
18    return("");
19  return(sprintf("/~ojw/Tiles/%s.php/%d/%d/%d.png",$Layer,$Z,$X,$Y));
20}
21 
22function TilePartName($X,$Y,$Z){
23  if(!TileValid($X,$Y,$Z))
24    return("");
25  return sprintf(
26    "%02d/%03d/%03d/%03d/%03d.png",
27    $Z,
28    $X/1000,
29    $X%1000,
30    $Y/1000,
31    $Y%1000);
32}
33
34
35#----------------------------------------------------------------------
36# Tests if a tile coordinate is valid
37#
38# See [[Slippy Map Tilenames]] on openstreetmap wiki for details
39#----------------------------------------------------------------------
40function TileValid($X,$Y,$Z){
41 
42  # Zoom depth is limited to 17
43  if($Z > 17)
44    return(0);
45   
46  if($Z < 0)
47    return(0);
48   
49  # Check that the specified x,y exist at this zoom level
50  if($X < 0 || $Y < 0)
51    return(0);
52  $Limit = pow(2,$Z);
53  if($X >= $Limit || $Y >= $Limit)
54    return(0);
55  return(1);
56}
57?>
Note: See TracBrowser for help on using the repository browser.